Constructor to initialize things. It is important to keep initialization and game logic separate.
Used for direction tracing in the API.
Defines tile type codes.
Since tilemaps get initialized with 0xFFFF (none) tiles, we need to set it to 0x0000
Key event data is received here.
Moves the snake in the given direction.
Makes it possible to close the game the proper way.
Places the next apple to a random empty location. If it can no longer put any new apples anywhere, then the game have been won.
A timer event, to make the game run stable regardless of the framerate.
Main loop cycle, where all the good things happen.
These are the tiles, we're going to use in our game
Contains the current direction.
These are the tiles, we're going to use in our game
Handles all the inputs. On every keypress/buttonpress, a new event is created, which changes the internal state of the program.
The output screen, where the output is being displayed.
The TileLayer, that: * Displays the current game state * Stores playfield data (snaketail, apple's position, etc)
Contains the previous direction.
The raster handles frame buffer and layer priority management. Even though we currently only have a single tilelayer, we will still needing it.
A random number generator
Counts how much score the player has.
These are the tiles, we're going to use in our game
The position of the head of the snake. We can track the rest of the snake by tracking the directions.
These are the tiles, we're going to use in our game
Program and game state. 4: program exit 5: game start 6: game over 7: game won
A simple snake game. Uses code-generated graphics to avoid relying on external assets.
Game rules: * The player controls a snake. * The player must collect apples to get score, which also makes the snake grow. * Every time an apple is collected, a new one is randomly spawned on the map at a point outside of the snake. * If the player either hits the snake or wall, they lose. * If the player somehow makes the snake to grow so big a new apple cannot be spawned, then the player wins.
Design guidelines: * No much external assets. (except for engine essentials). * Snake tail follows past directions
Some possible assignments to practice using the engine: * Use some external assets. * Add some obstacles. * Add a second, third, etc. player.