2023-06-12 18:50:58 +02:00
|
|
|
class_name Enemy
|
2023-06-11 23:38:54 +02:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
2023-06-12 18:50:58 +02:00
|
|
|
const Y_SPAWN_OFFSET = -8
|
|
|
|
@export var speed = 80
|
2023-06-12 22:06:48 +02:00
|
|
|
var has_thrown_ball = false
|
|
|
|
var ball_scene = preload("res://scenes/ball.tscn")
|
2023-06-11 23:38:54 +02:00
|
|
|
@onready var tile_map: TileMap = get_parent()
|
|
|
|
@onready var animation_player = $AnimationPlayer
|
2023-06-12 18:50:58 +02:00
|
|
|
@onready var sprite = $Sprite2D
|
2023-06-11 23:38:54 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
var spawn_cell: Vector2i = tile_map.get_top_spawn_cell()
|
|
|
|
position = tile_map.map_to_local(spawn_cell)
|
2023-06-12 18:50:58 +02:00
|
|
|
position.y += Y_SPAWN_OFFSET
|
2023-06-12 22:06:48 +02:00
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
func throw_ball(target: Vector2):
|
2023-06-12 22:06:48 +02:00
|
|
|
var ball = ball_scene.instantiate()
|
|
|
|
ball.position = position
|
2023-06-18 20:30:25 +02:00
|
|
|
ball.target = target
|
2023-06-12 22:06:48 +02:00
|
|
|
tile_map.add_child(ball)
|