Created
April 19, 2019 16:04
-
-
Save ryonagana/1aeadb9383f5b47077528cf9d5ee58a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = Vector2(0,900) | |
const WALK_SPEED = 250.0 | |
const JUMP_SPEED = 450 | |
const DOWN_FORCE = Vector2(0,-1) | |
var linear_vel = Vector2() | |
const MAX_FALLING_SPEED = 1400 | |
var has_double_jump = false; | |
var jump_count = 2 | |
const MAX_JUMPS_POSSIBLE = 2 | |
var light_mode = true; | |
func jump(force): | |
if Input.is_action_pressed("jump"): | |
linear_vel.y = -force | |
func _input(event): | |
if event is InputEventKey: | |
if jump_count < MAX_JUMPS_POSSIBLE and Input.is_action_pressed("jump"): | |
#this cut the force of second jump into half | |
var jmp_force = JUMP_SPEED | |
if jump_count >= 1: | |
jmp_force = jmp_force - 180 | |
jump(jmp_force) | |
jump_count += 1 | |
if Input.is_action_just_released("light_mode"): | |
light_mode = not light_mode | |
print(light_mode) | |
func _physics_process(delta): | |
#apply gravity | |
linear_vel += delta * GRAVITY | |
if linear_vel.y > MAX_FALLING_SPEED: | |
linear_vel.y = clamp(linear_vel.y, 0, MAX_FALLING_SPEED) | |
linear_vel = move_and_slide(linear_vel, DOWN_FORCE, 25.0) | |
var on_floor = is_on_floor() | |
var speed = 0 | |
if Input.is_action_pressed("ui_left"): | |
speed -= 1 | |
if Input.is_action_pressed("ui_right"): | |
speed += 1 | |
speed *= WALK_SPEED | |
if on_floor: | |
jump_count = 0 | |
linear_vel.x = lerp(linear_vel.x, speed, 0.1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment