extends KinematicBody2D
class_name Player
export(int) var JUMPFORCE = -225
export(int) var JUMPRELEASEFORCE = -115
export(int) var MAXSPEED = 100
export(int) var ACCELERATION = 20
export(int) var FRICTION = 15
export(int) var GRAVITY = 6
export(int) var ADDITIONALFALLGRAVITY = 4
var velocity = Vector2.ZERO
func physicsprocess(delta):
applygravity()
var input = Vector2.ZERO
input.x = Input.getactionstrength("right") - Input.getaction_strength("left")
if input.x == 0:
apply_friction()
$AnimatedSprite.animation = "Idle"
else:
apply_acceleration(input.x)
$AnimatedSprite.animation = "Run"
if input.x > 0:
$AnimatedSprite.flip_h = false
elif input.x < 0:
$AnimatedSprite.flip_h = true
if is_on_floor():
if Input.is_action_pressed("Jump"):
velocity.y= JUMP_FORCE
else:
$AnimatedSprite.animation = "Jump"
if Input.is_action_just_released("Jump") and velocity.y < -80:
velocity.y = JUMP_RELEASE_FORCE
if velocity.y > 0:
velocity.y += ADDITIONAL_FALL_GRAVITY
var was_in_air = not is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
var just_landed = is_on_floor() and was_in_air
if just_landed:
$AnimatedSprite.animation = "Run"
$AnimatedSprite.frame = 1
func apply_gravity():
velocity.y += GRAVITY
func applyfriction():
velocity.x = movetoward(velocity.x, 0, FRICTION)
func applyacceleration(amount):
velocity.x = movetoward(velocity.x, MAX_SPEED * amount, ACCELERATION)
pass