Play ball with the enemy

Enemy can return the ball to the player
This commit is contained in:
Mathilde Grapin 2023-06-27 21:25:32 +02:00
parent 332c0fb0e1
commit e0633efcbe
14 changed files with 139 additions and 44 deletions

View file

@ -0,0 +1,7 @@
class_name CanGoToBallCondition
extends ConditionLeaf
func tick(actor, _blackboard):
if actor.next_target != null && actor.has_thrown_ball && !actor.collide_with_ball:
return SUCCESS
return FAILURE

View file

@ -0,0 +1,12 @@
class_name CanReturnBallCondition
extends ConditionLeaf
func tick(actor, _blackboard):
if (
actor.has_thrown_ball
&& actor.next_target != null
&& actor.collide_with_ball
&& !actor.current_ball.aim_to_bottom()
):
return SUCCESS
return FAILURE

View file

@ -1,8 +1,11 @@
class_name CanWaitCodition
extends ConditionLeaf
func tick(_actor, _blackboard):
func tick(actor, _blackboard):
if actor.next_target != null:
return FAILURE
var num = randi_range(0, 1)
if num == 0:
return SUCCESS
return FAILURE
if num == 1:
return FAILURE
return SUCCESS

View file

@ -0,0 +1,13 @@
class_name GetBallDestinationAction
extends ActionLeaf
func tick(actor: Node, blackboard: Blackboard):
# var rand_cell: Vector2i = actor.tile_map.get_random_top_cell()
# 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
#
blackboard.set_value("destination", actor.next_target)
return SUCCESS

View file

@ -1,13 +0,0 @@
class_name GetRandomDestinationAction
extends ActionLeaf
func tick(actor: Node, blackboard: Blackboard):
var rand_cell: Vector2i = actor.tile_map.get_random_top_cell()
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
blackboard.set_value("destination", destination)
return SUCCESS

View file

@ -1,5 +0,0 @@
class_name IsIdleCondition
extends ConditionLeaf
func tick(_actor, _blackboard):
return SUCCESS

View file

@ -0,0 +1,17 @@
class_name ReturnBallAction
extends ActionLeaf
func before_run(actor, _blackboard):
actor.play_throw_animation()
func tick(actor, blackboard):
if !actor.is_throw_animation_finished:
return RUNNING
else:
print("enemy return ball!")
var target = blackboard.get_value("target")
actor.return_ball(target)
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.play("idle")

View file

@ -1,16 +1,11 @@
class_name ThrowBallAction
extends ActionLeaf
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
actor.play_throw_animation()
func tick(actor, blackboard):
actor.animation_player.play("throw")
if !is_animation_finished:
if !actor.is_throw_animation_finished:
return RUNNING
else:
var target = blackboard.get_value("target")
@ -19,8 +14,4 @@ func tick(actor, blackboard):
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.speed_scale = 1
actor.animation_player.play("idle")
func _on_animation_finished(_anim_name):
is_animation_finished = true