Skip to content

Instantly share code, notes, and snippets.

@futureperfect
Created March 6, 2018 08:24
Show Gist options
  • Save futureperfect/84fcf652bd37fcc1a615ecab538ba12c to your computer and use it in GitHub Desktop.
Save futureperfect/84fcf652bd37fcc1a615ecab538ba12c to your computer and use it in GitHub Desktop.
PICO-8 Demo of a ball moving with arrow keys
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