new mods upon mods by devhammer: - Added paddle control using tilting of the console - Finished mute function - Reduced flickering See game.cpp for full info.

Dependencies:   mbed

Fork of RETRO_Pong_Mod by G. Andrew Duthie

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Game.h Source File

Game.h

00001 #include "mbed.h"
00002 
00003 #include "DisplayN18.h"
00004 
00005 #pragma once
00006 
00007 class Game {    
00008     static const char* LOSE_1;
00009     static const char* LOSE_2;
00010     static const char* SPLASH_1;
00011     static const char* SPLASH_2;
00012     static const char* LIVES;
00013     static const char* SCORE;
00014     
00015     static const int BALL_RADIUS = 3;
00016     static const int BALL_STARTING_SPEED = 3;
00017     static const int PADDLE_WIDTH = 38;
00018     static const int PADDLE_HEIGHT = 4;
00019     static const int PADDLE_SPEED = 5;
00020     static const int BOUNCE_SOUND_TICKS = 2;
00021     static const int GRAPH_HEIGHT = 40;
00022     static const int GRAPH_SPACING = 2;
00023     static const char I2C_ADDR = 0x1C << 1;
00024     
00025     int ballX;
00026     int ballXprev;
00027     int ballY;
00028     int ballYprev;
00029     int ballSpeedX;
00030     int ballSpeedY;
00031     int paddleX;
00032     int paddleXprev;
00033     int pwmTicksLeft;
00034     int lives;
00035     int score;
00036     int graphX;    
00037     bool mode;
00038     bool lastUp;
00039     bool lastDown;
00040     bool muted;
00041     unsigned short colors[3];
00042 
00043     DigitalIn left;
00044     DigitalIn right;
00045     DigitalIn down;
00046     DigitalIn up;
00047     DigitalIn square;
00048     DigitalIn circle; 
00049     DigitalOut led1;
00050     DigitalOut led2;
00051     PwmOut pwm;
00052     AnalogIn ain;
00053     I2C i2c;
00054     DisplayN18 disp;
00055     
00056     void readRegisters(char address, char* buffer, int len);
00057     int writeRegister(char address, char value);
00058     void getXYZ(double& x, double& y, double& z);
00059     double convert(char* buffer);
00060     void printDouble(double value, int x, int y);
00061     
00062     void drawAxes();
00063     void drawPoint(int axis, double value);
00064     void checkGraphReset();
00065     
00066     void initialize();
00067     void initializeBall();
00068     
00069     void drawString(const char* str, int y);
00070     
00071     void clearPaddle();
00072     void drawPaddle();
00073     void redrawPaddle();
00074     void updatePaddle();
00075     
00076     void clearBall();
00077     void clearBallPrev();
00078     void drawBall();
00079     void redrawBall();
00080     void updateBall();
00081     
00082     int checkTilt();
00083     void checkButtons();
00084     void checkCollision();
00085     void checkPwm();
00086     void checkLives();
00087     
00088     public:
00089         Game();
00090         
00091         void showSplashScreen();
00092         void tick();
00093 };