Log In  


Cart #rbits_2048-1 | 2024-07-17 | Code ▽ | Embed ▽ | No License
10

I created this to teach myself PICO-8. It has animations, and should be 100% accurate to the original game, including scoring (please let me know if this is not the case). All the 2048 versions I've found on the PICO-8 BBS don't have animations, or have different rules.

Since PICO-8 only supports 16-bit signed integers, it would only allow scores up to 32767, which is a problem with 2048 where scores can go much higher than that. I had to create a long integer "class" to fix that, which took a while. However, it still only supports scores up to just over 3 million. I decided that's probably enough.

Git Repo
Original game by Gabriele Cirulli

Update v1.0.2 (15/7/24):

  • Add button buffering
  • Add sound effects (optional)
10


Nice remake.
Controls wise, inputs are not buffered, so if I quickly press up then right, the right input is often not applied, especially on slower speed setting.
Another minor design mistake : when offering to reset the high score, the highlighted spot should be Cancel, not confirm, especially with X button auto-repeat, unless activating the confirm button requires a long press of both X and O at the same time, for example.

Had fun looking at your LongInt class, I'm not used to see OOP operator re-definition in pico-8 game.

Felt a bit overkill, as pico-8 numbers have 32 bits and you can do simple arithmetic to use the fractional part.

score+=100>>16 to add 100 to the score.
You can also multiply by an integer :

base=100>>16
multiplier_bonus=5 --not shifted
score+=base*multiplier_bonus

What you can't do is directly multiply two pre-shifted numbers

The only problem left is displaying the score.
@Felice made a great little converter function:

function getscoretext(val)
   local s = ""
   local v = abs(val)
   while (v!=0) do
     s = (v % 0x0.000a << 16)..s
     v /= 10
   end
   if (val<0)  s = "-"..s
   return s 
 end 

If for some reason you need arbitrarily big integers, your OOP approach is nicer, but your internal data representation of the integer should be extendable, like an array or a string.


@RealShadowCaster Thanks for the feedback! Yeah making an entire class is probably overkill, but I had already written everything with normal numbers and I didn't want to have to go through and change everything. Plus it makes it more readable and I can reuse it in another game if I want to.

I didn't consider using the fractional part, that would've been much easier. I initially tried to do 2 16-bit numbers, but printing it would've been too hard. But using the fractional part, PICO-8 would mostly handle that for me. I might do that in a future game if I need it to be smaller.

Also yeah I plan to add buffered inputs (or cancel the animation when pressing the key) in a future version. And maybe add sounds.



[Please log in to post a comment]