Some random attempts at programming the retro console

Dependencies:   LCD_ST7735 mbed

Fork of RETRO_Pong_Mod by G. Andrew Duthie

Committer:
loop
Date:
Sat Feb 28 00:04:52 2015 +0000
Revision:
8:c63981a45c95
Parent:
7:c0f12f624832
Child:
9:5c4a3e89a713
Brought in MusicEngine

Who changed what in which revision?

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