
- #Classic snake game background code
- #Classic snake game background series
- #Classic snake game background windows
Even though the game board has fewer columns, we can setup our matrix for 256 columns. Does this matter? Not really, both programs spent 99.99% of their time in the necessary delay loop.īecause there is no shortage of memory, we can waste some and benefit from it. To put 'faster' in some perspective: the 'MATRIX' program runs a typical cycle in 1.1 µsec, and the 'VRAM' program runs a cycle in 2.6 µsec. Faster because reading from VRAM is slow compared to reading from regular RAM, and more flexible because the screen can keep displaying all of the characters and all of the color combinations. This solution is similar to reading the video buffer matrix but is both faster and more flexible. Reading game information from a matrix of our own. Jne al, 00010001b Slow uses one out of four mov, al speed: mov al, 11111111b Fast uses every tick Show "GO" and wait for a keypress, then begin Paint the playfield, draw the snake and food The Snake Game - VRAM (c) 2021 Sep Roland Hiding the cursor is also solely for the benefit of running the demo's in Microsoft Windows. That does not help in getting nice square tiles.
#Classic snake game background windows
The simpler method to produce square tiles would have been to use the 40x25 text video mode, but as it turns out, for Microsoft Windows the 40x25 mode is the same as using the left half of the 80x25 mode. In the demonstration programs that follow, every tile on the game board is made up of 2 character cells in the video buffer of the 80x25 text video mode. Similarly if we select ASCII 219 (full block), the video hardware only needs the foreground color and we can use the 4-bit space reserved for the background color to record our game information. If we then select ASCII 32 (space), the video hardware only needs the background color and we can use the 4-bit space reserved for the foreground color to record our game information. Instead of using the character byte to store the game information, we could also use the attribute byte. For example, if the current tail is at (5,8) and the character byte in the video memory holds the value 48h ( up), then the new tail will be positioned at (5,7). The scancodes of the arrow keys are used for this purpose. We can set things up so that the character byte of the tile where the current tail is located, records the direction to move to in order to position the new tail. The resulting output will always form a single color, solid rectangle.
#Classic snake game background code
If the foreground and background colors happen to be equal, it won't matter anymore what character code we have stored there. Reading game information from the video buffer matrix.įirst let us assume using a text video mode where each character cell is represented by a character byte (ASCII), and an attribute byte (color) that enables us to choose between 16 foreground colors and 16 background colors.



We can store this information in the video buffer matrix, in a matrix of our own, or in a circular buffer. We can choose to store the actual (X,Y) coordinates or an indication of the change between successive coordinates. To keep track of the snake we have to record the position of all of its segments. Updating the 'head' variable is easy, but how can we unambiguously know where the new 'tail' will be? So, how can we keep track of the snake? Will it be necessary to invent some data structure? In the program we can store the coordinates for both 'head' and 'tail' in variables. To make the snake move, a new segment is added at the 'head' side and an existing segment is removed at the 'tail' side. If the snake crashes into the border or bumps into itself, the game is over! If the food is eaten, the snake will grow an additional one segment and a following food is placed on the board. The player can control the snake through the arrow keys on the keyboard, aiming for the food. There's no need for any graphical markings.
#Classic snake game background series
In its most basic form, the game only uses 3 colors: one for the snake (a series of interconnected tiles), one for the food (a randomly chosen tile), and one for the background (the unoccupied tiles).īecause the snake is continuously on the move, it will be obvious enough where the head of the snake is at any one time. The objective of this board game is to eat the food and grow.
