GMTK-2024/gmtk_2024/scripts/player_movement.gd

38 lines
797 B
GDScript3
Raw Normal View History

2024-08-16 21:03:06 +02:00
extends CharacterBody2D
@export var speed = 50
2024-08-16 21:42:27 +02:00
@export var gravity = 50
2024-08-16 22:09:19 +02:00
@export var jump = 700
var max_jumps = 2;
var jumpcount = 2;
var input_direction = 0
2024-08-16 21:03:06 +02:00
func get_input():
2024-08-16 22:09:19 +02:00
var left = Input.is_action_pressed("player_left")
var right = Input.is_action_pressed("player_right")
if left and right:
input_direction = input_direction
elif left:
input_direction = -1
elif right:
input_direction = 1
else :
input_direction = 0
2024-08-16 21:03:06 +02:00
velocity.x = input_direction * speed
2024-08-16 22:09:19 +02:00
if Input.is_action_just_pressed("player_jump") and jumpcount > 0:
velocity.y = -1 *jump
jumpcount = jumpcount-1
elif Input.is_action_pressed("player_jump"):
velocity.y += -1 * 20
2024-08-16 21:03:06 +02:00
func _physics_process(delta):
2024-08-16 22:09:19 +02:00
if is_on_floor():
jumpcount = max_jumps
2024-08-16 21:03:06 +02:00
get_input()
2024-08-16 21:42:27 +02:00
velocity.y += gravity
2024-08-16 21:03:06 +02:00
move_and_slide()