diff --git a/src/classes/Unit.gd b/src/classes/Unit.gd index 5b21c13..e13a175 100644 --- a/src/classes/Unit.gd +++ b/src/classes/Unit.gd @@ -68,7 +68,6 @@ func move(movement : Vector2): var area_around = Grid.get_around_coordinate(Grid.position_to_coordinates(position, height), i) if not area_around.has(Grid.position_to_coordinates(_target_position, _target_height)): movement_points = movement_points - i - 1 - print(movement_points) break #change the z_index @@ -78,13 +77,27 @@ func move(movement : Vector2): z_index = 100 -func attack(): #TODO - if attack_points == 0: +func attack(damage : float, points : int, pattern : PoolVector2Array): #TODO + if attack_points != 0: #change animation to attacking - #make attacked change to hurt animation - #somehow change health values - #maybe using an attacked method?? - attack_points = 0 + $AnimationPlayer.play("Attack front") + + #selects all of the units within the attack pattern + # and calls their attacked method + for i in range(pattern.size()): + var coord = Grid.position_to_coordinates(position, height) + var selected_name = Grid.grid[coord.x + pattern[i].x][coord.y + pattern[i].y][0] + if selected_name: + get_node(("../" + selected_name)).attacked(damage, "") #TODO effects implementation + + #change the attack points left + attack_points = max(attack_points - points, 0) #keep >= 0 + + +func attacked(damage : float, effects : String): + $AnimationPlayer.play("Attacked front") + health -= damage + #probably do some stuff here TODO with death func _physics_process(delta: float) -> void: