embedded-software
reusable software modules for embedded systems
|
Game Management / Helper Module. More...
Data Structures | |
struct | char_object_t |
Char Object. More... | |
struct | linked_char_object_t |
Linkable Char Object. More... | |
struct | player_info_t |
Player info structure to hold player settings. More... | |
Macros | |
#define | TRANSPARENT_CHAR '`' |
transparent character for drawing tiles More... | |
Functions | |
uint8_t | Game_Register (char *name, char *description, void(*play)(void), void(*help)(void)) |
Game_Register registers a game by adding it to the games[] array. More... | |
void | Game_RegisterCallback (uint8_t game_id, void(*callback)(int argc, char *argv[])) |
void | Game_RegisterHighscoreCallback (uint8_t game_id, void(*callback)(void)) |
void | Game_Log (uint8_t game_id, char *str,...) |
void | Game_EnableMultiPlayer (uint8_t game_id, uint8_t num) |
void | Game_RegisterPlayer1Receiver (void(*rx)(uint8_t)) |
void | Game_RegisterPlayer2Receiver (void(*rx)(uint8_t)) |
Register Player 2 UART Channel. More... | |
void | Game_UnregisterPlayer1Receiver (void(*rx)(uint8_t)) |
Unregister Player 1 UART Channel receiver. More... | |
void | Game_UnregisterPlayer2Receiver (void(*rx)(uint8_t)) |
Unregister Player 2 UART Channel receiver. More... | |
void | Game_CharXY (char c, char x, char y) |
Write a character to a coordinate of the terminal. More... | |
void | Game_Player1CharXY (char c, char x, char y) |
Write a character to a coordinate of the first players terminal. More... | |
void | Game_Player2CharXY (char c, char x, char y) |
Write a character to a coordinate of the second players terminal. More... | |
void | Game_CursorXY (char x, char y) |
Cursor Position XY. More... | |
void | Game_Player1CursorXY (char x, char y) |
Player 1 Cursor Position XY. More... | |
void | Game_Player2CursorXY (char x, char y) |
Player 2 Cursor Position XY. More... | |
void | Game_Printf (char *str,...) |
void | Game_PrintfXY (char x, char y, char *str,...) |
PrintfXY to screen. More... | |
void | Game_Player1Printf (char *str,...) |
void | Game_Player2Printf (char *str,...) |
void | Game_HideCursor (void) |
Hide the cursor for player 1 (and player2 if a two player game) More... | |
void | Game_ShowCursor (void) |
Show the cursor for player 1 (and player2 if a two player game) More... | |
void | Game_SetColor (enum term_color color) |
void | Game_DrawTile (char *tile[], char x, char y) |
void | Game_DrawRect (char x_min, char y_min, char x_max, char y_max) |
void | Game_FillRect (char c, char x_min, char y_min, char x_max, char y_max) |
void | Game_LinkedChar (char c, char x_first, char y_first, int length, int direction, linked_char_object_t list[]) |
void | Game_ScrollDown (void) |
void | Game_ScrollUp (void) |
void | Game_ClearScreen (void) |
uint8_t | Game_IsTransmitting (void) |
void | Game_Bell (void) |
void | Game_GameOver (void) |
let the game management module know that your game is over. More... | |
Game Management / Helper Module.
This module helps manage multiple game modules running on a single system as well as implementing several helper functions and structures.
Command list:
Notes for developing a game using this game management module:
MM add "$game player1 ..." and "$game player2 ..." command support
MM implement transparent character support
#define TRANSPARENT_CHAR '`' |
transparent character for drawing tiles
void Game_Bell | ( | void | ) |
This is used to print out an "\a" within the game. The "\a" is used to represent a bell that sounds an alarm
void Game_CharXY | ( | char | c, |
char | x, | ||
char | y | ||
) |
Write a character to a coordinate of the terminal.
Game_CharXY writes a character to the terminal. If there are multiple players it will write to all available terminals
c | is the character you wish to print to the terminal |
x | defines where to print the character on the x axis |
y | defines where to print the character on the y axis |
void Game_ClearScreen | ( | void | ) |
void Game_CursorXY | ( | char | x, |
char | y | ||
) |
Cursor Position XY.
Game_CursorXY Moves the cursor to a specified location using the Terminal_CursorXY function based off the number of players.
x | is the horizontal coordinate. |
y | is the vertical coordinate. |
DS 3/25/19
void Game_DrawRect | ( | char | x_min, |
char | y_min, | ||
char | x_max, | ||
char | y_max | ||
) |
Draws the border of a rectangle using the following character codes: 186, 187, 188, 200, 201, 205
x_min | The smallest horizontal location to begin drawing. |
y_min | The smallest vertical direction to begin drawing. |
x_max | The largest horizontal location to begin drawing. |
y_max | The largest vertical direction to begin drawing. |
void Game_DrawTile | ( | char * | tile[], |
char | x, | ||
char | y | ||
) |
Convenience function for writing a tile (2D array of characters) to the screen at a specified X, Y coordinate. This function maps characters in the beginning of the array to the top of the screen and the end to a lower portion of the screen. A null terminated array signals the end of the array.
tile | An array of character pointers with null termination |
x | The horizontal location to begin drawing the tile |
y | The vertical location to begin drawing the tile |
void Game_EnableMultiPlayer | ( | uint8_t | game_id, |
uint8_t | num | ||
) |
game_id | |
num |
void Game_FillRect | ( | char | c, |
char | x_min, | ||
char | y_min, | ||
char | x_max, | ||
char | y_max | ||
) |
This function can be used to fill up a rectangular area with a passed character
c | - Some character |
x_min | - minimum value of x |
y_min | - minimum value of y |
x_max | - maximum value of x |
y_max | - maximum value of y Example code: #include <stdio.h>
#include <stdlib.h>
.
.
.
int main()
{
.
.
.
Game_FillRect('C', 1, 1, 10, 10)
.
.
.
return 0;
}
|
void Game_GameOver | ( | void | ) |
let the game management module know that your game is over.
This function must be called after your game is over so the game management module can allow users to play again.
void Game_HideCursor | ( | void | ) |
Hide the cursor for player 1 (and player2 if a two player game)
Hide the cursor and, if echo is on, turn echo off.
uint8_t Game_IsTransmitting | ( | void | ) |
Game_IsTransmitting is used to determine whether the game is currently transmitting data to UART This allows the user to check that the game screen is fully updated before allowing the game to advances forward
void Game_LinkedChar | ( | char | c, |
char | x_first, | ||
char | y_first, | ||
int | length, | ||
int | direction, | ||
linked_char_object_t | list[] | ||
) |
This function creates (initializes) and displays a list of char objects from an uninitialized linked_char_object_t array. Can be used to make walls, multi-char enemies, sub-boundaries, etc.
c | - character that will make up nodes of list |
x_first | - x position of starting node |
y_first | - y position of starting node |
length | - length of char list |
direction | - determines direction the list will be made from starting node 0 -> up, 1 -> right, 2 -> down, 3 -> left |
list[] | - uninitialized linked_char_object_t array |
Example code:
void Game_Log | ( | uint8_t | game_id, |
char * | str, | ||
... | |||
) |
game_id | ID of game (returned when Game_Register() is called) |
str | pointer to null terminated string |
... | variable argument list to be used with any replacement flags in the string |
Similar to LogMsg() except with the addition of the game name to the message.
void Game_Player1CharXY | ( | char | c, |
char | x, | ||
char | y | ||
) |
Write a character to a coordinate of the first players terminal.
Game_Player1CharXY writes a character to the first player terminal
c | is the character you wish to print to the terminal |
x | defines where to print the character on the x axis |
y | defines where to print the character on the y axis |
void Game_Player1CursorXY | ( | char | x, |
char | y | ||
) |
Player 1 Cursor Position XY.
Game_Player1CursorXY Moves the cursor to a specified location using the Terminal_CursorXY function based off the Player1UART.
x | is the horizontal coordinate. |
y | is the vertical coordinate. |
DS 3/25/19
void Game_Player1Printf | ( | char * | str, |
... | |||
) |
str | pointer to string to be printed (must be null terminated) |
... | variable argument list to be used with any replacement flags in the string |
Function: Game_Printf(*str)
This function is passed a pointer to a string and prints that string to player 1's terminal using UART_vprintf. The function supports printf style replacement flags.
void Game_Player2CharXY | ( | char | c, |
char | x, | ||
char | y | ||
) |
Write a character to a coordinate of the second players terminal.
Game_Player2CharXY writes a character to the second player terminal
c | is the character you wish to print to the terminal |
x | defines where to print the character on the x axis |
y | defines where to print the character on the y axis |
void Game_Player2CursorXY | ( | char | x, |
char | y | ||
) |
Player 2 Cursor Position XY.
Game_Player2CursorXY Moves the cursor to a specified location using the Terminal_CursorXY function based off the Player1UART.
x | is the horizontal coordinate. |
y | is the vertical coordinate. |
DS 3/25/19
void Game_Player2Printf | ( | char * | str, |
... | |||
) |
Sending a Player 2 specific message
str | is a string which is to be printed to player 2's screen. |
... | variable argument list to be used with any replacement flags in the string |
This function is passed a pointer to a string and prints that string to player 2's terminal using UART_vprintf. The function supports printf style replacement flags.
void Game_Printf | ( | char * | str, |
... | |||
) |
str | pointer to string to be printed (must be null terminated) |
... | variable argument list to be used with any replacement flags in the string |
Function: Game_Printf(*str)
This function is passed a pointer to a string and prints that string to the terminal using UART_vprintf. The function supports printf style replacement flags. Can output messages from multiple UART channels if more than one person is playing.
void Game_PrintfXY | ( | char | x, |
char | y, | ||
char * | str, | ||
... | |||
) |
PrintfXY to screen.
Game_PrintfXY prints a specified string to a certain location using terminal_cursorXY and Subsystem_printf.
x | is the horizontal coordinate. |
y | is the vertical coordinate. |
* | str points to location of the beginning of the specified string |
... | variable argument list to be used with any replacement flags in the string |
DS 3/25/19
uint8_t Game_Register | ( | char * | name, |
char * | description, | ||
void(*)(void) | play, | ||
void(*)(void) | help | ||
) |
Game_Register registers a game by adding it to the games[] array.
Game_Register will take input pointers and copy it onto the corresponding variable pointers in game_t struct. Will also initialize num_players, score, and callback.
name | - Pointer to start of character array containing name of game |
description | - Pointer to start of character array containing description of game |
play | - Pointer to function that initiates playing the game |
help | - Pointer to function that displays help info |
void Game_RegisterCallback | ( | uint8_t | game_id, |
void(*)(int argc, char *argv[]) | callback | ||
) |
This function takes in an id for the game along with the callback, and saves it in the array of games. The index of the array the callback is stored in is the game_id, so this number must be less than the size of the games array.
game_id | ID of the game. Also used as the array index. |
callback | The callback pointer |
void Game_RegisterHighscoreCallback | ( | uint8_t | game_id, |
void(*)(void) | callback | ||
) |
game_id | |
callback |
void Game_RegisterPlayer1Receiver | ( | void(*)(uint8_t) | rx | ) |
Game_RegisterPlayer1Receiver will register the UART char receiver function for player 1
Game_RegisterPlayer1Receiver registers the UART char receiver function for player 1. PLAYER1_UART defines the channel of the UART to be registered.
rx | Pointer to UART char receiver function |
void Game_RegisterPlayer2Receiver | ( | void(*)(uint8_t) | rx | ) |
Register Player 2 UART Channel.
Game_RegisterPlayer2Receiver() registers a second UART channel to be used by a second player. Only use if you game allows a for a second player
rx | is a function pointer that calls a function when a character is received in the UART channel |
void Game_ScrollDown | ( | void | ) |
void Game_ScrollUp | ( | void | ) |
void Game_SetColor | ( | enum term_color | color | ) |
This function sets the color for the game and can be either the foreground or the background depending on the user input. If there is a second channel, it will also set the corresponding color specifications to the second UART channel.
color | is one of the elements within the enumeration defined in terminal.h. |
void Game_ShowCursor | ( | void | ) |
Show the cursor for player 1 (and player2 if a two player game)
Show the cursor and, if echo was on, turn echo back on.
void Game_UnregisterPlayer1Receiver | ( | void(*)(uint8_t) | rx | ) |
Unregister Player 1 UART Channel receiver.
Game_UnregisterPlay1Receiver() unregisters the UART channel associated with player 1.
rx | is a function pointer that calls a function when a character is received in the UART channel |
void Game_UnregisterPlayer2Receiver | ( | void(*)(uint8_t) | rx | ) |
Unregister Player 2 UART Channel receiver.
Game_UnregisterPlayer2Receiver() unregisters the UART channel that has been assigned to Player 2.
rx | is a function pointer that calls the desired function when the UART channel receives a character. |