Code created during recording the Linux Terminal Game from Scratch video series.
Linux Terminal Game from Scratch I - Termios, ANSI Escape Codes
Linux Terminal Game from Scratch II - Game Loop, Rendering, Level Loading
Linux Terminal Game from Scratch III - Gameplay
Linux Terminal Game from Scratch IV - Tests, Rendering, Colors, Animations
Just a C compiler :)
gcc -std=gnu17 -Wall -Wextra -O2 ./game.c -o game
./game
- Non-canonical input mode
- Turning off echo
- Proper reset on exit (both for normal exit and abnormal exit)
- Rudimentary game loop
- Grab the arrow keys
- Print them out (e.g. RIGHT)
- Empty level with borders
- Player can walk around within the borders
- Optimize rendering
- Optimize game loop
- Load up level from a file
- Gameplay
- Tests
- Rendering
- Colors
- Animations?
@ - Player Character
X - Wall
$ - Gems / Gold
O - Rock
. - Earth
- Space/Empty
E - Exit
- Player can dig a tunnel through Earth
- Rocks/Gems fall down if there is space below them
- Rocks/Gems falling on Player ends the game -> Lose Scenario
- Player entering Exit ends the game -> Win scenario
- Player can't go through Wall, Rock
- Player can collect Gems
This is stable
.O.
.O.
This is unstable -> Top rock rolls to the left
. O..
. O..
This is unstable -> Top rock rolls to the right
..O .
..O .
However, this is stable
.O ...
XX XXX
Rocks and Gems behave similarly in most of the time. For example, a Gem can kill the player if it falls on its head.
Player can push a rock horizontally if there is empty Space behind the Rock. In the scenario below, the Player can push the rocks right or left.
.. O@O ..
.........
- Low resolution
- ASCII characters (subpixels, textures)
- Colors (foreground, background)
- Move the cursor's position freely
- Canonical Mode - line based
- Non-Canonical Input Mode - More control over input
- RAW Input Mode
- Turn off Echo
- :(
- Terminal Bell - NO
- man 3 termios
- ANSII Escape Codes - https://en.m.wikipedia.org/wiki/ANSI_escape_code
Paremeters: R G B
printf "\x1B[:38;2;R;G;Bm"
Parameters: R G B
printf "\x1B[48;2;R;G;Bm"
Move Cursor To (x, y) - Upper Left Corner is (1, 1) Paremeters: X Y
printf "\x1B[Y;XH"
printf "\x1B[2J"
printf "\x1B[?25l"
printf "\x1B[?25h"
printf "\x1B[m"