Retro game that let's the player steer a ball through a hole filled maze. Has multiple levels of increasing difficulty.

Dependencies:   LCD_ST7735 MusicEngine RETRO_BallsAndThings mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Game.h Source File

Game.h

00001 #pragma once
00002 #include <stdarg.h>
00003 #include <algorithm>        // required for min() and max(), see http://www.cplusplus.com/reference/algorithm/
00004 #include "mbed.h"
00005 
00006 #include "Color565.h"
00007 #include "font_OEM.h"
00008 #include "LCD_ST7735.h"
00009 #include "SoundFX.h"
00010 #include "Accelerometer.h"
00011 #include "Shapes.h"
00012 #include "Ball.h"
00013 #include "Wall.h"
00014 #include "Hole.h"
00015 
00016 
00017 #define NUM_WALLS 30
00018 #define NUM_HOLES 20
00019 
00020 class Game
00021 {
00022     static const char* LOSE_1;
00023     static const char* LOSE_2;
00024     static const char* SPLASH_1;
00025     static const char* SPLASH_2;
00026     static const char* SPLASH_3;
00027     
00028     static const int BALL_RADIUS = 5;
00029     static const int HOLE_RADIUS = 6;
00030     static const char I2C_ADDR = 0x1C << 1;
00031 
00032     DigitalIn left;
00033     DigitalIn right;
00034     DigitalIn down;
00035     DigitalIn up;
00036     DigitalIn square;
00037     DigitalIn circle; 
00038     DigitalOut led1;
00039     DigitalOut led2;
00040     AnalogIn ain;
00041     LCD_ST7735 disp;
00042 
00043     SoundFX snd;
00044     Accelerometer accel;
00045     Timer tWait;    // timer used for tickcounts
00046 
00047     Vector vGravity;
00048     Vector vFriction;
00049     Ball ball;
00050     Wall aWalls[NUM_WALLS];
00051     Hole aHoles[NUM_HOLES];
00052 
00053     bool mode;
00054     int nTopWall;
00055     int nBalls;
00056     int nScore;
00057 
00058     bool lastUp;
00059     bool lastDown;
00060     int nGameTickDelay;     // delay during game-tick
00061 
00062     void printDouble(double value, int x, int y);
00063     
00064     void initialize();
00065     void initLevel();
00066     Point getGridPos(char *sPos);
00067     void addWall(char *sWall);
00068     void addWalls(char *sWalls);
00069     void drawWalls();
00070     void addHole(char *sHole);
00071     void addHoles(char *sHoles);
00072     void drawHoles();
00073     
00074     void drawString(const char* str, int y);
00075 
00076     void newBall();
00077     void updateBall();
00078     void redrawBall();
00079     void checkBallCollision();
00080     
00081     void checkTilt();
00082     void checkButtons();
00083 
00084     void printf(int x, int y, const char *szFormat, ...);
00085     void checkNumBalls();
00086     
00087     public:
00088         Game();
00089         
00090         void showSplashScreen();
00091         void tick();
00092 };