Created
January 31, 2018 04:46
-
-
Save emersonmx/70b0e2d90251893ddb0e865dde786df6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends KinematicBody2D | |
const GRAVITY = 20 | |
const SPEED = 300 | |
const JUMP_HEIGHT = -600 | |
const FLOOR_NORMAL = Vector2(0, -1) | |
var velocity = Vector2() | |
func _physics_process(delta): | |
velocity.y += GRAVITY | |
velocity.x = 0 | |
if Input.is_action_pressed('ui_left'): | |
velocity.x = -SPEED | |
elif Input.is_action_pressed('ui_right'): | |
velocity.x = SPEED | |
if Input.is_action_just_pressed('ui_cancel'): | |
position = Vector2(512, 80) | |
velocity = Vector2() | |
if is_on_floor(): | |
velocity.y += GRAVITY * 10 | |
if is_on_floor() and Input.is_action_just_pressed('ui_select'): | |
velocity.y = JUMP_HEIGHT | |
velocity = move_and_slide(velocity, FLOOR_NORMAL, 25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment