Some random attempts at programming the retro console

Dependencies:   LCD_ST7735 mbed

Fork of RETRO_Pong_Mod by G. Andrew Duthie

Files at this revision

API Documentation at this revision

Comitter:
loop
Date:
Sat Feb 28 17:39:08 2015 +0000
Parent:
9:5c4a3e89a713
Commit message:
Remove some unused stuff

Changed in this revision

Game.cpp Show annotated file Show diff for this revision Revisions of this file
Game.h Show annotated file Show diff for this revision Revisions of this file
--- a/Game.cpp	Sat Feb 28 14:46:09 2015 +0000
+++ b/Game.cpp	Sat Feb 28 17:39:08 2015 +0000
@@ -36,7 +36,6 @@
     
     this->lastUp = false;
     this->lastDown = false;
-    this->mode = true;
     this->cCol = 0;
     
     this->i2c.frequency(400);
@@ -75,51 +74,12 @@
     y = this->convert(buffer + 2);
 }
 
-void Game::getXYZ(double& x, double& y, double& z) {
-    char buffer[6];
-    this->readRegisters(0x01, buffer, 4);
-    x = this->convert(buffer);
-    y = this->convert(buffer + 2);
-    z = this->convert(buffer + 4);
-
-}
-
 void Game::printDouble(double value, int x, int y) {
     char buffer[10];
     int len = sprintf(buffer, "%.1f", value);
     this->disp.drawString(font_ibm, x, y, buffer);
 }
 
-void Game::drawAxes() {
-    for (int i = 0; i < 3; i++) {
-        this->disp.drawLine(0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING), 0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT, Color565::White);
-        this->disp.drawLine(0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT / 2, disp.getWidth(), i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT / 2, Color565::White);
-    }
-}
-
-void Game::drawPoint(int axis, double value) {
-    if (value < -1.0)
-        value = -1.0;
-
-    if (value > 1.0)
-        value = 1.0;
-
-    value += 1.0;
-    value /= 2.0;
-    value = 1.0 - value;
-    value *= Game::GRAPH_HEIGHT;
-
-    this->disp.setPixel(this->graphX, axis * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + (int)value, this->colors[axis]);
-}
-
-void Game::checkGraphReset() {
-    if (this->graphX > disp.getWidth()) {
-        this->graphX = 0;
-        this->disp.clearScreen();
-        this->drawAxes();
-    }
-}
-
 void Game::initialize() {
     this->disp.setOrientation(LCD_ST7735::Rotate270, false);    
     this->disp.clearScreen();
@@ -154,47 +114,20 @@
     int tcount = 0;
     this->checkButtons();
     
-    if (this->mode) {
-        if ((tcount++ % 10) == 0) {
-          this->readAccel();
-        };
-        this->updateBall();
-        this->checkCollision();
-        this->clearBall();
-        this->drawBall();
-        // this->checkPwm();
-        //this->checkLives(); 
-    }
-    else {    
-        double x, y, z;
-        
-        this->getXYZ(x, y, z);
-        
-        this->checkGraphReset();
-        this->drawPoint(0, x);
-        this->drawPoint(1, y);
-        this->drawPoint(2, z);
-        this->graphX++;
-    } 
+    if ((tcount++ % 10) == 0) {
+        this->readAccel();
+    };
+    this->clearBall();
+    this->updateBall();
+    this->checkCollision();
+    this->drawBall();
+    //this->checkPwm();
+    //this->checkLives(); 
 }
 
 void Game::checkButtons() {
     if (!this->square.read()) {
-        //this->muted = !this->muted;
-        this->mode = !this->mode;
-        
-        this->disp.clearScreen();
-        
-        if (!this->mode) {
-            this->graphX = 0;
-            
-            this->drawAxes();
-        }
-        
-        //this->led1.write(this->muted);
-        //this->led2.write(!this->muted);
-        //this->led1.write(this->mode);
-        //this->led2.write(!this->mode);
+        this->muted = !this->muted;
     }  
     
     bool xDir = this->ballSpeedX > 0.0;
@@ -246,7 +179,7 @@
                         ballY - BALL_RADIUS,
                         ballX + BALL_RADIUS,
                         ballY + BALL_RADIUS,
-                        Color565::Gray);
+                        Color565::Black);
 }
 
 void Game::drawBall() {
@@ -284,10 +217,10 @@
         this->bounce();
     }
     // Sanity
-    this->printDouble(this->ballSpeedX, 1, 0);
-    this->printDouble(this->ballSpeedY, 1, 8);
-    this->printDouble(this->ballAccelX, 120, 0);
-    this->printDouble(this->ballAccelY, 120, 8);
+    //this->printDouble(this->ballSpeedX, 1, 0);
+    //this->printDouble(this->ballSpeedY, 1, 8);
+    //this->printDouble(this->ballAccelX, 120, 0);
+    //this->printDouble(this->ballAccelY, 120, 8);
 }
 
 void Game::bounce() {
@@ -345,7 +278,6 @@
 */
 
 }
-
 void Game::checkPwm() {
     if (this->pwmTicksLeft == 0) {
          this->pwm.write(0.0);
--- a/Game.h	Sat Feb 28 14:46:09 2015 +0000
+++ b/Game.h	Sat Feb 28 17:39:08 2015 +0000
@@ -12,14 +12,12 @@
     static const char* LIVES;
     static const char* SCORE;
     
-    static const int BALL_RADIUS = 3;
+    static const int BALL_RADIUS = 2;
     static const int BALL_STARTING_SPEED = 3;
     static const int PADDLE_WIDTH = 38;
     static const int PADDLE_HEIGHT = 4;
     static const int PADDLE_SPEED = 5;
     static const int BOUNCE_SOUND_TICKS = 2;
-    static const int GRAPH_HEIGHT = 40;
-    static const int GRAPH_SPACING = 2;
     static const char I2C_ADDR = 0x1C << 1;
 
     static const int CHAR_WIDTH = 8;
@@ -37,8 +35,6 @@
     int pwmTicksLeft;
     int lives;
     int score;
-    int graphX;    
-    bool mode;
     bool lastUp;
     bool lastDown;
     bool muted;
@@ -60,15 +56,10 @@
     void readRegisters(char address, char* buffer, int len);
     int writeRegister(char address, char value);
     void getXY(float& x, float& y);
-    void getXYZ(double& x, double& y, double& z);
 
     double convert(char* buffer);
     void printDouble(double value, int x, int y);
     
-    void drawAxes();
-    void drawPoint(int axis, double value);
-    void checkGraphReset();
-    
     void initialize();
     void initializeBall();