extends CharacterBody2D
var walk
var flip
var SPEED = 400.0
var JUMP_VELOCITY = -700.0
var sprinting_speed = 400
var big_jump = -300
var soup = -300
var idle
var jump
var mach
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
walk = get_node("SprPlayerMove1")
idle = get_node("SprPlayerIdle0")
jump = get_node("SprPlayerFall0")
mach = get_node("SprPlayerMach40")
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
jump.set_visible(true)
idle.set_visible(false)
walk.set_visible(false)
else:
jump.set_visible(false)
idle.set_visible(true)
if Input.is_action_just_pressed("Jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
jump.set_visible(true)
idle.set_visible(false)
walk.set_visible(false)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("Left", "Right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
if Input.is_action_just_pressed("Run"):
SPEED += sprinting_speed
mach.set_visible(true)
if Input.is_action_just_released("Run"):
SPEED = 400.0
mach.set_visible(false)
if Input.is_action_just_pressed("Up"):
JUMP_VELOCITY += big_jump
SPEED += soup
if Input.is_action_just_released("Up"):
SPEED = 400
if Input.is_action_just_released("Up"):
JUMP_VELOCITY = -700
if Input.is_action_pressed("Right"):
flip = 1
walk.set_flip_h(false)
walk.set_visible(true)
idle.set_flip_h(false)
idle.set_visible(false)
jump.set_flip_h(false)
mach.set_flip_h(false)
jump.set_flip_h(false)
jump.set_visible(false)
if Input.is_action_pressed("Left"):
flip = -1
walk.set_flip_h(true)
walk.set_visible(true)
idle.set_flip_h(true)
idle.set_visible(false)
jump.set_flip_h(false)
mach.set_flip_h(true)
jump.set_flip_h(true)
jump.set_visible(false)
if Input.is_action_just_released("Left"):
walk.set_visible(false)
idle.set_visible(true)
if Input.is_action_just_released("Right"):
walk.set_visible(false)
idle.set_visible(true)
if Input.is_action_pressed("Run"):
idle.set_visible(false)
walk.set_visible(false)
jump.set_visible(false)
Did you like this post? Tell us