Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

GameScreen.h

Committer:
AppleJuice
Date:
2015-03-10
Revision:
6:b1c54f8b28fe
Parent:
5:d395a7134278
Child:
8:ebddb721f1ee

File content as of revision 6:b1c54f8b28fe:

#ifndef GameScreen_H
#define GameScreen_H

#include "mbed.h"
#include "N5110.h"

//GameScreen class is an extension of the base Nokia Library Created by Craig Evans
// This extension adds functionality relevant to 'Fall Down Game'.
// drawPlatform, drawBall, drawScore etc....
// # of platforms defined and can be altered/
// updates platforms at speed proportional to speedOfPlatforms_
// manages location and state of all platforms + player ball

//ISSUES:
//  text is written in wrong plane. Easy fix if I had access to private members of N5110...could just edit lib...
//      could also override current fontarray... look into this later.
//
//



struct Platform {
    int id;     //for identifying.
    int x;      //col of gap
    int y;      //row
};

struct Ball {
    int x;
    int y;
};

class GameScreen: public N5110::N5110
{
public:
    explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
        :N5110(pwrPin, scePin,rstPin,dcPin,mosiPin,sclkPin,ledPin) {}   //classes needed are private...dont want to steal code so we'll just inheret constructor aswell :)

    void Initialize(Ball ball);

    //draw horizontal platform where y top pixel layer location. x hole location
    void printString(const char * str,int x,int y);     //overide base class
    void drawBall();
    void eraseBall();
    void createAllPlatforms();
    void drawAllPlatforms();
    void eraseAllPlatforms();
    void shiftAllPlatforms();     //move all platforms up 1 pixel
    Platform nextClosestPlatform(int y);
    
    //Write Access, set
    void        setBallPos(int x, int y)        { playerBall.x = x; playerBall.y = y; }

    //Read Access, get
    Platform    getPlatformData(int i)          { return *allPlatforms[i];  }
    int         getPlatGapSize()                { return platGapSize_;       }  
    int         getMaxY()                          { return maxY_;             }
    int         getMaxX()                          { return maxX_;             }
    int         getPlatThickness()                 { return platThickness_;    }
    int         getBallR()                      { return ballRadius_;       }
    int         getBallX()                      { return playerBall.x;      }
    int         getBallY()                      { return playerBall.y;      }
    
private:
    void drawPlatform(int x,int y);
    void erasePlatform(int y);
    void freeAllPlatforms();        //garbage cleanup

private:
    static const int platGapSize_ = 8;          //standard platform gap width in pixels
    static const int platThickness_ = 2;        //platform thickness in pixels
    static const int platSpacing_ = 14;         // subsequent platform spacing in pixels
    static const int maxX_ = 48;                // maximun horizontal pixel
    static const int maxY_ = 84;                // maximum vertical pixel
    static const int ballRadius_ = 4;           // size of player ball
    static const int numPlatforms_ = 6;         // total number of platforms
    Ball playerBall;
    Platform *allPlatforms[numPlatforms_];      //array used to track each platform, and refresh when needed!
};


#endif