Shadow Tetris

Game details

Shadow Tetris is playable but it is unfinished: the tiles are missing colors, the menu offers no configuration, the music is silly and repeating, and most importantly, the game is not a fun challenge, because the mechanics are broken and you won't last more than a few seconds before losing in the game.

Feel free (as you should be!) to fork this game to modify it and learn from the source code. You could for example:

  • Pick a better music track. The current song is silly. However silly it may be, it is made by a composer named Kevin MacLeod who makes his music available online for free (Licensed under Creative Commons: By Attribution 3.0, see his FAQ, which includes links to more resources for free music). His songs are very famous and you may be aware of some of them! For example Sneaky Snitch, Fluffing a Duck, Scheming Weasel, and many others.
  • Color the tiles or add textures.
  • Make the keys configurable and/or include support for mouse or touch input.
  • Actually finish the game by making it fun to play.

The source code

On the source side, you will find basically a single piece of source code, the main.fnl file which contains about 500 lines of documented Fennel code. The git repository has a small log history, where most of the features are apparent, for instance (this is to be read bottom-up)

1eb9c27 add music
c1b0bc3 add interaction between player and pile and score
6ec5178 added growing pile
d9811f7 add menu
caebf0e add rotations for the tetris blocks
ece8c55 wall collision
73271a1 tetris shape falls down

The code is a bit scattered. You may want to organize it by splitting it in multiple files, but the basic gist of it is this:

  • I have several timers to control when updating occurs. A player timer (see create-timer) tells me when the input for the player should be considered; I have a last-key variable which stores the last saved input that is now going to be acted upon. Another timer tells me when to push the pile up. I have a timer to restart the music when it's done.
  • The GFX on the menu screen is a bunch of random points (see create-particle) moving around with motion described by simple harmonic motion with perpendicular drift velocity. This basically means the particle moves left and right in the screen and travels upward. I randomized the parameters so that each particle behaves a bit differently.
  • Tetris tile rotation is from hardcoded data. I did not bother actually writing any rotating code, I just hardcoded some positions in an array, see tetris-shapes. I made that array cyclic with create-cyclic so that I don't even have to keep track of an index on it.
  • A global variable called game-state tells me what game the state is on, so that I know whether I'm on the menu screen or the tetris game screen. I call the appropriate draw functions according to that variable.
  • I have wall collision and wall clipping detection functions. One issue that arose was that a tile would end up lying outside the visible screen when rotated at the edge of the screen. I detect this situation with left-wall-clip? and right-wall-clip? and move the tile respectively right or left until it is back into the board. This is all invisible to the player, because it happens before it is actually drawn.
  • For the keys pressed, I wrote a kbd function (inspired by the Emacs text editor), which checks if a key matches a given list of keys. Then I used the keybindings variable to hold associations between key matches and actions to be taken when those keys are pressed. This concept can be extended somewhat (just like Emacs does, say with named events) and can lead to easily configurable key configurations.

Overall, I was surprised by how hard it is to write a video game! It's one of my first and it was not an easy task.

Playing the game

To launch this game on your local copy, you need to install lua and love2d. Fennel is just one file (called fennel.lua) embedded in the project so you don't need to install it. You can then launch the game by navigating into the project directory and typing on a shell (e.g. on Linux)

love .

Keys

  • q or ESC puts you to menu or leaves game, also exits credits.
  • SPACE rotates the tile.
  • ENTER to make a menu choice.
  • left/right/down arrows or a/s/d to move the tile.

Licensing and credits

The font used is Numbeato Font by denny-0980, it is in the public domain.

Music track called Farting Around by Kevin MacLeod, licensed under CC BY-3.0.

The github project is here, licensed under the MIT license. I also used lume.lua which is licensed under the MIT license as well.


Converted into a web browser game with love.js.

StatusCanceled
PlatformsHTML5
Authornchatz314
GenrePuzzle
Made withLÖVE
Tagsfennel, LÖVE, Tetris
Code licenseMIT License
Average sessionA few seconds
LanguagesEnglish
InputsKeyboard
LinksSource code

Leave a comment

Log in with itch.io to leave a comment.