Created
March 6, 2018 08:24
-
-
Save futureperfect/84fcf652bd37fcc1a615ecab538ba12c to your computer and use it in GitHub Desktop.
PICO-8 Demo of a ball moving with arrow keys
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
pico-8 cartridge // http://www.pico-8.com | |
version 16 | |
__lua__ | |
-- move an ball on-screen | |
-- by erik hollembeak | |
SCREEN_WIDTH = 128 | |
SCREEN_HEIGHT = 128 | |
-- Ball definition | |
Ball = { | |
x = 64, | |
y = 64, | |
sprite = 0, | |
speed = 3 | |
} | |
-- screen is a manifold that wraps at edges | |
function _update() | |
if btn(0) then | |
Ball.x = (Ball.x - Ball.speed) % SCREEN_WIDTH | |
end | |
if btn(1) then | |
Ball.x = (Ball.x + Ball.speed) % SCREEN_WIDTH | |
end | |
if btn(2) then | |
Ball.y = (Ball.y - Ball.speed) % SCREEN_HEIGHT | |
end | |
if btn(3) then | |
Ball.y = (Ball.y + Ball.speed) % SCREEN_HEIGHT | |
end | |
end | |
function _draw() | |
cls() | |
rectfill(0, 0, 127, 127, 1) | |
spr(Ball.sprite, Ball.x, Ball.y) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment