It's 8pm here. Self challenge which I'll live blog: can I implement a version of tetris in Racket by 10pm? Let's see if I can... I'm gonna live blog it here.
Ok, starting off, a while ago I already wrote out some vectors representing the tetris shapes and a little utility to rotate them. That's all I'm starting with, which isn't too much of a head start.
I'm going to use "lux", which is the "grown up" version of Racket's big bang. There are multiple renderers you can plug in... it comes with a Racket "draw" based basic canvas one, or I can use raart, which would be terminal ansi-art based. Not sure which I'm doing yet.
Repo here https://gitlab.com/dustyweb/racktris
You can see what I started with in this commit... some stuff but not too much: https://gitlab.com/dustyweb/racktris/commit/20652a2f6cab7d0c16bdbde711bcb92d9af2c851
Wrote basic game datastucture.
Already have nice looking rendering of blocks. Check out the visual rendering of the block hashmap at the REPL!
1 hour to go... I've got a lot to get done in this hour. It probably won't be done in my original 2 hour goal.
But what about 3? ;)
LIVE CODING UPDATE
I dropped a grape
So, it's 9:38PM right now. That's a little over two hours until midnight.
How about we make this a game for charity? Feel free to put down pledges to donate to a freedom-loving charity. Put down your donation amount and choose one of the following orgs:
- Software Freedom Conservancy
If I get a graphical game by midnight, donate $MONEY amount to $CHARITY.
I promise $30 to Conservancy if I get this done by midnight. Bonus: if I get a console version too, $60!
need more caffeine
Working on the blitting-to-the-board function, which doubles as collision detection. Probably the hardest part of this (and not too hard)
come on chris... don't lag now... only an hour left!
oh no oh no oh no only 35mins left
2 minutes left and the game mostly works
Okay, it's midnight! Here's what works:
- the game renders and looks nice
- pieces advance and can rotate and can be placed
Here's what I don't have yet:
- You can't clear rows yet... oops!
- Rotation code is apparently broken... you can't rotate all the way around, only 90 degrees and back. I don't know why this is!
I'm going to see if I can get those last two bits in. I consider that good enough for me to donate the smaller amount, but you judge for yourself!
gosh I'm tired and I can't figure out why my roation code doesn't work.
I guess I'll add all the rest of the code.
Considering things "mostly" worked at midnight, and it's all working before I'm going to sleep, I'm calling it a success. Donating $30 to Conservancy now!
Oh yeah, you'll need the Lux game engine:
$ raco pkg install lux
Oh yeah, want to see what the finished game looks like? Here's a screenshot:
Those tiles used in the game are procedurally generated btw! They use the Racket "icon" library. Same rendering as the buttons in DrRacket ;)
@dthompson So Lux is really cool! It's basically "big-bang for grownups" (where big-bang is Racket's builtin game engine for middle schoolers).
The answer to "does it use opengl" is "yes, optionally" but not in the way most game engines say that. The core of the functional game engine actually doesn't specify the input/output system, which is provided by a "chaos". One chaos comes bundled which uses Racket's canvas drawing and GUI input events, but you can plug in others
@dthompson Two other really interesting chaos renderers available are:
- raart: for making ansi art / console / curses games https://github.com/jeapostrophe/raart/tree/master#readme Underdocumented, but comes with a demo https://github.com/jeapostrophe/raart/blob/master/t/hack.rkt
- mode-lambda: "the best 2D graphics of the 90s, today!" (that's literally its slogan) which is optimized for SNES style games, and even includes mode 7 graphics https://docs.racket-lang.org/mode-lambda/
@dthompson So here's what's cool about this: since the input / rendering engine is decoupled from the game loop engine, it's very easy to write one game and have totally different renderers... or at least I think so! Tonight I'm going to add an optional console version of Racktris using Raart and I think it's going to be pretty easy.
Octodon is a nice general purpose instance.