Skip to content

Commit

Permalink
add limit of 3 for missiles, UI for missiles amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Nartynka committed Sep 30, 2022
1 parent 70c3117 commit 73e5d0a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func _physics_process(delta):
if Input.is_action_pressed("fire_bullet") and fireBulletTimer.time_left == 0:
fire_bullet()
if Input.is_action_pressed("fire_missile") and fireBulletTimer.time_left == 0:
fire_missile()
if PlayerStats.missiles > 0:
fire_missile()
PlayerStats.missiles -= 1

func fire_bullet():
var bullet = Utils.instance_on_main(Bullet, firePoint.global_position)
Expand Down
8 changes: 8 additions & 0 deletions Player/PlayerStats.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ extends Resource
class_name PlayerStats

signal player_health_change(value)
signal player_missiles_change(value)
signal player_death

var max_health = 4
var health = max_health setget set_health

var max_missiles = 3
var missiles = max_missiles setget set_missiles

func set_health(new_value):
if new_value < health:
Events.emit_signal("add_screenshake", 0.4, 0.5)
health = clamp(new_value, 0, max_health)
emit_signal("player_health_change", health)
if health == 0:
emit_signal("player_death")

func set_missiles(new_value):
missiles = clamp(new_value, 0, max_missiles)
emit_signal("player_missiles_change", missiles)
12 changes: 12 additions & 0 deletions UI/MissilesCount.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends HBoxContainer

onready var label = $Label

var PlayerStats = ResourceLoader.PlayerStats

func _ready():
PlayerStats.connect("player_missiles_change", self, "_on_missiles_change")
label.text = str(PlayerStats.max_missiles)

func _on_missiles_change(amount):
label.text = str(amount)
25 changes: 25 additions & 0 deletions UI/MissilesCount.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://UI/PlayerMissileIcon.png" type="Texture" id=1]
[ext_resource path="res://UI/DefaultTheme.tres" type="Theme" id=2]
[ext_resource path="res://UI/MissilesCount.gd" type="Script" id=3]

[node name="MissilesCount" type="HBoxContainer"]
margin_right = 25.0
margin_bottom = 10.0
theme = ExtResource( 2 )
custom_constants/separation = 1
script = ExtResource( 3 )

[node name="Icon" type="TextureRect" parent="."]
margin_right = 8.0
margin_bottom = 10.0
texture = ExtResource( 1 )

[node name="Label" type="Label" parent="."]
margin_left = 9.0
margin_right = 14.0
margin_bottom = 10.0
size_flags_vertical = 1
text = "2"
valign = 1
9 changes: 8 additions & 1 deletion UI/UI.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://UI/HealthMeter.tscn" type="PackedScene" id=1]
[ext_resource path="res://Menus/PauseMenu.tscn" type="PackedScene" id=2]
[ext_resource path="res://UI/MissilesCount.tscn" type="PackedScene" id=3]

[node name="UI" type="CanvasLayer"]

Expand All @@ -13,3 +14,9 @@ margin_bottom = 16.0

[node name="PauseMenu" parent="." instance=ExtResource( 2 )]
visible = false

[node name="MissilesCount" parent="." instance=ExtResource( 3 )]
margin_left = 5.0
margin_top = 20.0
margin_right = 30.0
margin_bottom = 30.0

0 comments on commit 73e5d0a

Please sign in to comment.