Player throw back the ball from walk or idle state

This commit is contained in:
Mathilde Grapin 2023-06-18 20:30:25 +02:00
parent 1aff1c2e38
commit 332c0fb0e1
16 changed files with 165 additions and 25 deletions

View file

@ -3,7 +3,7 @@ extends ActionLeaf
func tick(actor: Node, blackboard: Blackboard):
var rand_cell: Vector2i = actor.tile_map.get_random_top_cell()
actor.tile_map.set_cell(0, Vector2i(rand_cell.x, rand_cell.y), 2, Vector2i(0, 0), 0) # debug purpose
actor.tile_map.reset_and_set_destination_cell(rand_cell)
var destination = actor.tile_map.map_to_local(rand_cell)
destination.y += actor.Y_SPAWN_OFFSET

View file

@ -0,0 +1,12 @@
class_name GetRandomTargetAction
extends ActionLeaf
func tick(actor, blackboard):
var rand_cell: Vector2i = actor.tile_map.get_random_bottom_cell()
actor.tile_map.reset_and_set_target_cell(rand_cell)
var target = actor.tile_map.map_to_local(rand_cell)
blackboard.set_value("target", target)
return SUCCESS

View file

@ -14,3 +14,9 @@ func tick(actor: Node, blackboard: Blackboard):
if actor.position == destination:
return SUCCESS
return RUNNING
func after_run(actor, blackboard):
var destination = blackboard.get_value("destination")
destination.y -= actor.Y_SPAWN_OFFSET
var cell = actor.tile_map.local_to_map(destination)
actor.tile_map.set_cell(0, cell, 0, Vector2i(0, 0), 0) # debug purpose

View file

@ -1,25 +1,26 @@
class_name ThrowBallAction
extends ActionLeaf
var has_animation_finished = false
var is_animation_finished = false
func before_run(actor, _blackboard):
actor.animation_player.animation_finished.connect(_on_animation_finished)
actor.animation_player.speed_scale = 0.8
func tick(actor, _blackboard):
func tick(actor, blackboard):
actor.animation_player.play("throw")
if !has_animation_finished:
if !is_animation_finished:
return RUNNING
else:
actor.throw_ball()
var target = blackboard.get_value("target")
actor.throw_ball(target)
actor.has_thrown_ball = true
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.play("idle")
actor.animation_player.speed_scale = 1
actor.animation_player.play("idle")
func _on_animation_finished(_anim_name):
has_animation_finished = true
is_animation_finished = true