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.
Dependencies: N5110 mbed PowerControl
GameScreen.h@12:9ba4b21f8220, 2015-04-29 (annotated)
- Committer:
- AppleJuice
- Date:
- Wed Apr 29 23:45:08 2015 +0000
- Revision:
- 12:9ba4b21f8220
- Parent:
- 11:c6c88617f7e7
- Child:
- 13:7071a14b2fab
record entry screen complete;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AppleJuice | 0:c2c1df1163f1 | 1 | #ifndef GameScreen_H |
AppleJuice | 0:c2c1df1163f1 | 2 | #define GameScreen_H |
AppleJuice | 0:c2c1df1163f1 | 3 | |
AppleJuice | 0:c2c1df1163f1 | 4 | #include "mbed.h" |
AppleJuice | 0:c2c1df1163f1 | 5 | #include "N5110.h" |
AppleJuice | 0:c2c1df1163f1 | 6 | |
AppleJuice | 0:c2c1df1163f1 | 7 | //GameScreen class is an extension of the base Nokia Library Created by Craig Evans |
AppleJuice | 4:f8d04c073730 | 8 | // This extension adds functionality relevant to 'Fall Down Game'. |
AppleJuice | 0:c2c1df1163f1 | 9 | // drawPlatform, drawBall, drawScore etc.... |
AppleJuice | 2:d4402bc3dd45 | 10 | // # of platforms defined and can be altered/ |
AppleJuice | 2:d4402bc3dd45 | 11 | // updates platforms at speed proportional to speedOfPlatforms_ |
AppleJuice | 2:d4402bc3dd45 | 12 | // manages location and state of all platforms + player ball |
AppleJuice | 2:d4402bc3dd45 | 13 | |
AppleJuice | 6:b1c54f8b28fe | 14 | |
AppleJuice | 2:d4402bc3dd45 | 15 | struct Platform { |
AppleJuice | 2:d4402bc3dd45 | 16 | int id; //for identifying. |
AppleJuice | 2:d4402bc3dd45 | 17 | int x; //col of gap |
AppleJuice | 4:f8d04c073730 | 18 | int y; //row |
AppleJuice | 4:f8d04c073730 | 19 | }; |
AppleJuice | 4:f8d04c073730 | 20 | |
AppleJuice | 4:f8d04c073730 | 21 | struct Ball { |
AppleJuice | 4:f8d04c073730 | 22 | int x; |
AppleJuice | 4:f8d04c073730 | 23 | int y; |
AppleJuice | 2:d4402bc3dd45 | 24 | }; |
AppleJuice | 0:c2c1df1163f1 | 25 | |
AppleJuice | 0:c2c1df1163f1 | 26 | class GameScreen: public N5110::N5110 |
AppleJuice | 4:f8d04c073730 | 27 | { |
AppleJuice | 0:c2c1df1163f1 | 28 | public: |
AppleJuice | 0:c2c1df1163f1 | 29 | explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin) |
AppleJuice | 4:f8d04c073730 | 30 | :N5110(pwrPin, scePin,rstPin,dcPin,mosiPin,sclkPin,ledPin) {} //classes needed are private...dont want to steal code so we'll just inheret constructor aswell :) |
AppleJuice | 4:f8d04c073730 | 31 | |
AppleJuice | 8:ebddb721f1ee | 32 | void Initialize(); |
AppleJuice | 11:c6c88617f7e7 | 33 | void printString(const char * str,int x,int y,bool invert = false); //overide base class |
AppleJuice | 5:d395a7134278 | 34 | void drawBall(); |
AppleJuice | 8:ebddb721f1ee | 35 | void eraseBall(); |
AppleJuice | 2:d4402bc3dd45 | 36 | void drawAllPlatforms(); |
AppleJuice | 2:d4402bc3dd45 | 37 | void eraseAllPlatforms(); |
AppleJuice | 4:f8d04c073730 | 38 | void shiftAllPlatforms(); //move all platforms up 1 pixel |
AppleJuice | 5:d395a7134278 | 39 | Platform nextClosestPlatform(int y); |
AppleJuice | 8:ebddb721f1ee | 40 | void displayStartScreen(); |
AppleJuice | 8:ebddb721f1ee | 41 | void displayInstructionScreen(); |
AppleJuice | 8:ebddb721f1ee | 42 | void displayCountdown(); |
AppleJuice | 11:c6c88617f7e7 | 43 | void displayEndScreen(int lvl,int *cursor); |
AppleJuice | 12:9ba4b21f8220 | 44 | void displayRecordScreen(int *cursor, char ltr1, char ltr2,char ltr3); |
AppleJuice | 1:3305d7e44880 | 45 | |
AppleJuice | 5:d395a7134278 | 46 | //Write Access, set |
AppleJuice | 4:f8d04c073730 | 47 | void setBallPos(int x, int y) { playerBall.x = x; playerBall.y = y; } |
AppleJuice | 4:f8d04c073730 | 48 | |
AppleJuice | 5:d395a7134278 | 49 | //Read Access, get |
AppleJuice | 5:d395a7134278 | 50 | Platform getPlatformData(int i) { return *allPlatforms[i]; } |
AppleJuice | 5:d395a7134278 | 51 | int getPlatGapSize() { return platGapSize_; } |
AppleJuice | 5:d395a7134278 | 52 | int getMaxY() { return maxY_; } |
AppleJuice | 5:d395a7134278 | 53 | int getMaxX() { return maxX_; } |
AppleJuice | 5:d395a7134278 | 54 | int getPlatThickness() { return platThickness_; } |
AppleJuice | 4:f8d04c073730 | 55 | int getBallR() { return ballRadius_; } |
AppleJuice | 4:f8d04c073730 | 56 | int getBallX() { return playerBall.x; } |
AppleJuice | 4:f8d04c073730 | 57 | int getBallY() { return playerBall.y; } |
AppleJuice | 0:c2c1df1163f1 | 58 | |
AppleJuice | 4:f8d04c073730 | 59 | private: |
AppleJuice | 8:ebddb721f1ee | 60 | void createAllPlatforms(); |
AppleJuice | 4:f8d04c073730 | 61 | void drawPlatform(int x,int y); |
AppleJuice | 4:f8d04c073730 | 62 | void erasePlatform(int y); |
AppleJuice | 4:f8d04c073730 | 63 | void freeAllPlatforms(); //garbage cleanup |
AppleJuice | 4:f8d04c073730 | 64 | |
AppleJuice | 1:3305d7e44880 | 65 | private: |
AppleJuice | 2:d4402bc3dd45 | 66 | static const int platGapSize_ = 8; //standard platform gap width in pixels |
AppleJuice | 2:d4402bc3dd45 | 67 | static const int platThickness_ = 2; //platform thickness in pixels |
AppleJuice | 2:d4402bc3dd45 | 68 | static const int platSpacing_ = 14; // subsequent platform spacing in pixels |
AppleJuice | 2:d4402bc3dd45 | 69 | static const int maxX_ = 48; // maximun horizontal pixel |
AppleJuice | 2:d4402bc3dd45 | 70 | static const int maxY_ = 84; // maximum vertical pixel |
AppleJuice | 2:d4402bc3dd45 | 71 | static const int ballRadius_ = 4; // size of player ball |
AppleJuice | 2:d4402bc3dd45 | 72 | static const int numPlatforms_ = 6; // total number of platforms |
AppleJuice | 4:f8d04c073730 | 73 | Ball playerBall; |
AppleJuice | 4:f8d04c073730 | 74 | Platform *allPlatforms[numPlatforms_]; //array used to track each platform, and refresh when needed! |
AppleJuice | 0:c2c1df1163f1 | 75 | }; |
AppleJuice | 0:c2c1df1163f1 | 76 | |
AppleJuice | 2:d4402bc3dd45 | 77 | |
AppleJuice | 0:c2c1df1163f1 | 78 | #endif |