Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Committer:
AppleJuice
Date:
Mon Apr 27 23:49:19 2015 +0000
Revision:
11:c6c88617f7e7
Parent:
10:d8ef8633bd98
Child:
12:9ba4b21f8220
added game over screen, and text color inverting. Current state = game over is start screen. Need to do: button press detection, up/down on joystick, menu scrolling, alphabet selector, csv management, sounds!

Who changed what in which revision?

UserRevisionLine numberNew 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 1:3305d7e44880 44
AppleJuice 5:d395a7134278 45 //Write Access, set
AppleJuice 4:f8d04c073730 46 void setBallPos(int x, int y) { playerBall.x = x; playerBall.y = y; }
AppleJuice 4:f8d04c073730 47
AppleJuice 5:d395a7134278 48 //Read Access, get
AppleJuice 5:d395a7134278 49 Platform getPlatformData(int i) { return *allPlatforms[i]; }
AppleJuice 5:d395a7134278 50 int getPlatGapSize() { return platGapSize_; }
AppleJuice 5:d395a7134278 51 int getMaxY() { return maxY_; }
AppleJuice 5:d395a7134278 52 int getMaxX() { return maxX_; }
AppleJuice 5:d395a7134278 53 int getPlatThickness() { return platThickness_; }
AppleJuice 4:f8d04c073730 54 int getBallR() { return ballRadius_; }
AppleJuice 4:f8d04c073730 55 int getBallX() { return playerBall.x; }
AppleJuice 4:f8d04c073730 56 int getBallY() { return playerBall.y; }
AppleJuice 0:c2c1df1163f1 57
AppleJuice 4:f8d04c073730 58 private:
AppleJuice 8:ebddb721f1ee 59 void createAllPlatforms();
AppleJuice 4:f8d04c073730 60 void drawPlatform(int x,int y);
AppleJuice 4:f8d04c073730 61 void erasePlatform(int y);
AppleJuice 4:f8d04c073730 62 void freeAllPlatforms(); //garbage cleanup
AppleJuice 4:f8d04c073730 63
AppleJuice 1:3305d7e44880 64 private:
AppleJuice 2:d4402bc3dd45 65 static const int platGapSize_ = 8; //standard platform gap width in pixels
AppleJuice 2:d4402bc3dd45 66 static const int platThickness_ = 2; //platform thickness in pixels
AppleJuice 2:d4402bc3dd45 67 static const int platSpacing_ = 14; // subsequent platform spacing in pixels
AppleJuice 2:d4402bc3dd45 68 static const int maxX_ = 48; // maximun horizontal pixel
AppleJuice 2:d4402bc3dd45 69 static const int maxY_ = 84; // maximum vertical pixel
AppleJuice 2:d4402bc3dd45 70 static const int ballRadius_ = 4; // size of player ball
AppleJuice 2:d4402bc3dd45 71 static const int numPlatforms_ = 6; // total number of platforms
AppleJuice 4:f8d04c073730 72 Ball playerBall;
AppleJuice 4:f8d04c073730 73 Platform *allPlatforms[numPlatforms_]; //array used to track each platform, and refresh when needed!
AppleJuice 0:c2c1df1163f1 74 };
AppleJuice 0:c2c1df1163f1 75
AppleJuice 2:d4402bc3dd45 76
AppleJuice 0:c2c1df1163f1 77 #endif