Game Management / Helper Module.
More...
|
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 (charReceiver_t rx) |
|
void | Game_RegisterPlayer2Receiver (charReceiver_t rx) |
| Register Player 2 UART Channel. More...
|
|
void | Game_UnregisterPlayer1Receiver (charReceiver_t rx) |
| Unregister Player 1 UART Channel receiver. More...
|
|
void | Game_UnregisterPlayer2Receiver (charReceiver_t rx) |
| 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) |
|
void | Game_Player2CharXY (char c, char x, char y) |
|
void | Game_Printf (char *str,...) |
|
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_ScrollDown (void) |
|
void | Game_ScrollUp (void) |
|
void | Game_ClearScreen (void) |
|
uint8_t | Game_IsTransmitting (void) |
|
void | Game_Bell (void) |
|
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:
- $game help (print help info)
- $game player1 {name} [color] [skill] (set player1's name [optional color and skill])
- $game player2 {name} [color] [skill] (set player2's name [optional color and skill]) name can be up to 15 characters, color can be red, green, yellow, blue, magenta, cyan white, skill can be 0 to 9.
- $game {game_name} play (play game_name)
- $game {game_name} help (show help for game_name)
- $game {game_name} score (show highscores for game_name)
- $game {game_name} var1 var2... (call callback for game_name with argc, argv) this can be used to implement changing settings or other more advanced features that are not supported by default.
Notes for developing a game using this game management module:
- Create a function to initiate playing the game (i.e. Play()). The Play function will typically initialize the states, score, screen, etc. then register a receiver using Game_RegisterPlayer1Receiver() or Game_RegisterPlayer2Receiver() and it can shedule tasks to run the game etc. When the game is over you should be sure to ungregister the receiver and remove any tasks you still have scheduled.
- Create a function to print instructions and other information about your game (i.e. Help())
- If you use generic names like Play() or Help() or anything else that someone else might use then declare the function to be static so it is limited in scope to your game file "static void Play(void);"
- Create a [game_name]_Init() function which in most cases will be your only public function and should be called from main,
- [game_name]_Init() should at a minimum call Game_Register() and can optionally call Game_RegisterCallback() and/or Game_RegisterHighscoreCallback().
- Author
- Michael Muhlbaier
- Todo:
MM add "$game player1 ..." and "$game player2 ..." command support
MM implement transparent character support
- Warning
- KC 8/10
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
- Parameters
-
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 |
- Warning
- MM 9/10
void Game_ClearScreen |
( |
void |
| ) |
|
- Todo:
- Atharva A. Document this function (when done change this line to "@todo MM check <your names> documentation"
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
- Parameters
-
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. |
- Warning
- Remember that the coordinate system starts in the upper left corner and is positive down the screen for the y axis.
-
GL 10/10
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.
- Parameters
-
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 |
- Warning
- GL 10/10
void Game_EnableMultiPlayer |
( |
uint8_t |
game_id, |
|
|
uint8_t |
num |
|
) |
| |
- Parameters
-
- Todo:
- Jon W. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_FillRect |
( |
char |
c, |
|
|
char |
x_min, |
|
|
char |
y_min, |
|
|
char |
x_max, |
|
|
char |
y_max |
|
) |
| |
- Warning
- AA 10/10
This function can be used to fill up a rectangular area with a passed character
- Parameters
-
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:
11 Game_FillRect('C', 1, 1, 10, 10)
|
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
- Returns
- 1 if the UART for the specified player is being updated, 0 if no values are being written to UART
- Warning
- DB 9/10
void Game_Log |
( |
uint8_t |
game_id, |
|
|
char * |
str, |
|
|
|
... |
|
) |
| |
- Parameters
-
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.
- Warning
- CR 7/10
void Game_Player1CharXY |
( |
char |
c, |
|
|
char |
x, |
|
|
char |
y |
|
) |
| |
- Parameters
-
- Todo:
- Anthony M. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_Player1Printf |
( |
char * |
str, |
|
|
|
... |
|
) |
| |
- Parameters
-
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.
- Warning
- TM 9/10
void Game_Player2CharXY |
( |
char |
c, |
|
|
char |
x, |
|
|
char |
y |
|
) |
| |
- Parameters
-
- Todo:
- Anthony M. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_Player2Printf |
( |
char * |
str, |
|
|
|
... |
|
) |
| |
Sending a Player 2 specific message
- Parameters
-
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 |
1 Game_Player2Printf("Your score is: %d", score);
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.
- Warning
- RT 8/10
void Game_Printf |
( |
char * |
str, |
|
|
|
... |
|
) |
| |
- Parameters
-
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.
- Warning
- TM 9/10
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.
- Parameters
-
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 |
- Returns
- returns 0xFF if games[] array is at MAX_GAMES length Otherwise returns index of registered game in games[] array
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.
- Parameters
-
game_id | ID of the game. Also used as the array index. |
callback | The callback pointer |
- Warning
- JR 10/10
void Game_RegisterHighscoreCallback |
( |
uint8_t |
game_id, |
|
|
void(*)(void) |
callback |
|
) |
| |
- Parameters
-
- Todo:
- Andrew R. Document this function (when done change this line to "@todo MM check <your names> documentation"
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.
- Parameters
-
rx | Pointer to UART char receiver function |
- Warning
- Make sure to Game_UnregisterPlayer1Receiver() when game play is over
-
JWi 10/10
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
- Parameters
-
rx | is a function pointer that calls a function when a character is received in the UART channel |
- Warning
- Make sure to Game_UnregisterPlayer2Receiver() when game play is over
-
TG 10/10
void Game_ScrollDown |
( |
void |
| ) |
|
- Todo:
- Gerald V. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_ScrollUp |
( |
void |
| ) |
|
- Todo:
- Gerald V. Document this function (when done change this line to "@todo MM check <your names> documentation"
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.
- Parameters
-
color | is one of the elements within the enumeration defined in terminal.h. |
- Warning
- RT 10/10
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.
Unregister Player 1 UART Channel receiver.
Game_UnregisterPlay1Receiver() unregisters the UART channel associated with player 1.
- Parameters
-
rx | is a function pointer that calls a function when a character is received in the UART channel |
- Warning
- TG 10/10
Unregister Player 2 UART Channel receiver.
Game_UnregisterPlayer2Receiver() unregisters the UART channel that has been assigned to Player 2.
- Parameters
-
rx | is a function pointer that calls the desired function when the UART channel receives a character. |
- Warning
- MM 9/10