Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of The_Children_of_Cronos_el15mggr by
hydralib.h
00001 #ifndef HYDRALIB_H 00002 #define HYDRALIB_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 00008 #define widthA 82 00009 #define heightA 36 00010 #define sizeA 3 00011 00012 00013 /** Head position */ 00014 struct position { 00015 int x;/**< x pos */ 00016 int y;/**< y pos */ 00017 } ; 00018 /** Food position */ 00019 struct foodposition { 00020 int x;/**< x pos */ 00021 int y;/**< y pos */ 00022 }; 00023 00024 /** Velocity vector */ 00025 struct velocity { 00026 int x; /**< x vector */ 00027 int y;/**< y vector */ 00028 } ; 00029 00030 /** Tail position */ 00031 struct tail { 00032 int X;/**< x pos */ 00033 int Y;/**< y pos */ 00034 } ; 00035 00036 00037 00038 00039 /** hydralib Class 00040 * @brief Library for the first game, Hydra 00041 * @brief Revision 1.3 00042 * @author Mateo Randulfe 00043 * @date May 2017 00044 */ 00045 00046 class hydralib 00047 { 00048 public: 00049 /** Constructor */ 00050 hydralib(); 00051 /** 00052 * Function that initialises the values for the main positions 00053 */ 00054 void init(); 00055 /** 00056 * Function that checks if the snake touched the extremes of the screen 00057 * or if it ate itself 00058 * @return if it touches or not 00059 */ 00060 bool border(); 00061 /** 00062 * Function that checks if the snake head position is the same as any of his tail parts position 00063 * ie if it ate itself 00064 * @return if it touches or not 00065 */ 00066 bool touch(); 00067 /** 00068 * Allow player to move and changes velocity of movement depending on the players input 00069 * @param a/b/x/y down,right,left and up 00070 * @param pad down,right,left and up 00071 */ 00072 void commands(Gamepad &pad,DigitalOut &a,DigitalOut &b,DigitalOut &x,DigitalOut &y); 00073 /** 00074 * Updates the movement of the snake tail and head id the snake moves 00075 */ 00076 void updatescr(); 00077 /** 00078 * Main draw function that draws all the component of the game 00079 * @param lcd for drawing into the screen 00080 */ 00081 void draw(N5110 &lcd); 00082 /** 00083 * Function that displays the game over screen and allows player to restart game 00084 *once restarted,all values set to original ones 00085 * @param lcd for drawing into the screen 00086 * @param start for restarting the game 00087 * @param pad for putting leds off 00088 */ 00089 void gameover(N5110 &lcd,DigitalOut &start,Gamepad &pad); 00090 /** 00091 * Function that switches only the same number of leds on as the same number of lifes 00092 * the player still have left 00093 * @param pad controls leds 00094 */ 00095 void leds(Gamepad &pad); 00096 /** 00097 * Function that sets the velocity of the game and the difficulty level 00098 * the highest the score the faster the game will go and the more difficult 00099 */ 00100 void velocities(); 00101 /** 00102 * Function that draws a difficulty levels indicator in the bottom on the screen 00103 * next to the score 00104 */ 00105 void rectangles(N5110 &lcd); 00106 /** Function that checks if the position of the head and the food is relatively the same 00107 * both of them are 3x3 rectangles. If any 2x2 parts of them are in contact it returns true 00108 * if it would be all 3x3 it would be too difficult 00109 * if it would be any 1x1 it would be too easy 00110 * @return true if eated 00111 */ 00112 bool eat(); 00113 /** 00114 * Pauses the game 00115 * @param l/r/lcd pauses the game and adds a p of pause in the screen 00116 */ 00117 void pausegame(DigitalOut &l,DigitalOut &r,N5110 &lcd,DigitalOut &back); 00118 /** 00119 * Function that helps lately in the main file to generate food and increase score and lenght 00120 */ 00121 void auxiliar(); 00122 /** stores score 00123 * @returns score 00124 */ 00125 int score(); 00126 00127 00128 //snake lenght,score,lifes and a buffer for printing score 00129 int _lenght , _score, _lifes; 00130 bool _pause; 00131 char _buffer[20]; 00132 position _pos; 00133 foodposition _food; 00134 velocity _vel; 00135 tail _body[100]; 00136 00137 }; 00138 #endif
Generated on Wed Jul 13 2022 07:38:17 by
1.7.2
