Cleanup player
This commit is contained in:
parent
4658bf304f
commit
a9a9f05296
|
@ -1,26 +1,18 @@
|
||||||
class_name Player
|
class_name Player
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
const y_spawn_offset = -8
|
||||||
signal hit_ball
|
signal hit_ball
|
||||||
signal ball_starts_colliding
|
signal ball_starts_colliding
|
||||||
signal ball_stops_colliding
|
signal ball_stops_colliding
|
||||||
const Y_SPAWN_OFFSET = -8
|
|
||||||
@export var speed = 120
|
@export var speed = 120
|
||||||
@onready var animation_player = $AnimationPlayer
|
@onready var animation_player = $AnimationPlayer
|
||||||
@onready var sprite = $Sprite2D
|
@onready var sprite = $Sprite2D
|
||||||
@onready var tile_map: TileMap = get_parent()
|
@onready var tile_map: TileMap = get_parent()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var spawn_cell: Vector2i = tile_map.get_bottom_spawn_cell()
|
var spawn_cell = tile_map.get_bottom_spawn_cell()
|
||||||
position = tile_map.map_to_local(spawn_cell) + Vector2(0, Y_SPAWN_OFFSET)
|
position = tile_map.map_to_local(spawn_cell) + Vector2(0, y_spawn_offset)
|
||||||
|
|
||||||
func _on_area_2d_body_entered(_body):
|
|
||||||
# As player’s Area2D only collide with balls
|
|
||||||
# We only enter this function after colliding with a ball
|
|
||||||
ball_starts_colliding.emit()
|
|
||||||
|
|
||||||
func _on_area_2d_body_exited(_body):
|
|
||||||
ball_stops_colliding.emit()
|
|
||||||
|
|
||||||
func get_input_direction():
|
func get_input_direction():
|
||||||
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||||
|
@ -42,3 +34,11 @@ func play_hit_ball_animation():
|
||||||
animation_player.play("hit_ball")
|
animation_player.play("hit_ball")
|
||||||
await animation_player.animation_finished
|
await animation_player.animation_finished
|
||||||
animation_player.speed_scale = 1
|
animation_player.speed_scale = 1
|
||||||
|
|
||||||
|
func _on_area_2d_body_entered(_body):
|
||||||
|
# As player’s Area2D only collide with balls
|
||||||
|
# We only enter this function after colliding with a ball
|
||||||
|
ball_starts_colliding.emit()
|
||||||
|
|
||||||
|
func _on_area_2d_body_exited(_body):
|
||||||
|
ball_stops_colliding.emit()
|
||||||
|
|
Loading…
Reference in a new issue