Clean up enemy

This commit is contained in:
Mathilde Grapin 2023-07-01 13:26:45 +02:00
parent a08afcb147
commit a56ffa78c5
13 changed files with 90 additions and 99 deletions

View file

@ -2,6 +2,10 @@ class_name CanGoToBallCondition
extends ConditionLeaf
func tick(actor, _blackboard):
if actor.next_target != null && actor.has_thrown_ball && !actor.collide_with_ball:
if (
actor.next_target != null &&
actor.ball_in_game() &&
!actor.collide_with_ball
):
return SUCCESS
return FAILURE

View file

@ -3,10 +3,9 @@ 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()
actor.ball_in_game() &&
actor.next_target != null &&
actor.collide_with_ball
):
return SUCCESS
return FAILURE

View file

@ -2,6 +2,6 @@ class_name CanThrowBallCondition
extends ConditionLeaf
func tick(actor, _blackboard):
if !actor.has_thrown_ball:
if !actor.ball_in_game():
return SUCCESS
return FAILURE

View file

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

View file

@ -2,12 +2,5 @@ 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,12 +0,0 @@
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

@ -3,20 +3,19 @@ extends ActionLeaf
func before_run(actor, blackboard):
var destination = blackboard.get_value("destination")
actor.sprite.flip_h = actor.position.x > destination.x
actor.animation_player.play("walk")
actor.flip_sprite(destination)
actor.play_walk_animation()
func tick(actor: Node, blackboard: Blackboard):
var destination = blackboard.get_value("destination")
var delta = get_physics_process_delta_time()
actor.position = actor.position.move_toward(destination, delta * actor.speed)
actor.move_to(destination)
if actor.position == destination:
return SUCCESS
return RUNNING
func after_run(actor, blackboard):
actor.play_idle_animation()
# Debug
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
actor.reset_tile(destination)

View file

@ -2,15 +2,13 @@ class_name ReturnBallAction
extends ActionLeaf
func before_run(actor, _blackboard):
actor.play_throw_animation()
actor.play_hit_ball_animation()
func tick(actor, blackboard):
if !actor.is_throw_animation_finished:
func tick(actor, _blackboard):
if !actor.hit_ball_animation_finished:
return RUNNING
else:
var target = blackboard.get_value("target")
actor.return_ball(target)
return SUCCESS
actor.return_ball()
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.play("idle")

View file

@ -2,16 +2,13 @@ class_name ThrowBallAction
extends ActionLeaf
func before_run(actor, _blackboard):
actor.play_throw_animation()
actor.play_hit_ball_animation()
func tick(actor, blackboard):
if !actor.is_throw_animation_finished:
if !actor.hit_ball_animation_finished:
return RUNNING
else:
var target = blackboard.get_value("target")
actor.throw_ball(target)
actor.has_thrown_ball = true
return SUCCESS
actor.throw_ball()
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.play("idle")
actor.play_idle_animation()

View file

@ -2,7 +2,7 @@ class_name WaitAction
extends ActionLeaf
func before_run(actor, _blackboard):
actor.animation_player.play("idle")
actor.play_idle_animation()
func tick(_actor, _blackboard):
return RUNNING