Fix enemy return ball two times each time

This commit is contained in:
Mathilde Grapin 2023-07-01 17:12:02 +02:00
parent a9a9f05296
commit 2b11ec8638
10 changed files with 29 additions and 42 deletions

View file

@ -3,8 +3,8 @@ extends ConditionLeaf
func tick(actor, _blackboard):
if (
actor.next_target != null &&
actor.ball_in_game() &&
actor.next_destination != null &&
!actor.collide_with_ball
):
return SUCCESS

View file

@ -4,8 +4,8 @@ extends ConditionLeaf
func tick(actor, _blackboard):
if (
actor.ball_in_game() &&
actor.next_target != null &&
actor.collide_with_ball
actor.collide_with_ball &&
!actor.ball_aims_to_bottom
):
return SUCCESS
return FAILURE

View file

@ -1,10 +0,0 @@
class_name CanWaitCodition
extends ConditionLeaf
func tick(actor, _blackboard):
if (
actor.next_target == null
):
return SUCCESS
return FAILURE

View file

@ -2,5 +2,5 @@ class_name GetBallDestinationAction
extends ActionLeaf
func tick(actor: Node, blackboard: Blackboard):
blackboard.set_value("destination", actor.next_target)
blackboard.set_value("destination", actor.next_destination)
return SUCCESS

View file

@ -11,6 +11,7 @@ func tick(actor: Node, blackboard: Blackboard):
actor.move_to(destination)
if actor.position == destination:
actor.next_destination == null
return SUCCESS
return RUNNING

View file

@ -4,7 +4,7 @@ extends ActionLeaf
func before_run(actor, _blackboard):
actor.play_hit_ball_animation()
func tick(actor, blackboard):
func tick(actor, _blackboard):
if !actor.hit_ball_animation_finished:
return RUNNING
actor.throw_ball()

View file

@ -1,8 +0,0 @@
class_name WaitAction
extends ActionLeaf
func before_run(actor, _blackboard):
actor.play_idle_animation()
func tick(_actor, _blackboard):
return RUNNING

View file

@ -6,9 +6,10 @@ const ball_name = "Ball"
const y_spawn_offset = -8
signal hit_ball
var speed = 80
var next_target
var next_destination
var collide_with_ball = false
var hit_ball_animation_finished = false
var ball_aims_to_bottom = false
@onready var tile_map: TileMap = get_parent()
@onready var animation_player = $AnimationPlayer
@onready var sprite = $Sprite2D
@ -32,7 +33,6 @@ func throw_ball():
func return_ball():
hit_ball.emit()
next_target = null
func flip_sprite(destination):
sprite.flip_h = position.x > destination.x
@ -52,9 +52,13 @@ func play_walk_animation():
func _on_hit_ball_animation_finished(_anim_name):
hit_ball_animation_finished = true
func _on_notify_enemy(new_target):
# TODO: add to new_target an offset depending from where the enemy come from
next_target = tile_map.map_to_local(new_target)
func _on_notify_enemy(ball_target: Vector2i):
if tile_map.is_in_bottom_area(ball_target):
ball_aims_to_bottom = true
else:
ball_aims_to_bottom = false
# TODO: add to ball_target an offset depending from where the enemy come from
next_destination = tile_map.map_to_local(ball_target)
func _on_area_2d_body_entered(_body):
collide_with_ball = true