Skip to content

Commit

Permalink
add counter enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTOXIN committed May 5, 2022
1 parent 81eceef commit 214066d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ var levels = [
"res://maps/Map01.tscn"
]

var enemy_counter = 0

func restart():
current_level = 0
enemy_counter = 0
change_scene()

func next_level():
Expand Down
3 changes: 3 additions & 0 deletions UI/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ func _on_Player_boost():

func _on_Player_speeder(speed):
$GUI/Container/Speed/Label.text = str(int(speed)) + " / MPH"

func _on_Map01_enemy_counter(count):
$GUI/Container/Enemies/Label.text = str(int(count)) + " TANKS"
15 changes: 15 additions & 0 deletions UI/HUD.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ margin_bottom = 27.0
custom_fonts/font = SubResource( 4 )
text = "54 MPH"

[node name="Enemies" type="MarginContainer" parent="GUI/Container"]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -123.0
margin_top = -31.0

[node name="Label" type="Label" parent="GUI/Container/Enemies"]
margin_top = 2.0
margin_right = 125.0
margin_bottom = 29.0
custom_fonts/font = SubResource( 4 )
text = "54 TANKS"

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/RESET = SubResource( 2 )
anims/healthbar_flash = SubResource( 1 )
Expand Down
1 change: 1 addition & 0 deletions UI/TitleScreen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ rotation = 1.52408
position = Vector2( -59.3814, 906.216 )
scale = Vector2( 0.5, 0.5 )
max_speed = 150
ghost = true

[node name="Obstacles" type="Node2D" parent="."]

Expand Down
12 changes: 10 additions & 2 deletions maps/Map.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
extends Node2D
#TODO BOOST EFFECT, SPEEDOMETER, TANK TRACK PRINT, DESTROY OBJECTS, ICON EFFECTS UI
#TODO BOOST EFFECT, TANK TRACK PRINT, DESTROY OBJECTS

signal enemy_counter

func _ready():
set_camera_limits()
var cursor = load("res://assets/UI/crossair_white.png")
Input.set_custom_mouse_cursor(cursor, Input.CURSOR_ARROW, Vector2(16, 16))
$Player.map = $Ground


func _process(delta):
emit_signal("enemy_counter", Globals.enemy_counter)
if Globals.enemy_counter == 0:
Globals.restart()

func set_camera_limits():
var map_limits = $Ground.get_used_rect()
var map_cell_size = $Ground.cell_size
Expand Down
2 changes: 1 addition & 1 deletion maps/Map01.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ detect_radius = 400

[node name="EnemyTurrent" parent="." instance=ExtResource( 6 )]
position = Vector2( 863, 365 )
offroad_friction = 0.75
gun_shots = 3
gun_spread = 0.1

Expand Down Expand Up @@ -96,6 +95,7 @@ position = Vector2( 478, 65 )
position = Vector2( 963, 255 )
type = 2

[connection signal="enemy_counter" from="." to="HUD" method="_on_Map01_enemy_counter"]
[connection signal="ammo_changed" from="Player" to="HUD" method="_on_Player_ammo_changed"]
[connection signal="boost" from="Player" to="HUD" method="_on_Player_boost"]
[connection signal="dead" from="Player" to="." method="_on_Player_dead"]
Expand Down
12 changes: 12 additions & 0 deletions tanks/Enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export (bool) var disable = false
export (float) var turret_speed
export (int) var detect_radius
export (float) var accuracy_shoot = 0.9
export (bool) var ghost = false

onready var parent = get_parent()

Expand All @@ -13,6 +14,7 @@ var hit_pos: Array = []
func _ready():
$DetectRadius/CollisionShape2D.shape = CircleShape2D.new()
$DetectRadius/CollisionShape2D.shape.radius = detect_radius
enemy_counter_trigger(1)

func _draw():
if Globals.debag_mode:
Expand Down Expand Up @@ -77,6 +79,16 @@ func control(delta):
#other movement
pass

func explode():
if alive:
alive = false
enemy_counter_trigger(-1)
.explode()

func enemy_counter_trigger(val):
if !ghost:
Globals.enemy_counter += val

func _on_DetectRadius_body_entered(body):
if body.name == "Player":
target = body
Expand Down

0 comments on commit 214066d

Please sign in to comment.