Clean up path and names
This commit is contained in:
parent
92ccf7279d
commit
1aff1c2e38
46 changed files with 203 additions and 117 deletions
7
scripts/enemy/behavior_tree/can_throw_ball_condition.gd
Normal file
7
scripts/enemy/behavior_tree/can_throw_ball_condition.gd
Normal file
|
@ -0,0 +1,7 @@
|
|||
class_name CanThrowBallCondition
|
||||
extends ConditionLeaf
|
||||
|
||||
func tick(actor, _blackboard):
|
||||
if !actor.has_thrown_ball:
|
||||
return SUCCESS
|
||||
return FAILURE
|
8
scripts/enemy/behavior_tree/can_wait_condition.gd
Normal file
8
scripts/enemy/behavior_tree/can_wait_condition.gd
Normal 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
|
13
scripts/enemy/behavior_tree/get_random_destination_action.gd
Normal file
13
scripts/enemy/behavior_tree/get_random_destination_action.gd
Normal 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
|
5
scripts/enemy/behavior_tree/is_idle_condition.gd
Normal file
5
scripts/enemy/behavior_tree/is_idle_condition.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
class_name IsIdleCondition
|
||||
extends ConditionLeaf
|
||||
|
||||
func tick(_actor, _blackboard):
|
||||
return SUCCESS
|
16
scripts/enemy/behavior_tree/move_to_destination_action.gd
Normal file
16
scripts/enemy/behavior_tree/move_to_destination_action.gd
Normal 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
|
25
scripts/enemy/behavior_tree/throw_ball_action.gd
Normal file
25
scripts/enemy/behavior_tree/throw_ball_action.gd
Normal 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
|
8
scripts/enemy/behavior_tree/wait_action.gd
Normal file
8
scripts/enemy/behavior_tree/wait_action.gd
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue