bovido/scripts/enemy.gd

21 lines
556 B
GDScript3
Raw Normal View History

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)