Certainly not the first block-stacking game, but this might be the first one on PICO-8 with global high scores*!
Play the game here*:
https://jaredkrinke.itch.io/fbgp8
How to play
The goal of the game is to score points by clearing lines. You clear lines by rotating and dropping pieces into complete lines (no gaps). The more lines you clear at once, the more points you score.
Pro tip: pieces fall faster on higher levels, but you get more points, so if you can handle it, try starting on level 9.
Game modes
- Endless (exactly what it sounds like)
- Countdown (game ends after 25 lines)
- Cleanup (same as countdown, but the play area starts filled with garbage)
High scores
High scores are tracked both locally and globally*.
See if you can make it into the top 10! (Update 12/13: getting on the list is no longer easy :)
Code
- Code is on GitHub: https://github.com/jaredkrinke/pico-8-fbg
- I'm using GPIO, JavaScript, and a back-end service to track scores. Happy to discuss my PICO-8-to-HTML host communication approach :)
Notes
* Global high scores only work on the web/browser version
Cartridge version (note: no global high scores)
Nice work! I'm looking to implement a global score in my game but I'm pretty clueless when it comes to web server communication as well as a beginner in game dev so not sure I will be able to pull it off...
If I want to do exactly what you have done, are you able to give any pointers or elaborate on the server setup?
I have my own domain I could use to host something, or are there other better options? Also I've seen posts touching on global score support in pico8, but not sure if that is supported at the moment or will be compatible with games you play in browser on itch.io for example.
Sure, I'm happy to explain what I did (although it's a bit convoluted in my case, so I'm not sure how helpful this will be).
Caveats
First of all, just to emphasize, my scheme only works in the browser (e.g. on itch.io) and not when running PICO-8 natively because (unless something has changed) PICO-8 cartridges can't access the network at all.
A second thing to emphasize: if you're just submitting high scores to a web service, there's nothing automatic to prevent someone from forging their high scores. This probably isn't a big deal, but the only solution I came up with to avoid this is to literally record every single game, upload the replay (in compressed form), and validate the replay on the server. Someone could still craft a replay by hand to cheat. So basically, you're probably not going to be able to prevent someone who's really determined from cheating (unless you run the game server-side or upload checkpoints in real time, which seems like an insane amount of work for anything that's not an e-sport :).
Local high scores
I store local high scores in PICO-8 cartdata (and this works outside the browser -- but not really what you're looking for). For my game, I needed to support scores above 32767 (the largest integer in PICO-8), so I had to write a bit of code to interpret a PICO-8 number as an unsigned 32-bit integer: https://github.com/jaredkrinke/pico-8-util/blob/master/uint32.p8
PICO-8-to-browser communication
The way I get around this limitation in the browser is by using PICO-8 GPIO. You can hook reads and writes to the GPIO pins in JavaScript in the host page and, best of all, everything is done synchronously, so you have nearly unlimited bandwidth between your cartridge and the host web page. Unnecessarily complex sample code is here: https://github.com/jaredkrinke/pico-8-comm
Browser to server communication
There's nothing special about communicating between browser and server, other than making sure you use Cross-Origin Resource Sharing to deal with the Same Origin Policy. I made the unfortunate decision to use jQuery (you should probably use the "fetch" API that browsers now support); my code to send scores
(and replays, as mentioned above) to the server is roughly here: https://github.com/jaredkrinke/pico-8-fbg/blob/6ab7f2ae6b91e32e30430949c850f8ebdd68d000/logic.js#L164
Server
For the server side, you don't need your own domain and can get by with only free services. I used Netlify Functions (a "serverless" setup) for running the code and Google Firestore for the database. The (TypeScript) code is here: https://github.com/jaredkrinke/fbg3/tree/master/db
Notes:
- "Add score" handler: https://github.com/jaredkrinke/fbg3/blob/master/db/src/addscore.ts
- "Get top scores" handler: https://github.com/jaredkrinke/fbg3/blob/master/db/src/topscores.ts
- You have to upload your Firestore credential with your Netlify Function, but you DO NOT want to check that credential into your source code!
Final note
That's all the time I have at the moment. Hopefully one or two things in there help!
Thanks for the explanation! It will probably take me some time to figure out each step but super helpful to have somewhere to start!
About preventing cheating the score, can encrypting the score data somehow work? I guess if the code is open, maybe it's easy to replicate the encryption but if the code is not open like in the bins or the html exports, would that be a viable option?
Encrypting/obfuscating the score would make it more difficult to cheat, but anything that runs on the client can be inspected/tampered with.
I forget if I mentioned it, but I did validate all the scores (and replays) submitted for my game and they didn't reveal any obvious cheating. I figure the type of person who plays PICO-8 games for fun probably realizes that cheating for the purposes of getting on the high scores list isn't fun or clever--it's just obnoxious :)
[Please log in to post a comment]