Instanciate a ball
Make the enemy throw a ball. It just instanciate a ball in the scene but does not move it.
This commit is contained in:
parent
5970aa2ac2
commit
92ccf7279d
7 changed files with 143 additions and 48 deletions
7
scripts/can_throw_ball_condition.gd
Normal file
7
scripts/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
|
|
@ -3,6 +3,8 @@ extends CharacterBody2D
|
|||
|
||||
const Y_SPAWN_OFFSET = -8
|
||||
@export var speed = 80
|
||||
var has_thrown_ball = false
|
||||
var ball_scene = preload("res://scenes/ball.tscn")
|
||||
@onready var tile_map: TileMap = get_parent()
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
@onready var sprite = $Sprite2D
|
||||
|
@ -11,3 +13,8 @@ func _ready():
|
|||
var spawn_cell: Vector2i = tile_map.get_top_spawn_cell()
|
||||
position = tile_map.map_to_local(spawn_cell)
|
||||
position.y += Y_SPAWN_OFFSET
|
||||
|
||||
func throw_ball():
|
||||
var ball = ball_scene.instantiate()
|
||||
ball.position = position
|
||||
tile_map.add_child(ball)
|
||||
|
|
25
scripts/throw_ball_action.gd
Normal file
25
scripts/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
|
|
@ -4,5 +4,5 @@ extends ActionLeaf
|
|||
func before_run(actor, _blackboard):
|
||||
actor.animation_player.play("idle")
|
||||
|
||||
func tick(actor, blackboard):
|
||||
func tick(_actor, _blackboard):
|
||||
return RUNNING
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue