Skip to content

Instantly share code, notes, and snippets.

Created November 2, 2017 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f7eafa69414c1a8151039b4fc6f61f80 to your computer and use it in GitHub Desktop.
Save anonymous/f7eafa69414c1a8151039b4fc6f61f80 to your computer and use it in GitHub Desktop.
Ritz Survival Game
extends Sprite
var t = Timer.new()
var vel = 0
var moving = false
var isLeft = false
func _ready():
set_process(true)
set_process_input(true)
t.set_wait_time(0.05)
t.set_one_shot(true)
func _process(delta):
if moving:
var degrees = -15.0
if isLeft:
degrees *= -1
self.set_rot(self.get_rot() + degrees * delta)
self.set_pos(Vector2(self.get_pos().x + vel, self.get_pos().y))
t.start()
yield(t, 'timeout')
func _input(event):
if event.is_action_pressed("move_left"):
vel = -10
moving = true
isLeft = true
if event.is_action_pressed("move_right"):
vel = 10
moving = true
isLeft = false
if event.is_action_released("move_left"):
vel = 0
moving = false
if event.is_action_released("move_right"):
vel = 0
moving = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment