Missiles limit & UI
This commit is contained in:
parent
853eb28d33
commit
632d927938
|
@ -82,7 +82,7 @@ func _physics_process(delta):
|
|||
if Input.is_action_pressed("fire") and fireBulletTimer.time_left == 0:
|
||||
fire_bullet()
|
||||
|
||||
if Input.is_action_pressed("fire_missile") and fireBulletTimer.time_left == 0:
|
||||
if Input.is_action_pressed("fire_missile") and fireBulletTimer.time_left == 0 and PlayerStats.missiles > 0:
|
||||
fire_missile()
|
||||
|
||||
func fire_bullet():
|
||||
|
@ -99,6 +99,7 @@ func fire_missile():
|
|||
motion -= missile.velocity * 0.25
|
||||
missile.rotation = missile.velocity.angle()
|
||||
fireBulletTimer.start()
|
||||
PlayerStats.missiles -= 1
|
||||
|
||||
func create_dust_effect():
|
||||
var dust_position = global_position
|
||||
|
|
|
@ -3,8 +3,11 @@ class_name PlayerStats
|
|||
|
||||
var max_health = 4
|
||||
var health = max_health setget set_health
|
||||
var max_missiles = 3
|
||||
var missiles = max_missiles setget set_missiles
|
||||
|
||||
signal player_health_changed(value)
|
||||
signal player_missiles_changed(value)
|
||||
signal player_died
|
||||
|
||||
func set_health(value):
|
||||
|
@ -16,3 +19,7 @@ func set_health(value):
|
|||
|
||||
if health == 0:
|
||||
emit_signal("player_died")
|
||||
|
||||
func set_missiles(value):
|
||||
missiles = clamp(value, 0, max_missiles)
|
||||
emit_signal("player_missiles_changed", missiles)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
extends HBoxContainer
|
||||
|
||||
var PlayerStats = ResourceLoader.PlayerStats
|
||||
|
||||
onready var label = $Label
|
||||
|
||||
func _ready():
|
||||
PlayerStats.connect("player_missiles_changed", self, "_on_player_missiles_changed")
|
||||
|
||||
func _on_player_missiles_changed(value):
|
||||
label.text = str(value)
|
|
@ -0,0 +1,27 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Assets/UI/PlayerMissileIcon.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Scenes/UI/PixelFont.tres" type="DynamicFont" id=2]
|
||||
[ext_resource path="res://Scenes/UI/MissilesUI.gd" type="Script" id=3]
|
||||
|
||||
[node name="MissilesUI" type="HBoxContainer"]
|
||||
margin_right = 33.0
|
||||
margin_bottom = 12.0
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Icon" type="TextureRect" parent="."]
|
||||
margin_right = 8.0
|
||||
margin_bottom = 12.0
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_left = 12.0
|
||||
margin_right = 17.0
|
||||
margin_bottom = 7.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
text = "3"
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/UI/HealthMeter.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Scenes/Menus/PauseMenu.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Scenes/UI/MissilesUI.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="UI" type="CanvasLayer"]
|
||||
|
||||
|
@ -13,3 +14,9 @@ margin_bottom = 16.0
|
|||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource( 2 )]
|
||||
visible = false
|
||||
|
||||
[node name="MissilesUI" parent="." instance=ExtResource( 3 )]
|
||||
margin_left = 4.0
|
||||
margin_top = 19.0
|
||||
margin_right = 37.0
|
||||
margin_bottom = 31.0
|
||||
|
|
Loading…
Reference in New Issue