From 8be0789b1725e629af498c295f53fd87e66d0496 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 17 Feb 2024 00:55:13 +0800 Subject: [PATCH] :sparkles: Upgradable --- project.godot | 2 +- scenes/main.tscn | 9 ++- scenes/ui/finish_screen.tscn | 103 +++++++++++++++++++++++++++-- scenes/ui/reward_claim_screen.tscn | 34 ++++++++++ scenes/ui/reward_item.tscn | 43 ++++++++++++ scenes/ui/stats_overlay.tscn | 7 +- scripts/Tower.gd | 2 + scripts/player.gd | 2 + scripts/ui/finish_screen.gd | 9 +++ scripts/ui/reward_claim_screen.gd | 57 ++++++++++++++++ scripts/ui/reward_item.gd | 22 ++++++ 11 files changed, 280 insertions(+), 10 deletions(-) create mode 100644 scenes/ui/reward_claim_screen.tscn create mode 100644 scenes/ui/reward_item.tscn create mode 100644 scripts/ui/reward_claim_screen.gd create mode 100644 scripts/ui/reward_item.gd diff --git a/project.godot b/project.godot index 855d7da..8eb03f6 100644 --- a/project.godot +++ b/project.godot @@ -51,7 +51,7 @@ skill_dash={ } weapon_fire={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":256,"position":Vector2(234, 24),"global_position":Vector2(242, 104),"factor":1.0,"button_index":9,"canceled":false,"pressed":true,"double_click":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null) , Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(185, 16),"global_position":Vector2(193, 96),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } diff --git a/scenes/main.tscn b/scenes/main.tscn index 4de701c..83ae678 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://l4mybb2dw107"] +[gd_scene load_steps=10 format=3 uid="uid://l4mybb2dw107"] [ext_resource type="PackedScene" uid="uid://cwkcf8h5rspoh" path="res://scenes/objects/player.tscn" id="1_nq1ke"] [ext_resource type="PackedScene" uid="uid://cxlgt8h33u7os" path="res://scenes/objects/tower.tscn" id="2_betjv"] @@ -7,6 +7,7 @@ [ext_resource type="PackedScene" uid="uid://2tqfm73cc4id" path="res://scenes/manager/statistics.tscn" id="5_qd3ww"] [ext_resource type="PackedScene" uid="uid://cjam63kp5sg2o" path="res://scenes/ui/stats_overlay.tscn" id="5_rymed"] [ext_resource type="PackedScene" uid="uid://dy51uqtr2ng32" path="res://scenes/ui/finish_screen.tscn" id="6_b264x"] +[ext_resource type="PackedScene" uid="uid://5mt7abqkbpei" path="res://scenes/ui/reward_claim_screen.tscn" id="6_t43s0"] [sub_resource type="Curve2D" id="Curve2D_gwd20"] _data = { @@ -39,6 +40,11 @@ rotation = 1.5708 [node name="StatsOverlay" parent="." node_paths=PackedStringArray("stats") instance=ExtResource("5_rymed")] stats = NodePath("../Statistics") +[node name="RewardClaimScreen" parent="." node_paths=PackedStringArray("tower", "player") instance=ExtResource("6_t43s0")] +visible = false +tower = NodePath("../Tower") +player = NodePath("../Player") + [node name="FinishScreen" parent="." node_paths=PackedStringArray("stats") instance=ExtResource("6_b264x")] visible = false stats = NodePath("../Statistics") @@ -48,4 +54,5 @@ stats = NodePath("../Statistics") [connection signal="enemy_defeat" from="EnemyFarm" to="Statistics" method="_on_enemy_defeated"] [connection signal="tower_broken" from="Tower" to="FinishScreen" method="_show"] [connection signal="wave_finished" from="Statistics" to="EnemyFarm" method="_on_wave_finished"] +[connection signal="wave_finished" from="Statistics" to="RewardClaimScreen" method="_show"] [connection signal="wave_started" from="Statistics" to="EnemyFarm" method="_on_wave_started"] diff --git a/scenes/ui/finish_screen.tscn b/scenes/ui/finish_screen.tscn index e0f7058..caf7806 100644 --- a/scenes/ui/finish_screen.tscn +++ b/scenes/ui/finish_screen.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://dy51uqtr2ng32"] +[gd_scene load_steps=4 format=3 uid="uid://dy51uqtr2ng32"] [ext_resource type="Script" path="res://scripts/ui/finish_screen.gd" id="1_c1emt"] [ext_resource type="Theme" uid="uid://gh5a3no0ojkl" path="res://codingland.tres" id="1_l6ven"] -[node name="FinishScreen" type="Control"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_djdno"] +bg_color = Color(0.301961, 0.301961, 0.301961, 1) + +[node name="FinishScreen" type="Control" node_paths=PackedStringArray("survived_indicator", "wave_indicator", "enemies_indicator", "bullet_indicator")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -12,17 +15,107 @@ grow_horizontal = 2 grow_vertical = 2 theme = ExtResource("1_l6ven") script = ExtResource("1_c1emt") +survived_indicator = NodePath("Panel/SurvivedTime") +wave_indicator = NodePath("Panel/WaveCount") +enemies_indicator = NodePath("Panel/EnemyCount") +bullet_indicator = NodePath("Panel/BulletCount") [node name="Panel" type="Panel" parent="."] layout_mode = 0 offset_right = 1152.0 offset_bottom = 648.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_djdno") [node name="Title" type="Label" parent="Panel"] layout_mode = 0 -offset_top = 280.0 +offset_top = 128.0 offset_right = 1152.0 -offset_bottom = 364.0 +offset_bottom = 212.0 theme_override_font_sizes/font_size = 64 -text = "Game Over" +text = "You failed" +horizontal_alignment = 1 + +[node name="Subtitle" type="Label" parent="Panel"] +layout_mode = 0 +offset_top = 208.0 +offset_right = 1152.0 +offset_bottom = 250.0 +theme_override_font_sizes/font_size = 28 +text = "The tower has been destroyed" +horizontal_alignment = 1 + +[node name="SurvivedCaption" type="Label" parent="Panel"] +layout_mode = 0 +offset_top = 416.0 +offset_right = 576.0 +offset_bottom = 448.0 +theme_override_font_sizes/font_size = 24 +text = "You Survived" +horizontal_alignment = 1 + +[node name="SurvivedTime" type="Label" parent="Panel"] +layout_mode = 0 +offset_top = 440.0 +offset_right = 576.0 +offset_bottom = 504.0 +theme_override_font_sizes/font_size = 48 +text = "0.0s" +horizontal_alignment = 1 + +[node name="WaveCaption" type="Label" parent="Panel"] +layout_mode = 0 +offset_top = 296.0 +offset_right = 576.0 +offset_bottom = 328.0 +theme_override_font_sizes/font_size = 24 +text = "Wave" +horizontal_alignment = 1 + +[node name="WaveCount" type="Label" parent="Panel"] +layout_mode = 0 +offset_top = 324.0 +offset_right = 576.0 +offset_bottom = 388.0 +theme_override_font_sizes/font_size = 48 +text = "1" +horizontal_alignment = 1 + +[node name="EnemyTitle" type="Label" parent="Panel"] +layout_mode = 0 +offset_left = 576.0 +offset_top = 296.0 +offset_right = 1152.0 +offset_bottom = 328.0 +theme_override_font_sizes/font_size = 24 +text = "Enemy Defeated" +horizontal_alignment = 1 + +[node name="EnemyCount" type="Label" parent="Panel"] +layout_mode = 0 +offset_left = 576.0 +offset_top = 324.0 +offset_right = 1152.0 +offset_bottom = 388.0 +theme_override_font_sizes/font_size = 48 +text = "0" +horizontal_alignment = 1 + +[node name="BulletTitle" type="Label" parent="Panel"] +layout_mode = 0 +offset_left = 576.0 +offset_top = 416.0 +offset_right = 1152.0 +offset_bottom = 448.0 +theme_override_font_sizes/font_size = 24 +text = "Bullet Shoot" +horizontal_alignment = 1 + +[node name="BulletCount" type="Label" parent="Panel"] +layout_mode = 0 +offset_left = 576.0 +offset_top = 440.0 +offset_right = 1152.0 +offset_bottom = 504.0 +theme_override_font_sizes/font_size = 48 +text = "0" horizontal_alignment = 1 diff --git a/scenes/ui/reward_claim_screen.tscn b/scenes/ui/reward_claim_screen.tscn new file mode 100644 index 0000000..361b469 --- /dev/null +++ b/scenes/ui/reward_claim_screen.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=5 format=3 uid="uid://5mt7abqkbpei"] + +[ext_resource type="Theme" uid="uid://gh5a3no0ojkl" path="res://codingland.tres" id="1_yxvac"] +[ext_resource type="Script" path="res://scripts/ui/reward_claim_screen.gd" id="2_c2hn7"] +[ext_resource type="PackedScene" uid="uid://bayylbkjbagy5" path="res://scenes/ui/reward_item.tscn" id="3_p7bh8"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3xnq2"] +bg_color = Color(0.301961, 0.301961, 0.301961, 1) + +[node name="RewardClaimScreen" type="Control"] +process_mode = 3 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_yxvac") +script = ExtResource("2_c2hn7") +card = ExtResource("3_p7bh8") + +[node name="Panel" type="Panel" parent="."] +layout_mode = 0 +offset_right = 1152.0 +offset_bottom = 648.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_3xnq2") + +[node name="RewardContainer" type="HBoxContainer" parent="Panel"] +layout_mode = 0 +offset_left = 32.0 +offset_top = 32.0 +offset_right = 1120.0 +offset_bottom = 616.0 +alignment = 1 diff --git a/scenes/ui/reward_item.tscn b/scenes/ui/reward_item.tscn new file mode 100644 index 0000000..5e74c83 --- /dev/null +++ b/scenes/ui/reward_item.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=2 format=3 uid="uid://bayylbkjbagy5"] + +[ext_resource type="Script" path="res://scripts/ui/reward_item.gd" id="1_v4j3k"] + +[node name="RewardItem" type="Panel"] +custom_minimum_size = Vector2(360, 584) +script = ExtResource("1_v4j3k") + +[node name="Title" type="Label" parent="."] +layout_mode = 0 +offset_top = 120.0 +offset_right = 360.0 +offset_bottom = 162.0 +theme_override_font_sizes/font_size = 32 +text = "Reward" +horizontal_alignment = 1 + +[node name="Subtitle" type="Label" parent="."] +layout_mode = 0 +offset_top = 160.0 +offset_right = 360.0 +offset_bottom = 184.0 +theme_override_font_sizes/font_size = 16 +text = "Reward description" +horizontal_alignment = 1 + +[node name="Description" type="RichTextLabel" parent="."] +layout_mode = 0 +offset_left = 52.0 +offset_top = 208.0 +offset_right = 308.0 +offset_bottom = 504.0 +bbcode_enabled = true +text = "This is the world most powerful reward. Trust me, choose this is a great choice." + +[node name="ClaimButton" type="Button" parent="."] +offset_left = 52.0 +offset_top = 520.0 +offset_right = 308.0 +offset_bottom = 552.0 +text = "Claim" + +[connection signal="pressed" from="ClaimButton" to="." method="_on_claim"] diff --git a/scenes/ui/stats_overlay.tscn b/scenes/ui/stats_overlay.tscn index 5292688..e21eb3c 100644 --- a/scenes/ui/stats_overlay.tscn +++ b/scenes/ui/stats_overlay.tscn @@ -30,17 +30,18 @@ offset_bottom = 648.0 [node name="SurvivedCaption" type="Label" parent="SurvivedControl"] layout_mode = 0 +offset_top = 5.0 offset_right = 1152.0 -offset_bottom = 26.0 +offset_bottom = 31.0 theme_override_font_sizes/font_size = 18 text = "You survived" horizontal_alignment = 1 [node name="SurvivedTime" type="Label" parent="SurvivedControl"] layout_mode = 0 -offset_top = 20.0 +offset_top = 25.0 offset_right = 1152.0 -offset_bottom = 65.0 +offset_bottom = 70.0 theme_override_font_sizes/font_size = 32 text = "0.0s" horizontal_alignment = 1 diff --git a/scripts/Tower.gd b/scripts/Tower.gd index 7c4c990..edc20e7 100644 --- a/scripts/Tower.gd +++ b/scripts/Tower.gd @@ -1,3 +1,5 @@ +class_name Tower + extends Area2D signal tower_broken diff --git a/scripts/player.gd b/scripts/player.gd index 87a1221..9de5c91 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,3 +1,5 @@ +class_name Player + extends CharacterBody2D @export var speed = 1200 diff --git a/scripts/ui/finish_screen.gd b/scripts/ui/finish_screen.gd index 734ba04..b692e83 100644 --- a/scripts/ui/finish_screen.gd +++ b/scripts/ui/finish_screen.gd @@ -2,5 +2,14 @@ extends Control @export var stats: Statistics +@export var survived_indicator: Label +@export var wave_indicator: Label +@export var enemies_indicator: Label +@export var bullet_indicator: Label + func _show(): + survived_indicator.text = "%.2fs" % (stats.get_time_survived() / 1000.0) + wave_indicator.text = "%d" % stats.get_current_wave() + enemies_indicator.text = "%d" % stats.enemies_defeated + bullet_indicator.text = "%d" % stats.bullet_shoot visible = true diff --git a/scripts/ui/reward_claim_screen.gd b/scripts/ui/reward_claim_screen.gd new file mode 100644 index 0000000..ad4d380 --- /dev/null +++ b/scripts/ui/reward_claim_screen.gd @@ -0,0 +1,57 @@ +extends Control + +@export var card: PackedScene +@export var tower: Tower +@export var player: Player + +@export var items = [ + { + id = "QUICK_TRIGGER", + title = "Quick Trigger", + subtitle = "Save your finger", + description = "Reduce the delay between two shot.", + weight = 0.1, + } +] + +func pick_item() -> Dictionary: + var total_weight: float = 0.0 + for choice in items: + total_weight += choice["weight"] + + var random_value: float = randf() * total_weight + var cumulative_weight: float = 0.0 + for choice in items: + cumulative_weight += choice["weight"] + if random_value <= cumulative_weight: + return choice + + return items.back() + +func roll(): + for child in $Panel/RewardContainer.get_children(): + child.queue_free() + + var items = [] + for idx in range(3): + items.append(pick_item()) + + for item in items: + var instance = card.instantiate() + instance.tower = tower + instance.player = player + instance.id = item["id"] + instance.title = item["title"] + instance.subtitle = item["subtitle"] + instance.description = item["description"] + instance.connect("claimed", _hide) + $Panel/RewardContainer.add_child(instance) + +func _show(): + roll() + get_tree().paused = true + visible = true + +func _hide(): + get_tree().paused = false + visible = false diff --git a/scripts/ui/reward_item.gd b/scripts/ui/reward_item.gd new file mode 100644 index 0000000..6adf31f --- /dev/null +++ b/scripts/ui/reward_item.gd @@ -0,0 +1,22 @@ +extends Panel + +signal claimed + +@export var tower: Tower +@export var player: Player + +@export var id: String +@export var title: String +@export var subtitle: String +@export var description: String + +func _ready(): + $Title.text = title + $Subtitle.text = subtitle + $Description.text = description + +func _on_claim(): + if id == "QUICK_TRIGGER": + if player.fire_cooldown_duration > 0: + player.fire_cooldown_duration -= 0.05 + claimed.emit()