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

This is a mod of the official Pong game released with the RETRO game console.

Committer:
maxint
Date:
Thu Jan 15 14:34:59 2015 +0000
Revision:
4:9ad3bc45b6ce
Parent:
3:2f09c90a732d
mod150115; - Added paddle control using tilting of the console; - Reduced flickering; - Finished mute function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
john_ghielec 1:cd8a3926f263 1 #include "mbed.h"
john_ghielec 1:cd8a3926f263 2
john_ghielec 1:cd8a3926f263 3 #include "DisplayN18.h"
john_ghielec 1:cd8a3926f263 4
john_ghielec 1:cd8a3926f263 5 #pragma once
john_ghielec 1:cd8a3926f263 6
john_ghielec 1:cd8a3926f263 7 class Game {
john_ghielec 1:cd8a3926f263 8 static const char* LOSE_1;
john_ghielec 1:cd8a3926f263 9 static const char* LOSE_2;
john_ghielec 2:6ab46f2e851a 10 static const char* SPLASH_1;
john_ghielec 2:6ab46f2e851a 11 static const char* SPLASH_2;
devhammer 3:2f09c90a732d 12 static const char* LIVES;
devhammer 3:2f09c90a732d 13 static const char* SCORE;
john_ghielec 1:cd8a3926f263 14
john_ghielec 1:cd8a3926f263 15 static const int BALL_RADIUS = 3;
devhammer 3:2f09c90a732d 16 static const int BALL_STARTING_SPEED = 3;
john_ghielec 1:cd8a3926f263 17 static const int PADDLE_WIDTH = 38;
john_ghielec 1:cd8a3926f263 18 static const int PADDLE_HEIGHT = 4;
devhammer 3:2f09c90a732d 19 static const int PADDLE_SPEED = 5;
john_ghielec 1:cd8a3926f263 20 static const int BOUNCE_SOUND_TICKS = 2;
john_ghielec 2:6ab46f2e851a 21 static const int GRAPH_HEIGHT = 40;
john_ghielec 2:6ab46f2e851a 22 static const int GRAPH_SPACING = 2;
john_ghielec 2:6ab46f2e851a 23 static const char I2C_ADDR = 0x1C << 1;
john_ghielec 1:cd8a3926f263 24
john_ghielec 1:cd8a3926f263 25 int ballX;
maxint 4:9ad3bc45b6ce 26 int ballXprev;
john_ghielec 1:cd8a3926f263 27 int ballY;
maxint 4:9ad3bc45b6ce 28 int ballYprev;
john_ghielec 1:cd8a3926f263 29 int ballSpeedX;
john_ghielec 1:cd8a3926f263 30 int ballSpeedY;
john_ghielec 1:cd8a3926f263 31 int paddleX;
maxint 4:9ad3bc45b6ce 32 int paddleXprev;
john_ghielec 1:cd8a3926f263 33 int pwmTicksLeft;
john_ghielec 1:cd8a3926f263 34 int lives;
devhammer 3:2f09c90a732d 35 int score;
john_ghielec 2:6ab46f2e851a 36 int graphX;
john_ghielec 2:6ab46f2e851a 37 bool mode;
john_ghielec 2:6ab46f2e851a 38 bool lastUp;
john_ghielec 2:6ab46f2e851a 39 bool lastDown;
devhammer 3:2f09c90a732d 40 bool muted;
john_ghielec 2:6ab46f2e851a 41 unsigned short colors[3];
john_ghielec 2:6ab46f2e851a 42
john_ghielec 1:cd8a3926f263 43 DigitalIn left;
john_ghielec 1:cd8a3926f263 44 DigitalIn right;
john_ghielec 1:cd8a3926f263 45 DigitalIn down;
john_ghielec 1:cd8a3926f263 46 DigitalIn up;
john_ghielec 1:cd8a3926f263 47 DigitalIn square;
john_ghielec 1:cd8a3926f263 48 DigitalIn circle;
john_ghielec 1:cd8a3926f263 49 DigitalOut led1;
john_ghielec 1:cd8a3926f263 50 DigitalOut led2;
john_ghielec 1:cd8a3926f263 51 PwmOut pwm;
john_ghielec 1:cd8a3926f263 52 AnalogIn ain;
john_ghielec 1:cd8a3926f263 53 I2C i2c;
john_ghielec 1:cd8a3926f263 54 DisplayN18 disp;
john_ghielec 1:cd8a3926f263 55
john_ghielec 2:6ab46f2e851a 56 void readRegisters(char address, char* buffer, int len);
john_ghielec 2:6ab46f2e851a 57 int writeRegister(char address, char value);
john_ghielec 2:6ab46f2e851a 58 void getXYZ(double& x, double& y, double& z);
john_ghielec 2:6ab46f2e851a 59 double convert(char* buffer);
john_ghielec 2:6ab46f2e851a 60 void printDouble(double value, int x, int y);
john_ghielec 2:6ab46f2e851a 61
john_ghielec 2:6ab46f2e851a 62 void drawAxes();
john_ghielec 2:6ab46f2e851a 63 void drawPoint(int axis, double value);
john_ghielec 2:6ab46f2e851a 64 void checkGraphReset();
john_ghielec 2:6ab46f2e851a 65
john_ghielec 1:cd8a3926f263 66 void initialize();
john_ghielec 1:cd8a3926f263 67 void initializeBall();
john_ghielec 1:cd8a3926f263 68
john_ghielec 1:cd8a3926f263 69 void drawString(const char* str, int y);
john_ghielec 1:cd8a3926f263 70
john_ghielec 1:cd8a3926f263 71 void clearPaddle();
john_ghielec 1:cd8a3926f263 72 void drawPaddle();
maxint 4:9ad3bc45b6ce 73 void redrawPaddle();
john_ghielec 1:cd8a3926f263 74 void updatePaddle();
john_ghielec 1:cd8a3926f263 75
john_ghielec 1:cd8a3926f263 76 void clearBall();
maxint 4:9ad3bc45b6ce 77 void clearBallPrev();
john_ghielec 1:cd8a3926f263 78 void drawBall();
maxint 4:9ad3bc45b6ce 79 void redrawBall();
john_ghielec 1:cd8a3926f263 80 void updateBall();
john_ghielec 1:cd8a3926f263 81
maxint 4:9ad3bc45b6ce 82 int checkTilt();
john_ghielec 2:6ab46f2e851a 83 void checkButtons();
john_ghielec 1:cd8a3926f263 84 void checkCollision();
john_ghielec 1:cd8a3926f263 85 void checkPwm();
john_ghielec 1:cd8a3926f263 86 void checkLives();
john_ghielec 1:cd8a3926f263 87
john_ghielec 1:cd8a3926f263 88 public:
john_ghielec 1:cd8a3926f263 89 Game();
john_ghielec 1:cd8a3926f263 90
john_ghielec 1:cd8a3926f263 91 void showSplashScreen();
john_ghielec 1:cd8a3926f263 92 void tick();
john_ghielec 1:cd8a3926f263 93 };