Last active
March 24, 2018 03:46
-
-
Save baraujo/c970e9cfe31a9ca2374f345c632a10f7 to your computer and use it in GitHub Desktop.
Code for classic Pong clone made with PICO-8
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
pico-8 cartridge // http://www.pico-8.com | |
version 16 | |
__lua__ | |
-- pong-8 | |
-- https://baraujo42.itch.io | |
-- globals | |
player_speed = 1 | |
ball_speed = 0.75 | |
-- game objects | |
ball = {} | |
p1 = {} | |
p2 = {} | |
function _init() | |
p1.x = 1 | |
p1.w = 3 | |
p1.h = 15 | |
p2.x = 124 | |
p2.w = 3 | |
p2.h = 15 | |
reset() | |
end | |
-- update with 60 fps | |
function _update60() | |
move_ball() | |
move_player(p1, 1) | |
move_player(p2, 0) | |
detect_ball_collisions() | |
end | |
function _draw() | |
cls() | |
-- ball | |
circfill(ball.x, | |
ball.y, | |
ball.r, | |
7) | |
-- players | |
draw_player(p1) | |
draw_player(p2) | |
draw_score() | |
end | |
function reset() | |
reset_ball() | |
reset_player(p1) | |
reset_player(p2) | |
end | |
function reset_player(p) | |
p.y = 56 | |
p.vy = 0 | |
p.score = 0 | |
end | |
function reset_ball() | |
ball.x = 64 | |
ball.y = 64 | |
ball.vx = 0 | |
ball.vy = 0 | |
ball.r = 3 | |
ball_speed = 0.75 | |
-- initial ball direction | |
srand(time()) | |
ball_dir = flr(rnd(4)) | |
if(ball_dir == 0) then | |
ball.vx = ball_speed | |
ball.vy = ball_speed | |
elseif (ball_dir == 1) then | |
ball.vx = -ball_speed | |
ball.vy = ball_speed | |
elseif (ball_dir == 2) then | |
ball.vx = ball_speed | |
ball.vy = -ball_speed | |
elseif (ball_dir == 3) then | |
ball.vx = -ball_speed | |
ball.vy = -ball_speed | |
end | |
end | |
function draw_player(p) | |
rectfill(p.x, | |
p.y, | |
p.x + p.w, | |
p.y + p.h, | |
7) | |
end | |
function draw_score() | |
print("baraujo42.itch.io/pong-8", 15, 0) | |
print(p1.score, 50, 10) | |
print(p2.score, 70, 10) | |
print("p1: keys e/d", 0,120) | |
print("p2: keys up/down", 65,120) | |
end | |
-- see player keys in https://neko250.github.io/pico8-api/ | |
function move_player(p, i) | |
if(btn(2, i)) then | |
p.vy = -player_speed | |
elseif(btn(3, i)) then | |
p.vy = player_speed | |
else p.vy = 0 | |
end | |
p.y += p.vy | |
if(p.y < 0) then | |
p.y = 0 | |
elseif(p.y + p.h > 128) then | |
p.y = 128 - p.h | |
end | |
end | |
function move_ball() | |
ball.x += ball.vx | |
ball.y += ball.vy | |
end | |
function detect_ball_collisions() | |
if(ball.x + ball.r > 128) then | |
p1.score += 1 | |
sfx(1) | |
reset_ball() | |
elseif(ball.x - ball.r < 0) then | |
p2.score += 1 | |
sfx(2) | |
reset_ball() | |
elseif(ball.y + ball.r > 128 or | |
ball.y - ball.r < 0) then | |
ball.vy *= -1 | |
sfx(0) | |
end | |
-- p1 | |
if(ball.y + ball.r> p1.y and | |
ball.y - ball.r < p1.y + p1.h and | |
ball.x - ball.r < p1.x + p1.w) then | |
ball.vx = ball_speed | |
if(p1.vy > 0) then ball.vy -= 0.4 | |
elseif(p1.vy < 0) then ball.vy += 0.4 | |
end | |
sfx(0) | |
ball_speed += 0.1 | |
end | |
-- p2 | |
if(ball.y + ball.r > p2.y and | |
ball.y - ball.r < p2.y + p2.h and | |
ball.x + ball.r > p2.x) then | |
ball.vx = -ball_speed | |
if(p2.vy > 0) then ball.vy -= 0.4 | |
elseif(p2.vy < 0) then ball.vy += 0.4 | |
end | |
sfx(0) | |
ball_speed += 0.1 | |
end | |
end | |
__label__ | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
07777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007777 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000777000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000007777700000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000077777770000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000077777770000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000077777770000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000007777700000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000777000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
__sfx__ | |
00010000207500d7500e7501a75011750187500f750157500c7500b750137500a75010750097500f7500e750047500b7500975003750077500675006750057500475003750017500175002600026000160003600 | |
000200002805026050250502305022050200501f0501e0501d0501d0501c0501c0501b0501b0501b0501a0501a05019050190501805017050170501605015050130501305011050100500f0500e0500b05007050 | |
00020000251502415022150201501f1501e1501e1501d1501c1501c1501b1501b1501a1501915019150191501815017150161501515014150131501215011150101500e1500d1500c1500a150081500715006150 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment