Flopsy/objects/characters/player/player.gd

30 lines
890 B
GDScript

extends "res://objects/characters/character.gd"
enum PLAYER_STATES {
IDLE,
JUMP,
RUN,
INJURED
}
var player_state = PLAYER_STATES.IDLE
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Movement
if Input.is_action_pressed("move_left") and not Input.is_action_pressed("move_right"):
velocity.x = -GlobalConfig.DEFAULT_SPEED.x * delta
elif Input.is_action_pressed("move_right") and not Input.is_action_pressed("move_left"):
velocity.x = GlobalConfig.DEFAULT_SPEED.x * delta
else:
velocity.x = 0
# Jump
if Input.is_action_just_pressed("jump") and _check_jump():
_disable_snap()
position.y += get_floor_velocity().y * get_physics_process_delta_time() \
- GlobalConfig.GRAVITY.y * get_physics_process_delta_time() - 3
velocity.y = GlobalConfig.DEFAULT_JUMP.y * delta