Ludum Dare #54compo
geom dsh
geom dsh
*An entire game fit within the limited space of a tweet!*
Full game code:
```
o=[0,3,7],h=b=f=0,s=2,setup=_=>createCanvas(400,400),draw=_=>{R=rect,f++,s+=.001,background(9),
R(0,h,20),7<h&&(y-=.5,h+=y),(o).map(p=>{x=99*((p-s*f/99)%6+5.9),R(x,0,20),9>h&&9>x&&(s=2,f=0)})
,b>(c=s*99|0)||(b=c),fill(255),text(`#LDJam ${b} ${c}`,0,99)},keyPressed=_=>0<h||(y=8,h=8)
```
You can paste that code into the p5js editor to run the game.
Controls:
- Press any key to jump
- Die to restart
Documented code
Here's the documented code. Had to use a lot of tricks and cut a lot to get the game under 280 characters.
```
// Initialize obstacle array.
o=[0,3,7],
// Initialize height, best score and frame count.
h=b=f=0,
// Initialize speed.
s=2,
// Other variables like the current score and the vertical speed get initialized when they're first set.
// Create the canvas for the game.
setup=_=>createCanvas(400,400),
draw=_=>{
// Alias function name that are used more than once.
R=rect,
// Update frame count
f++,
// Slowly increase speed.
s+=.001,
// Clear the canvas. 9 is a very dark grey instead of 0 (black) to be slightly different to black but effectively it's still black.
background(9),
// Draw the player.
R(0,h,20),
// If the player is in the air...
// 7 is the height of the cube just before we reach the ground,
// Which means the last time we run this, the player will be on the ground.
// This avoids code that checks if the player is touching the ground.
// Uses the short-circuit behavior of the && operator to acts as a branch statement.
7<h&&(
// Apply gravity to vertical speed.
y-=.5,
// Apply vertical speed to height
h+=y
),
// For each obstacle. p is the position of the obstacle.
(o).map(p=>{
// Calculate the x position of the obstacle.
x=99*(
// An initial position that moves with the speed * frame count
(p-s*f/99)
// This uses module to make the obstacles loop around the screen.
// It also abuses the way negative modulos work to make some obstacles appear later.
// Because we add 5.9 at the end, the x position will only be 0 when (p-s*f) is negative.
// So if we pick larger values for p, those obstacles will be delayed,
// so the game gets more difficult over time.
// These numbers are also picked so that obstacles loop just after they reach the end of the screen,
// so the collision check use less characters.
%6+5.9),
// Draw the obstacle
R(x,0,20),
// Check collsion:
// If `h < 9` (the player is roughly on the ground) and
// `x < 9` (the obstacle is near the player)
// The obstacle check can be one-sided because of how the obstacles loop.
9>h&&9>x&&
// Reset the game by resetting the speed and frame count.
(s=2,f=0)}
),
// If the best score is less than the score
b>(
// Turn the speed into a score variable,
// multiplying to be a nicer number and converting to integer.
c=s*99|0
// Update the best score
)||(b=c),
// Text color to white
fill(255),
// Draw both the current score and the best one
text(`#LDJam ${b} ${c}`,0,99)
},
// Keyboard input: When any key is pressed...
keyPressed=_=>
// If the player is on the ground
0<h||(
// Set the verticle speed to the initial jumping speed
y=8,
// We also need to put the player above the 7<h check earlier
// which is used to see if they're jumping or not.
h=8
)
```
Ended up with enough space to fit the hashtag in there :)



Comments9
I like the meta take of the theme, I remember very few entries of this kind over the numerous LDs I entered (notabily one in the url edit - a runner too - and another one in the page icon - wich I forgot the gameplay), but I think this is the first one I just had to copy-paste less than 300 chars in an editor in order to play it :smile:
Good job!
p.s.: you may have forgot to opt-out of Audio cat, unless you took the choice of considering silence as an appropriate sound for this kind of idea :joy:
"SyntaxError: missing ) after argument list"
One thing I could not really figure out is why the game would start with 198 points for the score. I see why the code does it, I just don't get the choise :-)
Edit: btw: your cover image is missing at the moment. Was that on purpose?
The reason the score starts at a random number is because I was reusing an existing variable to make the score, and it would take more characters to make that start at 0 :) I potentially could've got rid of the #LDJam hashtag I suppose :P
I started writing the game in JavaScript, as I would write it with if statements and regular functions and such, and then started making it smaller and cutting features. The game used to be on a circle, and whenever you landed more obstacles appeared, but those all took too many characters to fit. As I worked on it, I had a version that was not quite as split up as the commented version is, but it had newlines and indents to make things more readable.