Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GameScreen.h Source File

GameScreen.h

Go to the documentation of this file.
00001 /**
00002 @file GameScreen.h
00003 @brief Simple library for managing "Let The Ball Drop" Game screen
00004 @brief extends on N5110 library created by Craig.A.Evans
00005 @brief Adds functionality to animate game platforms and ball,
00006 @brief also displays various game screens throughout gameplay.
00007 @brief printString function from base class N5110 is overwritten and
00008 @brief extened to vertical orientation text and inverted pixel scheme.
00009 @author Thomas Davies
00010 @date May 2015
00011 */
00012 
00013 
00014 #ifndef GameScreen_H
00015 #define GameScreen_H
00016 
00017 #include "mbed.h"
00018 #include "N5110.h"
00019 
00020 /**
00021 Platform structure
00022 */
00023 struct Platform {
00024     int id;     ///< id identifier of platform
00025     int x;      ///< x-location of gap in platform
00026     int y;      ///< y-location of top pixel in platform
00027 };
00028 
00029 /**
00030 Ball structure
00031 */
00032 struct Ball {
00033     int x;      ///< ball x-location (far right pixel)
00034     int y;      ///< ball y-location (top pixel)
00035 };
00036 
00037 /** GameScreen Class
00038 *
00039 *Nokia 5110 screen controller with specific functions for manageing game objects and screens.
00040 *
00041 */
00042 class GameScreen: public N5110::N5110
00043 {
00044 public:
00045 
00046     /** Create GameScreen object connected to specific pins
00047     *
00048     * constructor inhereted from base class
00049     * @param pwr Pin connected to Vcc on the LCD display (pin 1)
00050     * @param sce Pin connected to chip enable (pin 3)
00051     * @param rst Pin connected to reset (pin 4)
00052     * @param dc  Pin connected to data/command select (pin 5)
00053     * @param mosi Pin connected to data input (MOSI) (pin 6)
00054     * @param sclk Pin connected to serial clock (SCLK) (pin 7)
00055     * @param led Pin connected to LED backlight (must be PWM) (pin 8)
00056     *
00057     */
00058     explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
00059         :N5110(pwrPin, scePin,rstPin,dcPin,mosiPin,sclkPin,ledPin) {}
00060 
00061     /** Initialise Game Screen
00062     *
00063     *   Calls N5110::init() which powers up display and sets starting brightness
00064     *   initialises ball position and creates platform list.
00065     *
00066     */
00067     void Initialize();
00068 
00069     /** Print String
00070     *
00071     * Overrides N5110::printString(*) to allow vertical orientation text.
00072     * requires a refresh to display.
00073     *
00074     *@param str - string to be printed
00075     *@param x - x coordinate of the string
00076     *@param y - y coordinate of the string
00077     *@param invert - color inversion toggle (default = false)
00078     *
00079     */
00080     void printString(const char * str,int x,int y,bool invert = false);
00081 
00082     /** Draw Ball
00083     *
00084     * Draws ball on screen from playerBall struct in object, requires refresh.
00085     *
00086     */
00087     void drawBall();
00088 
00089     /** Erases Ball
00090     *
00091     * Erases ball on screen from playerBall struct in object, requires refresh.
00092     *
00093     */
00094     void eraseBall();
00095 
00096     /** Draws All Platforms
00097     *
00098     * Draws all platforms from array allPlatforms in object, requires refresh.
00099     *
00100     */
00101     void drawAllPlatforms();
00102 
00103     /** Erases All Platforms
00104     *
00105     * Erases all platforms on screen from array allPlatforms in object, requires refresh.
00106     *
00107     */
00108     void eraseAllPlatforms();
00109 
00110     /** Shifts Platforms Up
00111     *
00112     * Alter array of platforms to shift each platform up n pisxels, requires refresh.
00113     *@param n - number of pixels to shift platform.
00114     *
00115     */
00116     void shiftAllPlatforms(int n=1);
00117 
00118     /** Finds next closest platform
00119     *
00120     *@param y - vertical position on screen
00121     *@return next closest platform to y.
00122     *
00123     */
00124     Platform nextClosestPlatform(int y);
00125 
00126     /** Displays The Start Screen
00127     *
00128     * first screen user sees, author name & title
00129     *
00130     */
00131     void displayStartScreen();
00132 
00133     /** Displays Instruction Screen
00134     *
00135     * shows game instructions, navigation method and "back story"
00136     *
00137     */
00138     void displayInstructionScreen();
00139 
00140     /** Displays Countdown
00141     *
00142     * countdown from 5 to 1 displayed on screen.
00143     *
00144     */
00145     void displayCountdown();
00146 
00147     /** displays Game Over Screen
00148     *
00149     * shows player level, and displays options.
00150     * options can be highlighted according to cursor location array
00151     * @param lvl - game level to be displayed.
00152     * @param cursor - array of ints used to highlight options.
00153     * @param isRecord - only display record option if player achieved a record
00154     *
00155     */
00156     void displayEndScreen(int lvl,int *cursor,bool isRecord);
00157 
00158     /** Display Initial Entry Screen
00159     *
00160     * screen for user to enter initials.
00161     *
00162     *@param cursor - array of ints used to highlight letters
00163     *@param ltr1 - first letter of initials
00164     *@param ltr2 - second letter of initials
00165     *@param ltr3 - third letter of initials
00166     *
00167     */
00168     void displayRecordScreen(int *cursor, char ltr1, char ltr2,char ltr3);
00169 
00170     /** Display High Score Screen
00171     *
00172     *@param s_hs0 - initials of top player.
00173     *@param s_hs1 - initials of second player.
00174     *@param s_hs2 - initials of third player.
00175     *@param d_hs - array of high score levels.
00176     */
00177     void displayHighScores(char *s_hs0,char *s_hs1,char *s_hs2,int *d_hs);
00178 
00179     /** Display Second instruction Screen
00180     *
00181     */
00182     void displayInstructionScreen2();
00183 
00184     /** Display Pause Menu Screen
00185     *
00186     *@param cursor - array of ints used to highlight selection
00187     *@param isSound - toggle for "yes" or "no" text for sound
00188     *
00189     */
00190     void displayPauseScreen(int *cursor, char isSound);
00191 
00192     /** Sets Ball Position
00193     *
00194     *@param x - new x coordinate of ball (right side)
00195     *@param y - new y coordinate of ball (top)
00196     */
00197     void        setBallPos(int x, int y)        {
00198         playerBall.x = x;
00199         playerBall.y = y;
00200     }
00201 
00202     //ACCESSOR FUNCTIONS
00203     /** @return platform gap size */
00204     int         getPlatGapSize ()                {
00205         return platGapSize_;
00206     }
00207 
00208     /** @return screen max Y */
00209     int         getMaxY ()                          {
00210         return maxY_;
00211     }
00212 
00213     /** @return screen max X */
00214     int         getMaxX ()                          {
00215         return maxX_;
00216     }
00217 
00218     /** @return platform thickness */
00219     int         getPlatThickness ()                 {
00220         return platThickness_;
00221     }
00222 
00223     /** @return ball radius */
00224     int         getBallR ()                      {
00225         return ballRadius_;
00226     }
00227 
00228     /** @return ball X coordinate */
00229     int         getBallX ()                      {
00230         return playerBall.x;
00231     }
00232 
00233     /** @return ball Y coordinate*/
00234     int         getBallY ()                      {
00235         return playerBall.y;
00236     }
00237 
00238 
00239     /** Creates All Platforms
00240     *
00241     * Randomly selects location of gap in each platform and adds all to 'allPlatforms' array.
00242     *
00243     */
00244     void createAllPlatforms();
00245 
00246     /** Draws Platform
00247     *
00248     * Draws a platform with thickness _platThickness at height y and gap x.
00249     *
00250     *@param x - location of gap on platform (right hand pixel)
00251     *@param y - y position of platform
00252     *
00253     */
00254     void drawPlatform(int x,int y);
00255 
00256     /** Draws Platform
00257     *
00258     * Erases a platform with thickness _platThickness at height y.
00259     *
00260     *@param y - y position of platform
00261     *
00262     */
00263     void erasePlatform(int y);
00264 
00265     /** Free All Platforms
00266     *
00267     * frees memory of each platform in 'allPlatforms' array and destroys the array.
00268     *
00269     */
00270     void freeAllPlatforms();
00271 
00272     static const int platGapSize_ = 8;          ///< standard platform gap width in pixels
00273     static const int platThickness_ = 2;        ///< platform thickness in pixels
00274     static const int platSpacing_ = 14;         ///< subsequent platform spacing in pixels
00275     static const int maxX_ = 48;                ///< maximun horizontal pixel
00276     static const int maxY_ = 84;                ///< maximum vertical pixel
00277     static const int ballRadius_ = 4;           ///< size of player ball
00278     static const int numPlatforms_ = 6;         ///< total number of platforms
00279     Ball playerBall;                            ///< player ball structure
00280     Platform *allPlatforms[numPlatforms_];      ///< array used to track each platform, and refresh when needed!
00281 };
00282 
00283 
00284 #endif