Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Committer:
AppleJuice
Date:
Tue Mar 10 21:17:58 2015 +0000
Revision:
8:ebddb721f1ee
Parent:
6:b1c54f8b28fe
Child:
10:d8ef8633bd98
added: start screen, instructions, and countdown to start.; ; bugs: ball sometimes passes through platforms if it traveled sideways through another above. Should be easily fixed by adding left/right movement boundaries.

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 2:d4402bc3dd45 14 //ISSUES:
AppleJuice 2:d4402bc3dd45 15 // text is written in wrong plane. Easy fix if I had access to private members of N5110...could just edit lib...
AppleJuice 2:d4402bc3dd45 16 // could also override current fontarray... look into this later.
AppleJuice 2:d4402bc3dd45 17 //
AppleJuice 2:d4402bc3dd45 18 //
AppleJuice 2:d4402bc3dd45 19
AppleJuice 2:d4402bc3dd45 20
AppleJuice 6:b1c54f8b28fe 21
AppleJuice 2:d4402bc3dd45 22 struct Platform {
AppleJuice 2:d4402bc3dd45 23 int id; //for identifying.
AppleJuice 2:d4402bc3dd45 24 int x; //col of gap
AppleJuice 4:f8d04c073730 25 int y; //row
AppleJuice 4:f8d04c073730 26 };
AppleJuice 4:f8d04c073730 27
AppleJuice 4:f8d04c073730 28 struct Ball {
AppleJuice 4:f8d04c073730 29 int x;
AppleJuice 4:f8d04c073730 30 int y;
AppleJuice 2:d4402bc3dd45 31 };
AppleJuice 0:c2c1df1163f1 32
AppleJuice 0:c2c1df1163f1 33 class GameScreen: public N5110::N5110
AppleJuice 4:f8d04c073730 34 {
AppleJuice 0:c2c1df1163f1 35 public:
AppleJuice 0:c2c1df1163f1 36 explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
AppleJuice 4:f8d04c073730 37 :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 38
AppleJuice 8:ebddb721f1ee 39 void Initialize();
AppleJuice 6:b1c54f8b28fe 40 void printString(const char * str,int x,int y); //overide base class
AppleJuice 5:d395a7134278 41 void drawBall();
AppleJuice 8:ebddb721f1ee 42 void eraseBall();
AppleJuice 2:d4402bc3dd45 43 void drawAllPlatforms();
AppleJuice 2:d4402bc3dd45 44 void eraseAllPlatforms();
AppleJuice 4:f8d04c073730 45 void shiftAllPlatforms(); //move all platforms up 1 pixel
AppleJuice 5:d395a7134278 46 Platform nextClosestPlatform(int y);
AppleJuice 8:ebddb721f1ee 47 void displayStartScreen();
AppleJuice 8:ebddb721f1ee 48 void displayInstructionScreen();
AppleJuice 8:ebddb721f1ee 49 void displayCountdown();
AppleJuice 1:3305d7e44880 50
AppleJuice 5:d395a7134278 51 //Write Access, set
AppleJuice 4:f8d04c073730 52 void setBallPos(int x, int y) { playerBall.x = x; playerBall.y = y; }
AppleJuice 4:f8d04c073730 53
AppleJuice 5:d395a7134278 54 //Read Access, get
AppleJuice 5:d395a7134278 55 Platform getPlatformData(int i) { return *allPlatforms[i]; }
AppleJuice 5:d395a7134278 56 int getPlatGapSize() { return platGapSize_; }
AppleJuice 5:d395a7134278 57 int getMaxY() { return maxY_; }
AppleJuice 5:d395a7134278 58 int getMaxX() { return maxX_; }
AppleJuice 5:d395a7134278 59 int getPlatThickness() { return platThickness_; }
AppleJuice 4:f8d04c073730 60 int getBallR() { return ballRadius_; }
AppleJuice 4:f8d04c073730 61 int getBallX() { return playerBall.x; }
AppleJuice 4:f8d04c073730 62 int getBallY() { return playerBall.y; }
AppleJuice 0:c2c1df1163f1 63
AppleJuice 4:f8d04c073730 64 private:
AppleJuice 8:ebddb721f1ee 65 void createAllPlatforms();
AppleJuice 4:f8d04c073730 66 void drawPlatform(int x,int y);
AppleJuice 4:f8d04c073730 67 void erasePlatform(int y);
AppleJuice 4:f8d04c073730 68 void freeAllPlatforms(); //garbage cleanup
AppleJuice 4:f8d04c073730 69
AppleJuice 1:3305d7e44880 70 private:
AppleJuice 2:d4402bc3dd45 71 static const int platGapSize_ = 8; //standard platform gap width in pixels
AppleJuice 2:d4402bc3dd45 72 static const int platThickness_ = 2; //platform thickness in pixels
AppleJuice 2:d4402bc3dd45 73 static const int platSpacing_ = 14; // subsequent platform spacing in pixels
AppleJuice 2:d4402bc3dd45 74 static const int maxX_ = 48; // maximun horizontal pixel
AppleJuice 2:d4402bc3dd45 75 static const int maxY_ = 84; // maximum vertical pixel
AppleJuice 2:d4402bc3dd45 76 static const int ballRadius_ = 4; // size of player ball
AppleJuice 2:d4402bc3dd45 77 static const int numPlatforms_ = 6; // total number of platforms
AppleJuice 4:f8d04c073730 78 Ball playerBall;
AppleJuice 4:f8d04c073730 79 Platform *allPlatforms[numPlatforms_]; //array used to track each platform, and refresh when needed!
AppleJuice 0:c2c1df1163f1 80 };
AppleJuice 0:c2c1df1163f1 81
AppleJuice 2:d4402bc3dd45 82
AppleJuice 0:c2c1df1163f1 83 #endif