Skip to content

Commit

Permalink
Part 07 - enemy unit healthbars, explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bradfield committed May 6, 2018
1 parent 14930d6 commit 2718b00
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 4 deletions.
10 changes: 8 additions & 2 deletions bullets/Bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ func _process(delta):
position += velocity * delta

func explode():
queue_free()
velocity = Vector2()
$Sprite.hide()
$Explosion.show()
$Explosion.play("smoke")

func _on_Bullet_body_entered(body):
explode()
if body.has_method('take_damage'):
body.take_damage(damage)

func _on_Lifetime_timeout():
explode()
explode()

func _on_Explosion_animation_finished():
queue_free()
11 changes: 10 additions & 1 deletion bullets/Bullet.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]

[ext_resource path="res://bullets/Bullet.gd" type="Script" id=1]
[ext_resource path="res://effects/Explosion.tscn" type="PackedScene" id=2]

[node name="Bullet" type="Area2D"]

Expand Down Expand Up @@ -30,8 +31,16 @@ wait_time = 1.0
one_shot = true
autostart = true

[node name="Explosion" parent="." index="3" instance=ExtResource( 2 )]

visible = false
scale = Vector2( 0.5, 0.5 )
_sections_unfolded = [ "Transform" ]

[connection signal="body_entered" from="." to="." method="_on_Bullet_body_entered"]

[connection signal="timeout" from="Lifetime" to="." method="_on_Lifetime_timeout"]

[connection signal="animation_finished" from="Explosion" to="." method="_on_Explosion_animation_finished"]


33 changes: 33 additions & 0 deletions effects/Explosion.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[gd_scene load_steps=12 format=2]

[ext_resource path="res://assets/explosions/explosion1.png" type="Texture" id=1]
[ext_resource path="res://assets/explosions/explosion2.png" type="Texture" id=2]
[ext_resource path="res://assets/explosions/explosion3.png" type="Texture" id=3]
[ext_resource path="res://assets/explosions/explosion4.png" type="Texture" id=4]
[ext_resource path="res://assets/explosions/explosion5.png" type="Texture" id=5]
[ext_resource path="res://assets/explosions/explosionSmoke1.png" type="Texture" id=6]
[ext_resource path="res://assets/explosions/explosionSmoke2.png" type="Texture" id=7]
[ext_resource path="res://assets/explosions/explosionSmoke3.png" type="Texture" id=8]
[ext_resource path="res://assets/explosions/explosionSmoke4.png" type="Texture" id=9]
[ext_resource path="res://assets/explosions/explosionSmoke5.png" type="Texture" id=10]

[sub_resource type="SpriteFrames" id=1]

animations = [ {
"frames": [ ExtResource( 1 ), ExtResource( 2 ), ExtResource( 3 ), ExtResource( 4 ), ExtResource( 5 ) ],
"loop": true,
"name": "fire",
"speed": 12.0
}, {
"frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ) ],
"loop": true,
"name": "smoke",
"speed": 12.0
} ]

[node name="Explosion" type="AnimatedSprite"]

frames = SubResource( 1 )
animation = "smoke"


1 change: 1 addition & 0 deletions maps/Map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Node2D

func _ready():
set_camera_limits()
Input.set_custom_mouse_cursor(load("res://assets/UI/crossair_black.png"), Input.CURSOR_ARROW, Vector2(16, 16))

func set_camera_limits():
var map_limits = $Ground.get_used_rect()
Expand Down
7 changes: 6 additions & 1 deletion tanks/EnemyTank.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://tanks/Tank.tscn" type="PackedScene" id=1]
[ext_resource path="res://tanks/EnemyTank.gd" type="Script" id=2]
[ext_resource path="res://bullets/EnemyBullet.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/onlyObjects_retina_rotated.png" type="Texture" id=4]
[ext_resource path="res://ui/UnitDisplay.tscn" type="PackedScene" id=5]

[sub_resource type="RectangleShape2D" id=1]

Expand Down Expand Up @@ -82,6 +83,10 @@ cast_to = Vector2( 100, 0 )
collision_mask = 7
_sections_unfolded = [ "Transform" ]

[node name="UnitDisplay" parent="." index="7" instance=ExtResource( 5 )]

[connection signal="health_changed" from="." to="UnitDisplay" method="update_healthbar"]

[connection signal="body_entered" from="DetectRadius" to="." method="_on_DetectRadius_body_entered"]

[connection signal="body_exited" from="DetectRadius" to="." method="_on_DetectRadius_body_exited"]
Expand Down
22 changes: 22 additions & 0 deletions ui/UnitDisplay.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends Node2D

var bar_red = preload("res://assets/UI/barHorizontal_red_mid 200.png")
var bar_green = preload("res://assets/UI/barHorizontal_green_mid 200.png")
var bar_yellow = preload("res://assets/UI/barHorizontal_yellow_mid 200.png")

func _ready():
for node in get_children():
node.hide()

func _process(delta):
global_rotation = 0

func update_healthbar(value):
$HealthBar.texture_progress = bar_green
if value < 60:
$HealthBar.texture_progress = bar_yellow
if value < 25:
$HealthBar.texture_progress = bar_red
if value < 100:
$HealthBar.show()
$HealthBar.value = value
43 changes: 43 additions & 0 deletions ui/UnitDisplay.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://ui/UnitDisplay.gd" type="Script" id=1]
[ext_resource path="res://assets/UI/barHorizontal_green_mid 200.png" type="Texture" id=2]

[node name="UnitDisplay" type="Node2D"]

scale = Vector2( 0.5, 0.5 )
script = ExtResource( 1 )
_sections_unfolded = [ "Transform", "Z Index" ]

[node name="HealthBar" type="TextureProgress" parent="." index="0"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = -100.0
margin_top = -156.0
margin_right = 100.0
margin_bottom = -116.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 100.0
step = 1.0
page = 0.0
value = 100.0
exp_edit = false
rounded = false
texture_under = null
texture_over = null
texture_progress = ExtResource( 2 )
radial_fill_degrees = 360.0
radial_center_offset = Vector2( 0, 0 )
nine_patch_stretch = false
_sections_unfolded = [ "Textures" ]


0 comments on commit 2718b00

Please sign in to comment.