2023-06-11 23:38:54 +02:00
|
|
|
|
class_name Player
|
|
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
|
signal hit
|
|
|
|
|
signal collide_with_ball
|
2023-06-11 23:38:54 +02:00
|
|
|
|
@export var speed = 120
|
|
|
|
|
var y_spawn_offset = -8
|
|
|
|
|
@onready var animation_player = $AnimationPlayer
|
|
|
|
|
@onready var sprite = $Sprite2D
|
|
|
|
|
@onready var tile_map: TileMap = get_parent()
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
|
var spawn_cell: Vector2i = tile_map.get_bottom_spawn_cell()
|
|
|
|
|
position = tile_map.map_to_local(spawn_cell)
|
|
|
|
|
position.y += y_spawn_offset
|
2023-06-18 20:30:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_area_2d_body_entered(body: Node2D):
|
|
|
|
|
# As player’s Area2D only collide with balls
|
|
|
|
|
# We only enter this function after colliding with a ball
|
|
|
|
|
collide_with_ball.emit()
|