Add attack and attacked method to Unit

This commit is contained in:
CactiChameleon9 2022-03-13 19:13:01 +00:00
parent 25a400f31f
commit 1d30a03966

View File

@ -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: