37 lines
797 B
GDScript
37 lines
797 B
GDScript
extends CharacterBody2D
|
|
|
|
@export var speed = 50
|
|
@export var gravity = 50
|
|
@export var jump = 700
|
|
|
|
var max_jumps = 2;
|
|
var jumpcount = 2;
|
|
|
|
var input_direction = 0
|
|
|
|
func get_input():
|
|
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
|
|
|
|
|
|
velocity.x = input_direction * speed
|
|
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
|
|
|
|
func _physics_process(delta):
|
|
if is_on_floor():
|
|
jumpcount = max_jumps
|
|
get_input()
|
|
velocity.y += gravity
|
|
move_and_slide()
|