Clean up path and names

This commit is contained in:
Mathilde Grapin 2023-06-13 21:36:01 +02:00
parent 92ccf7279d
commit 1aff1c2e38
46 changed files with 203 additions and 117 deletions

View file

@ -0,0 +1,7 @@
class_name CanThrowBallCondition
extends ConditionLeaf
func tick(actor, _blackboard):
if !actor.has_thrown_ball:
return SUCCESS
return FAILURE

View file

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

View file

@ -0,0 +1,13 @@
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.set_cell(0, Vector2i(rand_cell.x, rand_cell.y), 2, Vector2i(0, 0), 0) # debug purpose
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

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

View file

@ -0,0 +1,16 @@
class_name MoveToDestinationAction
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")
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)
if actor.position == destination:
return SUCCESS
return RUNNING

View file

@ -0,0 +1,25 @@
class_name ThrowBallAction
extends ActionLeaf
var has_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):
actor.animation_player.play("throw")
if !has_animation_finished:
return RUNNING
else:
actor.throw_ball()
actor.has_thrown_ball = true
return SUCCESS
func after_run(actor, _blackboard):
actor.animation_player.play("idle")
actor.animation_player.speed_scale = 1
func _on_animation_finished(_anim_name):
has_animation_finished = true

View file

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