Skip to content

Commit

Permalink
add pickup ammo and ammo guage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTOXIN committed May 1, 2022
1 parent 6c870c2 commit 0ce9a1a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
3 changes: 3 additions & 0 deletions UI/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var bar_green = preload("res://assets/UI/barHorizontal_green_mid 200.png")
var bar_yellow = preload("res://assets/UI/barHorizontal_yellow_mid 200.png")
var bar_texture

func _on_Player_ammo_changed(value):
$Margin/Container/AmmoGuage.value = value

func _on_Player_health_changed(value):
bar_texture = bar_green

Expand Down
19 changes: 18 additions & 1 deletion UI/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://assets/shield_silver.png" type="Texture" id=1]
[ext_resource path="res://assets/UI/barHorizontal_red_mid 200.png" type="Texture" id=2]
[ext_resource path="res://assets/UI/glassPanel_200.png" type="Texture" id=3]
[ext_resource path="res://UI/HUD.gd" type="Script" id=4]
[ext_resource path="res://assets/UI/barHorizontal_white_mid 200.png" type="Texture" id=5]
[ext_resource path="res://assets/UI/dotWhite.png" type="Texture" id=6]

[sub_resource type="Animation" id=2]
length = 0.001
Expand Down Expand Up @@ -68,6 +69,22 @@ texture_progress = ExtResource( 2 )

[node name="Tween" type="Tween" parent="Margin/Container/HealthBar"]

[node name="VSeparator" type="VSeparator" parent="Margin/Container"]
self_modulate = Color( 1, 1, 1, 0 )
margin_left = 238.0
margin_right = 243.0
margin_bottom = 560.0
custom_constants/separation = 5

[node name="AmmoGuage" type="TextureProgress" parent="Margin/Container"]
margin_left = 247.0
margin_right = 271.0
margin_bottom = 560.0
value = 75.0
texture_progress = ExtResource( 6 )
fill_mode = 4
radial_initial_angle = 180.0

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/RESET = SubResource( 2 )
anims/healthbar_flash = SubResource( 1 )
Expand Down
10 changes: 9 additions & 1 deletion items/Pickup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ enum Items {health, ammo}
export (Items) var type = Items.health
export (Vector2) var amount = Vector2(10, 25)

var icon_textures = {
Items.health: preload("res://assets/effects/wrench_white.png"),
Items.ammo: preload("res://assets/effects/ammo_machinegun.png")
}

func _ready():
$Icon.texture = icon_textures[type]

func _on_Pickup_body_entered(body):
match type:
Items.health:
if body.has_method('heal'):
body.heal(int(rand_range(amount.x, amount.y)))
Items.ammo:
pass
body.ammo += int(rand_range(amount.x, amount.y))
queue_free()
4 changes: 1 addition & 3 deletions items/Pickup.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://assets/onlyObjects_retina_rotated.png" type="Texture" id=1]
[ext_resource path="res://items/Pickup.gd" type="Script" id=2]
[ext_resource path="res://assets/effects/shadow_circle.png" type="Texture" id=3]
[ext_resource path="res://assets/effects/wrench_white.png" type="Texture" id=4]

[sub_resource type="CircleShape2D" id=1]
radius = 33.0151
Expand Down Expand Up @@ -170,7 +169,6 @@ modulate = Color( 0.470588, 0.898039, 0.337255, 1 )
self_modulate = Color( 1, 1, 1, 0.352941 )
position = Vector2( 0, -10 )
scale = Vector2( 0.7, 0.7 )
texture = ExtResource( 4 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
Expand Down
8 changes: 7 additions & 1 deletion maps/Map01.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tile_data = PoolIntArray( -1, 20, 0, -65536, 17, 0, -65535, 17, 0, -65534, 17, 0

[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 178, 167 )
ammo = 0

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

Expand Down Expand Up @@ -75,8 +76,13 @@ type = 19
[node name="Items" type="Node2D" parent="."]

[node name="Pickup" parent="Items" instance=ExtResource( 9 )]
position = Vector2( 475, 356 )
position = Vector2( 475, 449 )
type = 1

[node name="Pickup2" parent="Items" instance=ExtResource( 9 )]
position = Vector2( 478, 65 )

[connection signal="ammo_changed" from="Player" to="HUD" method="_on_Player_ammo_changed"]
[connection signal="dead" from="Player" to="." method="_on_Player_dead"]
[connection signal="health_changed" from="Player" to="HUD" method="_on_Player_health_changed"]
[connection signal="shoot" from="Player" to="." method="_on_Tank_shoot"]
Expand Down
1 change: 1 addition & 0 deletions tanks/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ max_speed = 200
rotation_speed = 1.0
gun_cooldown = 0.5
max_health = 100
ammo = 10

[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )
Expand Down
17 changes: 16 additions & 1 deletion tanks/Tank.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends KinematicBody2D

signal health_changed
signal ammo_changed
signal dead
signal shoot

Expand All @@ -13,6 +14,9 @@ export (int) var max_health
export (int) var gun_shots = 1
export (float, 0, 1.5) var gun_spread = 0

export (int) var max_ammo = 20
export (int) var ammo = -1 setget set_ammo

var velocity = Vector2()
var can_shoot = true
var alive = true
Expand All @@ -24,6 +28,7 @@ func _ready():

health = max_health
change_health()
change_ammo()

func _physics_process(delta):
if not alive:
Expand All @@ -44,6 +49,14 @@ func heal(amount):
func change_health():
emit_signal("health_changed", health * 100 / max_health)

func set_ammo(value):
ammo = clamp(value, -1, max_ammo)
print(ammo)
change_ammo()

func change_ammo():
emit_signal("ammo_changed", ammo * 100 / max_ammo)

func explode():
alive = false
can_shoot = false
Expand All @@ -54,8 +67,10 @@ func explode():

func shoot(num = 1, spread = 0, target = null):
#TODO check obstacles ray tracing
if can_shoot:
if can_shoot and ammo != 0:
can_shoot = false
#TODO может не сработать проверка на ноль если чило не кратно
self.ammo -= num
$GunTimer.start()
var dir = Vector2.RIGHT.rotated($Turret.global_rotation)
var pos = $Turret/Muzzle.global_position
Expand Down

0 comments on commit 0ce9a1a

Please sign in to comment.