summaryrefslogtreecommitdiff
path: root/Towers
diff options
context:
space:
mode:
Diffstat (limited to 'Towers')
-rw-r--r--Towers/Components/Assets/attack-component.png (renamed from Towers/Assets/attack-component.png)bin191 -> 191 bytes
-rw-r--r--Towers/Components/Assets/attack-component.png.import (renamed from Towers/Assets/attack-component.png.import)6
-rw-r--r--Towers/Components/Assets/attack-component.png~ (renamed from Towers/Assets/attack-component.png~)bin206 -> 206 bytes
-rw-r--r--Towers/Components/Assets/burn-component.png (renamed from Towers/Assets/burn-component.png)bin175 -> 175 bytes
-rw-r--r--Towers/Components/Assets/burn-component.png.import (renamed from Towers/Assets/burn-component.png.import)6
-rw-r--r--Towers/Components/Assets/burn-component.png~ (renamed from Towers/Assets/burn-component.png~)bin175 -> 175 bytes
-rw-r--r--Towers/Components/Assets/frost-component.png (renamed from Towers/Assets/frost-component.png)bin176 -> 176 bytes
-rw-r--r--Towers/Components/Assets/frost-component.png.import (renamed from Towers/Assets/frost-component.png.import)6
-rw-r--r--Towers/Components/Assets/range-component.png (renamed from Towers/Assets/range-component.png)bin162 -> 162 bytes
-rw-r--r--Towers/Components/Assets/range-component.png.import (renamed from Towers/Assets/range-component.png.import)6
-rw-r--r--Towers/Components/Assets/range-component.png~ (renamed from Towers/Assets/range-component.png~)bin176 -> 176 bytes
-rw-r--r--Towers/Components/BurnComponent.gd11
-rw-r--r--Towers/Components/FrostComponent.gd11
-rw-r--r--Towers/Components/TowerComponent.gd15
-rw-r--r--Towers/Tower.gd120
-rw-r--r--Towers/Tower.tscn70
16 files changed, 232 insertions, 19 deletions
diff --git a/Towers/Assets/attack-component.png b/Towers/Components/Assets/attack-component.png
index bb9250c..bb9250c 100644
--- a/Towers/Assets/attack-component.png
+++ b/Towers/Components/Assets/attack-component.png
Binary files differ
diff --git a/Towers/Assets/attack-component.png.import b/Towers/Components/Assets/attack-component.png.import
index ef9a73b..4000c58 100644
--- a/Towers/Assets/attack-component.png.import
+++ b/Towers/Components/Assets/attack-component.png.import
@@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://gbknvb38euuq"
-path="res://.godot/imported/attack-component.png-648f34932bc6754ec1b1094b76b170bc.ctex"
+path="res://.godot/imported/attack-component.png-64ebd1f55ef8067c9f5d485d7df578be.ctex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://Towers/Assets/attack-component.png"
-dest_files=["res://.godot/imported/attack-component.png-648f34932bc6754ec1b1094b76b170bc.ctex"]
+source_file="res://Towers/Components/Assets/attack-component.png"
+dest_files=["res://.godot/imported/attack-component.png-64ebd1f55ef8067c9f5d485d7df578be.ctex"]
[params]
diff --git a/Towers/Assets/attack-component.png~ b/Towers/Components/Assets/attack-component.png~
index e2f80bc..e2f80bc 100644
--- a/Towers/Assets/attack-component.png~
+++ b/Towers/Components/Assets/attack-component.png~
Binary files differ
diff --git a/Towers/Assets/burn-component.png b/Towers/Components/Assets/burn-component.png
index 33f9f7e..33f9f7e 100644
--- a/Towers/Assets/burn-component.png
+++ b/Towers/Components/Assets/burn-component.png
Binary files differ
diff --git a/Towers/Assets/burn-component.png.import b/Towers/Components/Assets/burn-component.png.import
index 0783a55..433699a 100644
--- a/Towers/Assets/burn-component.png.import
+++ b/Towers/Components/Assets/burn-component.png.import
@@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://2djpswd6sgng"
-path="res://.godot/imported/burn-component.png-c625b666f5c33be88ffb5514acf984cb.ctex"
+path="res://.godot/imported/burn-component.png-de3b76cc035d6d043dda7fb037e0c7e4.ctex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://Towers/Assets/burn-component.png"
-dest_files=["res://.godot/imported/burn-component.png-c625b666f5c33be88ffb5514acf984cb.ctex"]
+source_file="res://Towers/Components/Assets/burn-component.png"
+dest_files=["res://.godot/imported/burn-component.png-de3b76cc035d6d043dda7fb037e0c7e4.ctex"]
[params]
diff --git a/Towers/Assets/burn-component.png~ b/Towers/Components/Assets/burn-component.png~
index c9c1619..c9c1619 100644
--- a/Towers/Assets/burn-component.png~
+++ b/Towers/Components/Assets/burn-component.png~
Binary files differ
diff --git a/Towers/Assets/frost-component.png b/Towers/Components/Assets/frost-component.png
index e1c12f7..e1c12f7 100644
--- a/Towers/Assets/frost-component.png
+++ b/Towers/Components/Assets/frost-component.png
Binary files differ
diff --git a/Towers/Assets/frost-component.png.import b/Towers/Components/Assets/frost-component.png.import
index d22126b..9ebc0d6 100644
--- a/Towers/Assets/frost-component.png.import
+++ b/Towers/Components/Assets/frost-component.png.import
@@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://ba3dmlce1wv2p"
-path="res://.godot/imported/frost-component.png-e1bd3aee287cb92be940679bf3553e5f.ctex"
+path="res://.godot/imported/frost-component.png-09974dabb6d634a6ff1c953d1b9c629b.ctex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://Towers/Assets/frost-component.png"
-dest_files=["res://.godot/imported/frost-component.png-e1bd3aee287cb92be940679bf3553e5f.ctex"]
+source_file="res://Towers/Components/Assets/frost-component.png"
+dest_files=["res://.godot/imported/frost-component.png-09974dabb6d634a6ff1c953d1b9c629b.ctex"]
[params]
diff --git a/Towers/Assets/range-component.png b/Towers/Components/Assets/range-component.png
index e5ef51e..e5ef51e 100644
--- a/Towers/Assets/range-component.png
+++ b/Towers/Components/Assets/range-component.png
Binary files differ
diff --git a/Towers/Assets/range-component.png.import b/Towers/Components/Assets/range-component.png.import
index c626726..9500e69 100644
--- a/Towers/Assets/range-component.png.import
+++ b/Towers/Components/Assets/range-component.png.import
@@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://dx07y4scyi5a1"
-path="res://.godot/imported/range-component.png-5b23d157d3796cb80d7b2edb7addabe5.ctex"
+path="res://.godot/imported/range-component.png-e61b3503df71027fb6ac2a7fbd9e5943.ctex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://Towers/Assets/range-component.png"
-dest_files=["res://.godot/imported/range-component.png-5b23d157d3796cb80d7b2edb7addabe5.ctex"]
+source_file="res://Towers/Components/Assets/range-component.png"
+dest_files=["res://.godot/imported/range-component.png-e61b3503df71027fb6ac2a7fbd9e5943.ctex"]
[params]
diff --git a/Towers/Assets/range-component.png~ b/Towers/Components/Assets/range-component.png~
index e1c12f7..e1c12f7 100644
--- a/Towers/Assets/range-component.png~
+++ b/Towers/Components/Assets/range-component.png~
Binary files differ
diff --git a/Towers/Components/BurnComponent.gd b/Towers/Components/BurnComponent.gd
new file mode 100644
index 0000000..11e9e3f
--- /dev/null
+++ b/Towers/Components/BurnComponent.gd
@@ -0,0 +1,11 @@
+extends TowerComponent
+
+
+func _init() -> void:
+ name = "Burn"
+ set_sprite(preload("res://Towers/Components/Assets/burn-component.png"))
+
+
+func on_shoot(target: Unit):
+ var effect = preload("res://Effects/BurnEffect.tscn").instantiate()
+ target.add_effect(effect)
diff --git a/Towers/Components/FrostComponent.gd b/Towers/Components/FrostComponent.gd
new file mode 100644
index 0000000..d6384a7
--- /dev/null
+++ b/Towers/Components/FrostComponent.gd
@@ -0,0 +1,11 @@
+extends TowerComponent
+
+
+func _init() -> void:
+ name = "Frost"
+ set_sprite(preload("res://Towers/Components/Assets/frost-component.png"))
+
+
+func on_shoot(target: Unit):
+ var effect = preload("res://Effects/SlowEffect.tscn").instantiate()
+ target.add_effect(effect)
diff --git a/Towers/Components/TowerComponent.gd b/Towers/Components/TowerComponent.gd
new file mode 100644
index 0000000..570b442
--- /dev/null
+++ b/Towers/Components/TowerComponent.gd
@@ -0,0 +1,15 @@
+class_name TowerComponent
+extends Resource
+
+
+var name: String
+var sprite: Sprite2D = Sprite2D.new()
+
+
+func set_sprite(texture: Texture2D):
+ sprite.texture = texture
+
+ sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
+ sprite.centered = false
+ sprite.scale = Vector2(2, 2)
+ sprite.name = name
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index 54687fd..4262af1 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -6,6 +6,7 @@ signal selected
signal deselected
static var selected_towers: Array[Tower]
+static var hovered_tower: Tower
var is_selected = false :
set(value):
@@ -16,12 +17,19 @@ var is_selected = false :
else:
Tower.selected_towers.erase(self)
deselected.emit()
- Client.stage.hud.tower.text = ""
is_selected = value
queue_redraw()
+ toggle_ui()
var is_hovered = false :
set(value):
+ if value:
+ hovered_tower = self
+ Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
+ else:
+ if hovered_tower == self:
+ hovered_tower = null
+ Input.set_default_cursor_shape(Input.CURSOR_ARROW)
is_hovered = value
queue_redraw()
@@ -30,16 +38,26 @@ var mobs_in_range: Array = []
#var selection_area: Area2D
# rpc owner id
-var owner_id = 1
+@export var owner_id = 1
@export var attack_range: int = 32
@export var attack_power: int = 1
@export var attack_speed: int = 1
+@export var components: Array[TowerComponent] = []
+
func _ready():
$Range/CollisionShape2D.shape.radius = attack_range
$ShootCooldown.wait_time = attack_speed
+
+ toggle_ui()
+
+ #for component in [
+ #preload("res://Towers/Components/FrostComponent.gd").new(),
+ #preload("res://Towers/Components/BurnComponent.gd").new(),
+ #]:
+ #add_component(component)
func _draw():
@@ -122,26 +140,50 @@ func _on_selectable_area_select(event: InputEvent) -> void:
+func add_component(component: TowerComponent):
+ components.append(component)
+ var sprite = component.sprite
+ $ComponentsAnchor.add_child(sprite)
+ redraw_components()
+
+func remove_component(component_name: String):
+ for component in components:
+ if component.name == component_name:
+ components.erase(component)
+ $ComponentsAnchor.remove_child($ComponentsAnchor.get_node(NodePath(component.name)))
+ break
+ redraw_components()
+
+func redraw_components():
+ for idx in range(components.size()):
+ var component = components[idx]
+ var sprite = $ComponentsAnchor.get_node(NodePath(component.name))
+ sprite.position.y = (idx + 1) * -16
+
+
func is_melee_range():
return attack_range <= (Client.stage.map.tile_set.tile_size.x * 2)
func shoot():
- if get_multiplayer_authority() != multiplayer.get_unique_id():
+ if not multiplayer.is_server():
# TODO: do shoot animation, but don't subtract hp
return
var target = mobs_in_range[0] as Unit
+ for component in components:
+ if component.has_method("on_shoot"):
+ component.on_shoot(target)
+
if is_melee_range():
target.set_hp(target.hp - 1)
else: # TODO
target.set_hp(target.hp - 1)
-func show_ui():
- # todo: show ui
- pass
+func toggle_ui():
+ $HUD.visible = is_selected
func get_region():
@@ -163,4 +205,70 @@ func get_rpc_properties() -> Dictionary:
"name": null,
"global_position": null,
"owner_id": null,
+ "attack_range": null,
}
+
+
+func _on_h_box_container_gui_input(event: InputEvent) -> void:
+ if event.is_action_pressed("select"):
+ get_viewport().set_input_as_handled()
+
+ for tower in selected_towers:
+ var found = false
+ for idx in range(tower.components.size()):
+ var component = tower.components[idx]
+ if component.name == "Frost":
+ found = true
+ tower.remove_component(component.name)
+ break
+
+ if not found:
+ tower.add_component(preload("res://Towers/Components/FrostComponent.gd").new())
+
+ var data = {"components": []}
+ for c in tower.components:
+ data["components"].append(c.name)
+ Client.update_tower(tower, data)
+
+
+func _on_h_box_container_2_gui_input(event: InputEvent) -> void:
+ if event.is_action_pressed("select"):
+ get_viewport().set_input_as_handled()
+
+ for tower in selected_towers:
+ var found = false
+ for idx in range(tower.components.size()):
+ var component = tower.components[idx]
+ if component.name == "Burn":
+ found = true
+ tower.remove_component(component.name)
+ break
+
+ if not found:
+ tower.add_component(preload("res://Towers/Components/BurnComponent.gd").new())
+
+ var data = {"components": []}
+ for c in tower.components:
+ data["components"].append(c.name)
+ Client.update_tower(tower, data)
+
+
+class NetworkData extends Resource:
+ var name: String
+ var position: Vector2
+
+func to_network_data() -> NetworkData:
+ var data = NetworkData.new()
+
+ data.name = name
+ data.position = global_position
+
+ return data
+
+static func from_network_data(data: NetworkData) -> Tower:
+ var tower: Tower = preload("res://Towers/Tower.tscn").instantiate()
+
+ tower.name = data.name
+ tower.global_position = data.position
+
+ return tower
diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn
index 4177a3a..6bff2e3 100644
--- a/Towers/Tower.tscn
+++ b/Towers/Tower.tscn
@@ -1,8 +1,10 @@
-[gd_scene load_steps=7 format=3 uid="uid://by1x56w21o165"]
+[gd_scene load_steps=10 format=3 uid="uid://by1x56w21o165"]
[ext_resource type="Script" path="res://Towers/Tower.gd" id="1_axo1d"]
[ext_resource type="Texture2D" uid="uid://b1b18rd0tqbar" path="res://core_outdoor.png" id="1_mrep8"]
[ext_resource type="PackedScene" uid="uid://cqktpc8c7ecn3" path="res://Game/Selection/SelectableArea.tscn" id="3_57d5u"]
+[ext_resource type="Texture2D" uid="uid://ba3dmlce1wv2p" path="res://Towers/Components/Assets/frost-component.png" id="4_ccrqc"]
+[ext_resource type="Texture2D" uid="uid://2djpswd6sgng" path="res://Towers/Components/Assets/burn-component.png" id="5_y7tf5"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_atm5x"]
size = Vector2(31, 31)
@@ -12,6 +14,23 @@ size = Vector2(31, 31)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_312i7"]
size = Vector2(32, 32)
+[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_spp26"]
+properties/0/path = NodePath(".:position")
+properties/0/spawn = true
+properties/0/replication_mode = 0
+properties/1/path = NodePath(".:owner_id")
+properties/1/spawn = true
+properties/1/replication_mode = 0
+properties/2/path = NodePath(".:attack_range")
+properties/2/spawn = true
+properties/2/replication_mode = 2
+properties/3/path = NodePath("Sprite2D:modulate")
+properties/3/spawn = true
+properties/3/replication_mode = 0
+properties/4/path = NodePath("ComponentsAnchor:modulate")
+properties/4/spawn = true
+properties/4/replication_mode = 0
+
[node name="Tower" type="StaticBody2D"]
y_sort_enabled = true
collision_layer = 4
@@ -48,6 +67,53 @@ one_shot = true
position = Vector2(16, 16)
shape = SubResource("RectangleShape2D_312i7")
+[node name="ComponentsAnchor" type="Marker2D" parent="."]
+position = Vector2(0, 32)
+
+[node name="HUD" type="CanvasLayer" parent="."]
+
+[node name="CenterContainer" type="CenterContainer" parent="HUD"]
+anchors_preset = 12
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="HUD/CenterContainer"]
+layout_mode = 2
+
+[node name="HBoxContainer" type="HBoxContainer" parent="HUD/CenterContainer/VBoxContainer"]
+layout_mode = 2
+mouse_default_cursor_shape = 2
+
+[node name="TextureRect" type="TextureRect" parent="HUD/CenterContainer/VBoxContainer/HBoxContainer"]
+custom_minimum_size = Vector2(32, 0)
+layout_mode = 2
+texture = ExtResource("4_ccrqc")
+stretch_mode = 5
+
+[node name="Label" type="Label" parent="HUD/CenterContainer/VBoxContainer/HBoxContainer"]
+layout_mode = 2
+text = "Frost"
+
+[node name="HBoxContainer2" type="HBoxContainer" parent="HUD/CenterContainer/VBoxContainer"]
+layout_mode = 2
+mouse_default_cursor_shape = 2
+
+[node name="TextureRect" type="TextureRect" parent="HUD/CenterContainer/VBoxContainer/HBoxContainer2"]
+custom_minimum_size = Vector2(32, 0)
+layout_mode = 2
+texture = ExtResource("5_y7tf5")
+stretch_mode = 5
+
+[node name="Label" type="Label" parent="HUD/CenterContainer/VBoxContainer/HBoxContainer2"]
+layout_mode = 2
+text = "Burn"
+
+[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
+replication_config = SubResource("SceneReplicationConfig_spp26")
+
[connection signal="input_event" from="." to="." method="_on_input_event"]
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
@@ -57,3 +123,5 @@ shape = SubResource("RectangleShape2D_312i7")
[connection signal="hover_enter" from="SelectableArea" to="." method="_on_selectable_area_hover_enter"]
[connection signal="hover_exit" from="SelectableArea" to="." method="_on_selectable_area_hover_exit"]
[connection signal="select" from="SelectableArea" to="." method="_on_selectable_area_select"]
+[connection signal="gui_input" from="HUD/CenterContainer/VBoxContainer/HBoxContainer" to="." method="_on_h_box_container_gui_input"]
+[connection signal="gui_input" from="HUD/CenterContainer/VBoxContainer/HBoxContainer2" to="." method="_on_h_box_container_2_gui_input"]