44 lines
1.3 KiB
GDScript
44 lines
1.3 KiB
GDScript
extends CharacterBody2D
|
|
class_name Player
|
|
|
|
@export var move_speed: float = 100
|
|
@export var hp: int = 10
|
|
@export var push_strength: int = 50
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
var damage: float = 2
|
|
if SceneManager.player_next_scene_spawn_pos != Vector2(0, 0):
|
|
position = SceneManager.player_next_scene_spawn_pos
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta: float) -> void:
|
|
var move_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
|
velocity = move_vector * move_speed
|
|
|
|
if velocity.x > 0:
|
|
$AnimatedSprite2D.play("move_right")
|
|
elif velocity.x < 0:
|
|
$AnimatedSprite2D.play("move_left")
|
|
elif velocity.y > 0:
|
|
$AnimatedSprite2D.play("move_down")
|
|
elif velocity.y < 0:
|
|
$AnimatedSprite2D.play("move_up")
|
|
else:
|
|
$AnimatedSprite2D.stop()
|
|
|
|
# test
|
|
# get the last collision
|
|
# check if it's the block
|
|
# if it is the block then push it
|
|
var collision: KinematicCollision2D = get_last_slide_collision()
|
|
if collision:
|
|
var collisision_node = collision.get_collider()
|
|
if collisision_node.is_in_group("pushable"):
|
|
var collision_normal: Vector2 = collision.get_normal()
|
|
collisision_node.apply_central_force(-collision_normal * push_strength)
|
|
|
|
move_and_slide()
|
|
|