Created
November 2, 2017 23:29
-
-
Save anonymous/f7eafa69414c1a8151039b4fc6f61f80 to your computer and use it in GitHub Desktop.
Ritz Survival Game
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 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