Player throw back the ball from walk or idle state
This commit is contained in:
parent
1aff1c2e38
commit
332c0fb0e1
16 changed files with 165 additions and 25 deletions
|
@ -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
|
||||
|
|
12
scripts/enemy/behavior_tree/get_random_target_action.gd
Normal file
12
scripts/enemy/behavior_tree/get_random_target_action.gd
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,7 +14,8 @@ func _ready():
|
|||
position = tile_map.map_to_local(spawn_cell)
|
||||
position.y += Y_SPAWN_OFFSET
|
||||
|
||||
func throw_ball():
|
||||
func throw_ball(target: Vector2):
|
||||
var ball = ball_scene.instantiate()
|
||||
ball.position = position
|
||||
ball.target = target
|
||||
tile_map.add_child(ball)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue