Thomas Davies / Mbed 2 deprecated LetTheBallDrop

Dependencies:   N5110 mbed PowerControl

Embed: (wiki syntax)

« Back to documentation index

GameScreen Class Reference

GameScreen Class. More...

#include <GameScreen.h>

Public Member Functions

 GameScreen (PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
 Create GameScreen object connected to specific pins.
void Initialize ()
 Initialise Game Screen.
void printString (const char *str, int x, int y, bool invert=false)
 Print String.
void drawBall ()
 Draw Ball.
void eraseBall ()
 Erases Ball.
void drawAllPlatforms ()
 Draws All Platforms.
void eraseAllPlatforms ()
 Erases All Platforms.
void shiftAllPlatforms (int n=1)
 Shifts Platforms Up.
Platform nextClosestPlatform (int y)
 Finds next closest platform.
void displayStartScreen ()
 Displays The Start Screen.
void displayInstructionScreen ()
 Displays Instruction Screen.
void displayCountdown ()
 Displays Countdown.
void displayEndScreen (int lvl, int *cursor, bool isRecord)
 displays Game Over Screen
void displayRecordScreen (int *cursor, char ltr1, char ltr2, char ltr3)
 Display Initial Entry Screen.
void displayHighScores (char *s_hs0, char *s_hs1, char *s_hs2, int *d_hs)
 Display High Score Screen.
void displayInstructionScreen2 ()
 Display Second instruction Screen.
void displayPauseScreen (int *cursor, char isSound)
 Display Pause Menu Screen.
void setBallPos (int x, int y)
 Sets Ball Position.
int getPlatGapSize ()
int getMaxY ()
int getMaxX ()
int getPlatThickness ()
int getBallR ()
int getBallX ()
int getBallY ()
void createAllPlatforms ()
 Creates All Platforms.
void drawPlatform (int x, int y)
 Draws Platform.
void erasePlatform (int y)
 Draws Platform.
void freeAllPlatforms ()
 Free All Platforms.

Data Fields

Ball playerBall
 player ball structure
PlatformallPlatforms [numPlatforms_]
 array used to track each platform, and refresh when needed!

Static Public Attributes

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

Detailed Description

GameScreen Class.

Nokia 5110 screen controller with specific functions for manageing game objects and screens.

Definition at line 42 of file GameScreen.h.


Constructor & Destructor Documentation

GameScreen ( PinName  pwrPin,
PinName  scePin,
PinName  rstPin,
PinName  dcPin,
PinName  mosiPin,
PinName  sclkPin,
PinName  ledPin 
) [explicit]

Create GameScreen object connected to specific pins.

constructor inhereted from base class

Parameters:
pwrPin connected to Vcc on the LCD display (pin 1)
scePin connected to chip enable (pin 3)
rstPin connected to reset (pin 4)
dcPin connected to data/command select (pin 5)
mosiPin connected to data input (MOSI) (pin 6)
sclkPin connected to serial clock (SCLK) (pin 7)
ledPin connected to LED backlight (must be PWM) (pin 8)

Definition at line 58 of file GameScreen.h.


Member Function Documentation

void createAllPlatforms (  )

Creates All Platforms.

Randomly selects location of gap in each platform and adds all to 'allPlatforms' array.

Definition at line 90 of file GameScreen.cpp.

void displayCountdown (  )

Displays Countdown.

countdown from 5 to 1 displayed on screen.

Definition at line 240 of file GameScreen.cpp.

void displayEndScreen ( int  lvl,
int *  cursor,
bool  isRecord 
)

displays Game Over Screen

shows player level, and displays options. options can be highlighted according to cursor location array

Parameters:
lvl- game level to be displayed.
cursor- array of ints used to highlight options.
isRecord- only display record option if player achieved a record

Definition at line 262 of file GameScreen.cpp.

void displayHighScores ( char *  s_hs0,
char *  s_hs1,
char *  s_hs2,
int *  d_hs 
)

Display High Score Screen.

Parameters:
s_hs0- initials of top player.
s_hs1- initials of second player.
s_hs2- initials of third player.
d_hs- array of high score levels.

Definition at line 303 of file GameScreen.cpp.

void displayInstructionScreen (  )

Displays Instruction Screen.

shows game instructions, navigation method and "back story"

Definition at line 210 of file GameScreen.cpp.

void displayInstructionScreen2 (  )

Display Second instruction Screen.

Definition at line 225 of file GameScreen.cpp.

void displayPauseScreen ( int *  cursor,
char  isSound 
)

Display Pause Menu Screen.

Parameters:
cursor- array of ints used to highlight selection
isSound- toggle for "yes" or "no" text for sound

Definition at line 324 of file GameScreen.cpp.

void displayRecordScreen ( int *  cursor,
char  ltr1,
char  ltr2,
char  ltr3 
)

Display Initial Entry Screen.

screen for user to enter initials.

Parameters:
cursor- array of ints used to highlight letters
ltr1- first letter of initials
ltr2- second letter of initials
ltr3- third letter of initials

Definition at line 281 of file GameScreen.cpp.

void displayStartScreen (  )

Displays The Start Screen.

first screen user sees, author name & title

Definition at line 195 of file GameScreen.cpp.

void drawAllPlatforms (  )

Draws All Platforms.

Draws all platforms from array allPlatforms in object, requires refresh.

Definition at line 110 of file GameScreen.cpp.

void drawBall (  )

Draw Ball.

Draws ball on screen from playerBall struct in object, requires refresh.

Definition at line 56 of file GameScreen.cpp.

void drawPlatform ( int  x,
int  y 
)

Draws Platform.

Draws a platform with thickness _platThickness at height y and gap x.

Parameters:
x- location of gap on platform (right hand pixel)
y- y position of platform

Definition at line 20 of file GameScreen.cpp.

void eraseAllPlatforms (  )

Erases All Platforms.

Erases all platforms on screen from array allPlatforms in object, requires refresh.

Definition at line 117 of file GameScreen.cpp.

void eraseBall (  )

Erases Ball.

Erases ball on screen from playerBall struct in object, requires refresh.

Definition at line 74 of file GameScreen.cpp.

void erasePlatform ( int  y )

Draws Platform.

Erases a platform with thickness _platThickness at height y.

Parameters:
y- y position of platform

Definition at line 38 of file GameScreen.cpp.

void freeAllPlatforms (  )

Free All Platforms.

frees memory of each platform in 'allPlatforms' array and destroys the array.

Definition at line 103 of file GameScreen.cpp.

int getBallR (  )
Returns:
ball radius

Definition at line 224 of file GameScreen.h.

int getBallX (  )
Returns:
ball X coordinate

Definition at line 229 of file GameScreen.h.

int getBallY (  )
Returns:
ball Y coordinate

Definition at line 234 of file GameScreen.h.

int getMaxX (  )
Returns:
screen max X

Definition at line 214 of file GameScreen.h.

int getMaxY (  )
Returns:
screen max Y

Definition at line 209 of file GameScreen.h.

int getPlatGapSize (  )
Returns:
platform gap size

Definition at line 204 of file GameScreen.h.

int getPlatThickness (  )
Returns:
platform thickness

Definition at line 219 of file GameScreen.h.

void Initialize (  )

Initialise Game Screen.

Calls N5110::init() which powers up display and sets starting brightness initialises ball position and creates platform list.

Definition at line 6 of file GameScreen.cpp.

Platform nextClosestPlatform ( int  y )

Finds next closest platform.

Parameters:
y- vertical position on screen
Returns:
next closest platform to y.

Definition at line 137 of file GameScreen.cpp.

void printString ( const char *  str,
int  x,
int  y,
bool  invert = false 
)

Print String.

Overrides N5110::printString(*) to allow vertical orientation text. requires a refresh to display.

Parameters:
str- string to be printed
x- x coordinate of the string
y- y coordinate of the string
invert- color inversion toggle (default = false)

Definition at line 159 of file GameScreen.cpp.

void setBallPos ( int  x,
int  y 
)

Sets Ball Position.

Parameters:
x- new x coordinate of ball (right side)
y- new y coordinate of ball (top)

Definition at line 197 of file GameScreen.h.

void shiftAllPlatforms ( int  n = 1 )

Shifts Platforms Up.

Alter array of platforms to shift each platform up n pisxels, requires refresh.

Parameters:
n- number of pixels to shift platform.

Definition at line 124 of file GameScreen.cpp.


Field Documentation

array used to track each platform, and refresh when needed!

Definition at line 280 of file GameScreen.h.

const int ballRadius_ = 4 [static]

size of player ball

Definition at line 277 of file GameScreen.h.

const int maxX_ = 48 [static]

maximun horizontal pixel

Definition at line 275 of file GameScreen.h.

const int maxY_ = 84 [static]

maximum vertical pixel

Definition at line 276 of file GameScreen.h.

const int numPlatforms_ = 6 [static]

total number of platforms

Definition at line 278 of file GameScreen.h.

const int platGapSize_ = 8 [static]

standard platform gap width in pixels

Definition at line 272 of file GameScreen.h.

const int platSpacing_ = 14 [static]

subsequent platform spacing in pixels

Definition at line 274 of file GameScreen.h.

const int platThickness_ = 2 [static]

platform thickness in pixels

Definition at line 273 of file GameScreen.h.

player ball structure

Definition at line 279 of file GameScreen.h.