Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Committer:
AppleJuice
Date:
Mon Apr 27 21:10:23 2015 +0000
Revision:
10:d8ef8633bd98
Parent:
8:ebddb721f1ee
Child:
11:c6c88617f7e7
updated to new timer version. A single clock controls all animations. Also fixed fall through bug...;

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