Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
1k jump
by andy wallace
you can play the game here:
that page has the original 1013 byte code as well
this is a breakdown of the code where i add whitespace and a lot of comments
with one or two small exceptions, this code is identical to the 1024 byte version
i made this game as an entry for pico-1k jam
hosted by paul nicholas (@liquidream)
thank for setting it up!
if you dig this, you might like my #tweetcarts, which are just 280 chars
--setting color palette
--7 is the "active" color for the game. all live elements will use it
--13, 136, 141 are the background colors that spread while the game is played
--the title and game over also use 5 for gret, but i got lucky in that i had exactly 4 earlier colors so i did not need to add it to my palette
--the number of resets since the game started
--this is used to kick the game into the title screen when it first launches
--shortening some function names
--reset game values
::_r:: --this flag is used by a goto when the player presses x to reset
g=1 --game/game over. 1 means playing, 0 means game over
t=0 --time, goes up by 1 each tick
n=0 --time for next platform spawn
s=0 --score
w=128 --width of the screen
--player values
v=-1 --y velocity
--array for the platforms
--increment the number of attempts
--play a beep. this is weird! it's a print function that plays audio via an escape char!
--clear the screen
--game loop
--this flag is used by a goto to return to this point and create frames
--"clearing" the screen by setting pixels to black
--this affects 1500 randomly selected pixels each frame
for i=0,1500 do
--grab a random x and y position
d = r(w)
e = r(w)
--see what color it is
c = pget(d,e)
--if it is the base color, set it to 0 (black)
if(c==1) pset(d, e, 0)
--if it is one of the background colors, expand it to a nearby pixel
if(c>1) pset(d+r(2)-1, e+r(2)-1, c)
--main physics/game loop
--the runs m times per frame, allowing the game to get faster over time
--the game speeds up every 7 points
--the maximum is 12 ticks per frame (i've never gotten this far)
--if g is 0 (game over), the physics loop will not run at all
m = min(12, 2+s/7) * g
for j=1,m do
--move player x position from button input
--based on
--max(.3,-v*1.2) modulates the speed based on the y velocity
--the player moves faster when going up
if(b()>0 and b()<3) x+=(b()*2-3) * max(.3,-v*1.2)
--update y position of the player
v+=.01 --gravity
y+=v --add the velocity to the y position
--go through all platforms
--z represents the platform object for each iteration of the loop
for k,z in pairs(o)do
--move platform up
z.y-=.14 --this value is very small because it will happen m times per frame
c=1 --assume the platform will use the default color
--rectangular hit detection on the player
if abs(x-z.x)<9 and abs(y-z.y)<7 then
--increase the color to one of the background colors
c = 2+s%3
--set the player velocity go upward
v = -0.9
--increase the score
--play a little sound
--draw the rectangle for the platform
--this happens multiple times each frame, but that's fine
--if the color is above 1, it got set when the player hit the platform and we can remove it from the list
if(c>1) del(o,z)
--t is the timer, n is the time for the next spawn
--if t is greater than n, it's time for a new platform
if t>n then
--add a new platform at a random x position and a y that is just past the bottom of the screen
--increase the next time to spawn a platform
--as the game goes on and m gets bigger, the random range increases
--increase the timer
--end of the physics loop
--this next part deals with drawing the title/instructions and player
--the decoration escape string that multiple text draws use
f = "\#5\^t\^w"
--although g controls if game is over, i set this based on if the player's y is greater than 128 or lower than 0 (meaning they are off screen)
if y>w or y<0 then
--if g is still 1 and this isn't the first time we've reached this screen (a>1) play a little sound
if(g>0and a>1) print("\af#..f#..e7..e7")
--set g to 0 to make it game over
--a lot of this text uses the "?" version of the print command
--you can find some info about it here:
--draw the score using the formatting saved as f earlier
--draw the instructions
?"\#5⬅️ & ➡️ to move",35,72
?"\#5❎ to start",43,82
--if the user presses x, go to ::_r:: to reset the game
if(b(5)) goto _r
--things we draw if the game is still going
--the player is a mess of trig to allow it to spin, so i shortened the names of cos() and sin() to save chars
--draw a dot at the top of the screen randomly. this is to show the dangerous border on the top of the screen
--drawing a player that rotates as it moves was the last thing i did
--it's a little sloppy because i had some chars to spare and thought it would be fun
--this is a mess of bad variable names. pretty much just the next single letter name i had available
e = -x/30 --the current angle to rotate the player. based on their x position
j = x+c(e)*3 --x1 for the line that makes the player's arm
k = y+z(e)*3 --y1 for the line that makes the player's arm
u = x-c(e)*3 --x2 for the line that makes the player's arm
h = y-z(e)*3 --y2 for the line that makes the player's arm
--draw the line for the player arm
--the "body" is a set of lines that run perpendicular to the arm line
--first, change the angle to add 90 degrees (pi/2 radians)
e += .25
--this loop draws lines from 25% of the arm line to 75%
for i=-1,1,.25 do
p = .5 + i/4 --get the percentage
--get the x and y position of the base point along the arm line
--more bad variable names
l = p*j + u*(1-p) --x
m = p*k + h*(1-p) --y
--by default, the vertical line for the body will extend 3 pixels in either direciton
--if this point is in the center, i don't have it extend down
if(abs(i)<.8) d=0
--draw a vertical line around the center point from the arm line
line( l+c(e)*3, m+z(e)*3, l-c(e)*d, m-z(e)*d )
--give the player a head in the form of a circle
circ( x+c(e)*4, y+z(e)*4, 2)
--draw the score in the top left of the screen
--if the game just started, instead of playing i want to be on the title screen
--this is a slight mod on the game over screen
--if a is 1, that means the game just started and we should end the round
if a<2 then
--move the player off screen to kill them
--write the game title over the score
?f.."\#41k jump",37,48
--add in some credits so we know who made this thing!
?"by @andy_makes",36,99
--draw everything to the screen
--return to the ::_:: and reapeat everything for next frame!
goto _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment