bovido/scripts/enemy.gd
Mathilde Grapin 92ccf7279d Instanciate a ball
Make the enemy throw a ball. It just instanciate a ball in the scene but
does not move it.
2023-06-12 22:06:48 +02:00

21 lines
556 B
GDScript

class_name Enemy
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
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)