Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Committer:
AppleJuice
Date:
Sat Mar 07 13:49:53 2015 +0000
Revision:
2:d4402bc3dd45
Parent:
1:3305d7e44880
Child:
4:f8d04c073730
Added platform functions;     - draw and erase platform;     - manage platforms using Platform struct array;     - draw/erase/free all platforms.; ; Added ball functions;     - drawBall;     - eraseBall

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 0:c2c1df1163f1 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 2:d4402bc3dd45 21 struct Platform {
AppleJuice 2:d4402bc3dd45 22 int id; //for identifying.
AppleJuice 2:d4402bc3dd45 23 int x; //col of gap
AppleJuice 2:d4402bc3dd45 24 int y; //row
AppleJuice 2:d4402bc3dd45 25 };
AppleJuice 0:c2c1df1163f1 26
AppleJuice 0:c2c1df1163f1 27 class GameScreen: public N5110::N5110
AppleJuice 1:3305d7e44880 28 {
AppleJuice 0:c2c1df1163f1 29 public:
AppleJuice 0:c2c1df1163f1 30 explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
AppleJuice 1:3305d7e44880 31 :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 1:3305d7e44880 32
AppleJuice 1:3305d7e44880 33 void Initialize();
AppleJuice 1:3305d7e44880 34
AppleJuice 1:3305d7e44880 35 //draw horizontal platform where y top pixel layer location. x hole location
AppleJuice 1:3305d7e44880 36 void drawPlatform(int x,int y);
AppleJuice 2:d4402bc3dd45 37 void erasePlatform(int y);
AppleJuice 2:d4402bc3dd45 38 void drawBall(int x, int y);
AppleJuice 2:d4402bc3dd45 39 void eraseBall(int x, int y);
AppleJuice 2:d4402bc3dd45 40 void createAllPlatforms();
AppleJuice 2:d4402bc3dd45 41 void freeAllPlatforms(); //garbage cleanup
AppleJuice 2:d4402bc3dd45 42 void drawAllPlatforms();
AppleJuice 2:d4402bc3dd45 43 void eraseAllPlatforms();
AppleJuice 2:d4402bc3dd45 44 void shiftAllPlatformsUp(); //move all platforms up 1 pixel
AppleJuice 1:3305d7e44880 45
AppleJuice 2:d4402bc3dd45 46 //Read Only
AppleJuice 1:3305d7e44880 47 int maxY(){ return maxY_; }
AppleJuice 1:3305d7e44880 48 int maxX(){ return maxX_; }
AppleJuice 2:d4402bc3dd45 49 int platThickness() {return platThickness_;}
AppleJuice 2:d4402bc3dd45 50 int ballRadius() {return ballRadius_;}
AppleJuice 0:c2c1df1163f1 51
AppleJuice 2:d4402bc3dd45 52 Platform *allPlatforms[6]; //public for testing...
AppleJuice 0:c2c1df1163f1 53
AppleJuice 1:3305d7e44880 54 private:
AppleJuice 2:d4402bc3dd45 55 static const int platGapSize_ = 8; //standard platform gap width in pixels
AppleJuice 2:d4402bc3dd45 56 static const int platThickness_ = 2; //platform thickness in pixels
AppleJuice 2:d4402bc3dd45 57 static const int platSpacing_ = 14; // subsequent platform spacing in pixels
AppleJuice 2:d4402bc3dd45 58 static const int maxX_ = 48; // maximun horizontal pixel
AppleJuice 2:d4402bc3dd45 59 static const int maxY_ = 84; // maximum vertical pixel
AppleJuice 2:d4402bc3dd45 60 static const int ballRadius_ = 4; // size of player ball
AppleJuice 2:d4402bc3dd45 61 static const int numPlatforms_ = 6; // total number of platforms
AppleJuice 2:d4402bc3dd45 62 //Platform *allPlatforms[numPlatforms_]; //array used to track each platform, and refresh when needed!
AppleJuice 0:c2c1df1163f1 63 };
AppleJuice 0:c2c1df1163f1 64
AppleJuice 2:d4402bc3dd45 65
AppleJuice 0:c2c1df1163f1 66 #endif