meurig phillips snake game - accidentally published to my account instead of to the group!
Dependencies: Joystick N5110 SDFileSystem beep fsmMenu mbed
Fork of SnakeProjectRev1 by
main.h
- Committer:
- meurigp
- Date:
- 2016-05-04
- Revision:
- 15:a5590211888c
- Parent:
- 14:56e355c5cfc9
- Child:
- 16:68b9460d4c76
File content as of revision 15:a5590211888c:
/** @file main.h @brief Header file containing functions prototypes, defines and global variables for the snake game @brief Revision 1.0. @author Meurig Phillips @date April 2016 */ #ifndef MAIN_H #define MAIN_H #include "mbed.h" #include "beep.h" /** @namespace greenLed @brief GPIO output for green LED @namespace redLed @brief GPIO output for red LED @namespace pot @brief GPIO input for the POT @namespace buzzer @brief GPIO output for buzzer */ DigitalOut greenLed(PTC2); DigitalOut redLed(PTA2); AnalogIn pot(PTB10); Beep buzzer(PTA1); /// create enumerated type (0,1,2,3 etc. for current direction snake is travelling (not joystick reading)) enum CurrentDirection { up, down, left, right, centre, }; CurrentDirection currentDirection = centre; /// intialise direction at beginning /// create enumerated type (0,1,2 etc. for different game modes on the menu) enum GameType { classic, infiniteMap, hardMap, }; int randomX = rand() % 83 + 1; /*!< random number in the range of 1 to 83 assigned to randomX */ int randomY = rand() % 47 + 1; /*!< random number in the range of 1 to 47 assigned to randomY */ int randomXoddEven = randomX%2; /*!< distinguish whether randomX is odd or even */ int randomYoddEven = randomY%2; /*!< distinguish whether randomY is odd or even */ int snakeTailX[100]; /*!< array for X coordinate of each snake segment */ int snakeTailY[100]; /*!< array for Y coordinate of each snake segment */ int snakeTailLength = 3; /*!< length of snake, intialised to 3 */ int score = 0; /*!< score for current round */ int top_score = 0; /*!< top score read and write from the SD card */ int fruitValue = 10; /*!< value of the fruit */ int i = 40; /*!< x origin of snake head, intialised at 41 */ int j = 22; /*!< y origin of snake head, intialised at 23 */ int prev_i; /*!< integer to store previous value of x/i */ int prev_j; /*!< integer to store previous value of y/j */ int prev2_i; /*!< integer to store previous, previous value of x/i */ int prev2_j; /*!< integer to store previous, previous value of y/j */ bool gamePlaying = false; /*!< bool to store whether the game is in play or not */ int pauseCount; /*!< counts how many times the player has paused */ /** Displays new fruit */ void generateFood(); /** Generates new random coordinates for the fruit */ void newFruitXY(); /** Receives input form joystick and updates the current direction */ void moveSnake(); /** Restricted boundaries */ void hardWall(); /** Map with obstacles in the way */ void specialMap(); /** Infinite boundaries */ void wrapAround(); /** Calculates score */ void scoreCalculation(); /** Displayes scores when player dies */ void gameOver(); /** Initilaises the snake so it's moving from left to right to begin with */ void initSnakeTail(); /** Splash screen for the intro of the game */ void snakeIntro(); /** Game paused function */ void gamePaused(); /** Contains all logic for the snake game and displays accordingly */ void gameLogic(); #endif