geom dsh

Overall★★★★★★★★★★2.50
Fun★★★★★★★★★★2.70
Innovation★★★★★★★★★★3.50
Theme★★★★★★★★★★4.67
Graphics★★★★★★★★★★1.80
Audio★★★★★★★★★★1.00
Humor★★★★★★★★★★2.42
Mood★★★★★★★★★★1.70

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

godsboss3 Oct 2023, 11:56
Nice take on the theme. The short version of the code does not work due to double backticks (\`\` instead of \`).
LeReveur
LeReveur4 Oct 2023, 04:04
Thanks to @godsboss I managed to play the game!

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:
alexrose
alexrose5 Oct 2023, 21:40
I'm missing something here. when I paste that code I get this:

"SyntaxError: missing ) after argument list"
alexrose
alexrose5 Oct 2023, 21:57
nevermind saw the bottom link. I got a 382
Local Minimum
Local Minimum6 Oct 2023, 14:23
Great interpretation of the theme! I don't think I've ever encountered a limited source code game in LD before. A lot of game-play in so few lines.
Wouter52
Wouter527 Oct 2023, 12:22
What a fun way to spend your jam! Your ideas are often very much "out of the box" :smile: I like how you have a commented version of your game. Did you make that first, and then condensed it into the tweet-sized code?

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?
Jezzamon
Jezzamonauthor11 Oct 2023, 03:52
@godsboss Ah, in some markdown editors that escapes the backticks. Turns out it doesn't here. Fixed that! Thanks for the heads up
Jezzamon
Jezzamonauthor11 Oct 2023, 03:55
@wouter52 Ah, was somewhat distracted when uploading my game, so I missed the cover image. Added, thanks!

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.

Other games by @jezzamon

Found a bug?
Tell us on Discord