Skip to content

Instantly share code, notes, and snippets.

@hodgej
Created June 4, 2019 21:09
Show Gist options
  • Save hodgej/d8468a991ca8f1ef18b7fe2597779469 to your computer and use it in GitHub Desktop.
Save hodgej/d8468a991ca8f1ef18b7fe2597779469 to your computer and use it in GitHub Desktop.
extends KinematicBody2D
const FRICTION = Vector2(10,0)
var speed = -800
var turn_speed = 5
var backup_speed = -250
var backup_turn_speed = 3
var motion = transform.y * speed
var input_enabled = true
#-----MOVEMENT------
func _physics_process(delta):
if input_enabled == true:
if Input.is_action_pressed("forward"):
motion = transform.y * speed
elif Input.is_action_pressed("backward"):
motion = transform.y * - backup_speed
if Input.is_action_pressed("left"):
motion += transform.x * backup_speed
rotation += -backup_turn_speed * delta
elif Input.is_action_pressed("right"):
motion += transform.x * -backup_speed
rotation += backup_turn_speed * delta
else:
if motion > Vector2(0,0):
motion -= FRICTION
else:
motion = Vector2(0,0)
if Input.is_action_pressed("left") and Input.is_action_pressed("forward"):
motion += transform.x * speed
rotation += -turn_speed * delta
elif Input.is_action_pressed("right") and Input.is_action_pressed("forward"):
motion += transform.x * -speed
rotation += turn_speed * delta
move_and_slide(motion)
else:
pass
#----- GEARS -----
#gears are called from group.
func gear1():
print("Gear one engaged!")
speed = -800
turn_speed = 5
$Camera2D.smoothing_speed = 5
func gear2():
print("Gear two engaged!")
speed = -1500
turn_speed = 7
$Camera2D.smoothing_speed = 10
func gear3():
print("Gear three engaged!")
speed = -2000
turn_speed = 10
$Camera2D.smoothing_speed = 12.5
func barracade_hit():
modulate = Color(.2, .2, .4)
input_enabled = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment