This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from FinnTheTurkey/master
Add damage indicators
- Loading branch information
Showing
10 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Godot; | ||
|
||
|
||
public class DamageIndicator : Sprite | ||
{ | ||
public float MaxLife; | ||
public float RemainingLife; | ||
|
||
public Vector2 ShotFirePos2D; | ||
|
||
public ShaderMaterial Mat; | ||
|
||
public static Shader TransparencyShader; | ||
|
||
static DamageIndicator() | ||
{ | ||
TransparencyShader = GD.Load<Shader>("res://UI/DamageIndicator.shader"); | ||
} | ||
|
||
|
||
public void Setup(Vector3 Origin, float MaxLifeArg) | ||
{ | ||
MaxLife = MaxLifeArg; | ||
RemainingLife = MaxLife; | ||
|
||
ShotFirePos2D = new Vector2(Origin.x, Origin.z); | ||
|
||
Mat = new ShaderMaterial(); | ||
Mat.Shader = TransparencyShader; | ||
Mat.SetShaderParam("alpha", 1); | ||
Material = Mat; | ||
|
||
CenterSprite(); | ||
} | ||
|
||
|
||
private void CenterSprite() | ||
{ | ||
GlobalPosition = OS.GetWindowSize() / new Vector2(2, 2); | ||
} | ||
|
||
|
||
public override void _Process(float Delta) | ||
{ | ||
Vector2 PlayerPosition2D = new Vector2(Game.PossessedPlayer.Translation.x, Game.PossessedPlayer.Translation.z); | ||
SetRotation(PlayerPosition2D.AngleToPoint(ShotFirePos2D) + Game.PossessedPlayer.Rotation.y); | ||
|
||
RemainingLife -= Delta; | ||
if(RemainingLife <= 0) | ||
QueueFree(); | ||
|
||
Mat.SetShaderParam("alpha", RemainingLife/MaxLife); | ||
|
||
CenterSprite(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
shader_type canvas_item; | ||
uniform float alpha = 1; | ||
|
||
|
||
void fragment() | ||
{ | ||
COLOR = texture(TEXTURE, UV); | ||
COLOR.a = COLOR.a * alpha; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[gd_scene load_steps=5 format=2] | ||
|
||
[ext_resource path="res://UI/DamageIndicator.shader" type="Shader" id=1] | ||
[ext_resource path="res://UI/Textures/DamageIndicator.png" type="Texture" id=2] | ||
[ext_resource path="res://UI/DamageIndicator.cs" type="Script" id=3] | ||
|
||
[sub_resource type="ShaderMaterial" id=1] | ||
shader = ExtResource( 1 ) | ||
shader_param/alpha = 0.5 | ||
|
||
[node name="DamageIndicator" type="Sprite"] | ||
material = SubResource( 1 ) | ||
position = Vector2( 202.18, 203.938 ) | ||
texture = ExtResource( 2 ) | ||
script = ExtResource( 3 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/DamageIndicator.png-cbb494ba511e14f2e40bf5115c6800de.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://UI/Textures/DamageIndicator.png" | ||
dest_files=[ "res://.import/DamageIndicator.png-cbb494ba511e14f2e40bf5115c6800de.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |