Add resource stats

This commit is contained in:
Moe Poi ~ 2023-10-07 21:10:06 +07:00
parent dd21191eb3
commit 2933207108
7 changed files with 77 additions and 11 deletions

BIN
assets/icons/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dlyy0lwxniifh"
path="res://.godot/imported/close.png-8e81c1f7f49413c3a4d65fae064a1aae.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/icons/close.png"
dest_files=["res://.godot/imported/close.png-8e81c1f7f49413c3a4d65fae064a1aae.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://cy88k4uxt1v37"]
[gd_scene load_steps=5 format=3 uid="uid://cy88k4uxt1v37"]
[ext_resource type="Texture2D" uid="uid://d2d7ab8q2vik4" path="res://assets/icons/label_bg.png" id="1_1gxsd"]
[ext_resource type="Script" path="res://scripts/ui/game_stats.gd" id="1_ui7x4"]
[ext_resource type="Texture2D" uid="uid://derifasksdfub" path="res://assets/icons/pause.png" id="2_imq5h"]
[ext_resource type="Texture2D" uid="uid://e8dmiy1xr5g3" path="res://assets/icons/health.png" id="3_r1i66"]
@ -11,13 +12,14 @@ anchor_right = 1.0
offset_right = -2.0
offset_bottom = 51.0
grow_horizontal = 2
script = ExtResource("1_ui7x4")
[node name="Resources" type="NinePatchRect" parent="."]
layout_mode = 0
offset_left = 981.0
offset_left = 975.0
offset_top = 7.0
offset_right = 1125.0
offset_bottom = 42.0
offset_bottom = 48.0
texture = ExtResource("1_1gxsd")
[node name="Label" type="Label" parent="Resources"]
@ -31,20 +33,32 @@ text = "999999999"
horizontal_alignment = 1
vertical_alignment = 1
[node name="PauseButton" type="TextureButton" parent="."]
[node name="Pause" type="NinePatchRect" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -18.0
offset_top = 10.0
offset_right = 19.0
offset_bottom = 45.0
grow_horizontal = 2
texture = ExtResource("1_1gxsd")
[node name="PauseButton" type="TextureButton" parent="Pause"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -22.5
offset_right = 2028.0
offset_bottom = 2025.5
offset_left = -15.5
offset_top = -15.5
offset_right = 2032.5
offset_bottom = 2032.5
grow_horizontal = 2
grow_vertical = 2
scale = Vector2(0.02, 0.02)
scale = Vector2(0.015, 0.015)
texture_normal = ExtResource("2_imq5h")
[node name="Health" type="NinePatchRect" parent="."]

View file

@ -3,6 +3,8 @@ extends Node
class_name Config
var game = {
"health": 6,
"resource": 100,
"spawn_timer": 3.0,
"offset": [-30.0, 30.0],
"path_direction": [

View file

@ -6,11 +6,12 @@ var config = load("res://scripts/stages/1/config.gd").new()
var data = {
"tower": {},
"health": 6,
"resource": 100
"health": config.game['health'],
"resource": config.game['resource']
}
func _ready():
$CanvasLayer/GameStats.set_resource(data['resource'])
var placements = $Placements.get_children()
for placement in placements:
placement.connect("on_placement", on_game_placement)
@ -57,3 +58,4 @@ func on_build_tower(pos, tower_id, tower_placement_id):
data['tower'][str(tower_placement_id)]['id'] = tower_id
data['tower'][str(tower_placement_id)]['name'] = tower.name
data['resource'] -= config.menu[tower_id]['price']
$CanvasLayer/GameStats.set_resource(data['resource'])

14
scripts/ui/game_stats.gd Normal file
View file

@ -0,0 +1,14 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func set_resource(value):
$Resources/Label.text = str(value)