✨ Upgradable
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
class_name Tower
|
||||
|
||||
extends Area2D
|
||||
|
||||
signal tower_broken
|
||||
|
@@ -1,3 +1,5 @@
|
||||
class_name Player
|
||||
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 1200
|
||||
|
@@ -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
|
||||
|
57
scripts/ui/reward_claim_screen.gd
Normal file
57
scripts/ui/reward_claim_screen.gd
Normal file
@@ -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
|
22
scripts/ui/reward_item.gd
Normal file
22
scripts/ui/reward_item.gd
Normal file
@@ -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()
|
Reference in New Issue
Block a user