summaryrefslogtreecommitdiff
path: root/stage/stage.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2025-02-12 20:05:59 +0100
committerDaniel Weipert <git@mail.dweipert.de>2025-02-12 20:05:59 +0100
commit218748f67a6a6b35efc4a732ad11426d0f528709 (patch)
treee58504dd758ce6525844872007221cda2a8b6926 /stage/stage.gd
parentf6c81b065cf4d7f1302a50f2f72cfab32204a1ec (diff)
next commitHEADmain
Diffstat (limited to 'stage/stage.gd')
-rw-r--r--stage/stage.gd48
1 files changed, 40 insertions, 8 deletions
diff --git a/stage/stage.gd b/stage/stage.gd
index 9b1689f..b25e1da 100644
--- a/stage/stage.gd
+++ b/stage/stage.gd
@@ -22,6 +22,9 @@ func _ready() -> void:
for tile in $Floor.get_used_cells():
grid.set_point_solid(tile, false)
+ for node in find_children("PlayerUnit*", "PlayerUnit"):
+ grid.set_point_solid($Ground.local_to_map(node.global_position - $Floor.position), true)
+
grid_selector.move_mode_max_range = Network.current_player.current_move_points
# teams
@@ -37,9 +40,9 @@ func _ready() -> void:
teams["2"] = team_two
if multiplayer.is_server():
- Network.local_player.set_current_team_name("1")
+ Network.local_player.current_team_name = "1"
else:
- Network.local_player.set_current_team_name("2")
+ Network.local_player.current_team_name = "2"
grid_selector.current_team = Network.local_player.current_team_name
@@ -59,10 +62,10 @@ func _ready() -> void:
func _input(event: InputEvent) -> void:
- if event.is_action_pressed("menu") and Network.is_my_turn():
- $HUDMain.visible = true
+ if event.is_action_pressed("menu"):
grid_selector.process_mode = Node.PROCESS_MODE_DISABLED
- $HUDMain/PanelContainer/VBoxContainer/Button.grab_focus()
+ $HUDMain.enable() # TODO: shouldn't be possible to open when unitmenu open
+ $HUDUnit.visible = false
@rpc("any_peer", "call_local")
@@ -87,9 +90,12 @@ func place_unit(unit_position: Vector2, team: String) -> void:
var unit = preload("res://unit/unit.tscn").instantiate()
unit.global_position = unit_position + $Floor.position
unit.current_team = team
+ unit.current_player = Network.current_player
unit.modulate = Network.current_player.get_color()
add_child(unit, true)
+ Network.current_player.units.append(unit)
+
# block unit tile for movement
grid.set_point_solid($Ground.local_to_map(unit_position), true)
@@ -124,13 +130,39 @@ func _on_grid_selector_move_mode_confirmed(path: Array) -> void:
grid_selector.current_state = grid_selector.get_node("StateSelect")
grid_selector.current_state.draw($Ground.local_to_map(path[path.size() - 1]))
- Network.current_player.set_current_move_points(Network.current_player.current_move_points - (path.size() - 1))
+ #Network.current_player.set_current_move_points(Network.current_player.current_move_points - (path.size() - 1))
+ Network.current_player.current_move_points -= path.size() - 1
grid_selector.move_mode_max_range = Network.current_player.current_move_points
func _on_grid_selector_range_select_confirmed(grid_position: Vector2i, entity: Node2D) -> void:
- entity.queue_free()
- grid.set_point_solid(grid_position, false)
+ if grid_selector.range_select_current_mode == GridSelectorStateRangeSelect.Mode.Attack:
+ Network.current_player.current_attack_points -= 1
+ attack_entity.rpc(grid_position, grid_selector.current_entity.get_path(), entity.get_path())
+
+@rpc("any_peer", "call_local")
+func attack_entity(grid_position: Vector2i, attacking_entity_node_path: String, target_entity_node_path: String):
+ var attacking_entity := get_node(attacking_entity_node_path) as Unit
+ var target_entity = get_node(target_entity_node_path)
+
+ if target_entity is PlayerUnit:
+ target_entity.current_hp -= 1
+ print(target_entity, target_entity.current_hp)
+ if target_entity.current_hp <= 0:
+ target_entity.queue_free()
+ print("GAME OVER!!")
+
+ elif target_entity is Unit:
+ var damage: int = attacking_entity.unit_data.attack - target_entity.unit_data.defense
+ if damage > 0:
+ target_entity.current_hp -= damage
+
+ if target_entity.current_hp <= 0:
+ if target_entity in Network.current_player.units:
+ target_entity.current_player.units.erase(target_entity)
+
+ target_entity.queue_free()
+ grid.set_point_solid(grid_position, false)
func _on_grid_selector_moved(grid_position: Vector2i) -> void: