Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RETRO_Pong_Mod by
Game.h@5:8a26ad9d9ea1, 2015-02-25 (annotated)
- Committer:
- loop
- Date:
- Wed Feb 25 23:28:49 2015 +0000
- Revision:
- 5:8a26ad9d9ea1
- Parent:
- 4:84be90860d7c
- Child:
- 7:c0f12f624832
First try at reading accelerometer
Who changed what in which revision?
User | Revision | Line number | New 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 | |
loop | 4:84be90860d7c | 25 | // Start with a ball.. let's see what becomes |
john_ghielec | 1:cd8a3926f263 | 26 | int ballX; |
john_ghielec | 1:cd8a3926f263 | 27 | int ballY; |
john_ghielec | 1:cd8a3926f263 | 28 | int ballSpeedX; |
john_ghielec | 1:cd8a3926f263 | 29 | int ballSpeedY; |
loop | 4:84be90860d7c | 30 | int ballAccelX; |
loop | 4:84be90860d7c | 31 | int ballAccelY; |
john_ghielec | 1:cd8a3926f263 | 32 | int pwmTicksLeft; |
john_ghielec | 1:cd8a3926f263 | 33 | int lives; |
devhammer | 3:2f09c90a732d | 34 | int score; |
john_ghielec | 2:6ab46f2e851a | 35 | int graphX; |
john_ghielec | 2:6ab46f2e851a | 36 | bool mode; |
john_ghielec | 2:6ab46f2e851a | 37 | bool lastUp; |
john_ghielec | 2:6ab46f2e851a | 38 | bool lastDown; |
devhammer | 3:2f09c90a732d | 39 | bool muted; |
john_ghielec | 2:6ab46f2e851a | 40 | unsigned short colors[3]; |
john_ghielec | 2:6ab46f2e851a | 41 | |
john_ghielec | 1:cd8a3926f263 | 42 | DigitalIn left; |
john_ghielec | 1:cd8a3926f263 | 43 | DigitalIn right; |
john_ghielec | 1:cd8a3926f263 | 44 | DigitalIn down; |
john_ghielec | 1:cd8a3926f263 | 45 | DigitalIn up; |
john_ghielec | 1:cd8a3926f263 | 46 | DigitalIn square; |
john_ghielec | 1:cd8a3926f263 | 47 | DigitalIn circle; |
john_ghielec | 1:cd8a3926f263 | 48 | DigitalOut led1; |
john_ghielec | 1:cd8a3926f263 | 49 | DigitalOut led2; |
john_ghielec | 1:cd8a3926f263 | 50 | PwmOut pwm; |
john_ghielec | 1:cd8a3926f263 | 51 | AnalogIn ain; |
john_ghielec | 1:cd8a3926f263 | 52 | I2C i2c; |
john_ghielec | 1:cd8a3926f263 | 53 | DisplayN18 disp; |
john_ghielec | 1:cd8a3926f263 | 54 | |
john_ghielec | 2:6ab46f2e851a | 55 | void readRegisters(char address, char* buffer, int len); |
john_ghielec | 2:6ab46f2e851a | 56 | int writeRegister(char address, char value); |
john_ghielec | 2:6ab46f2e851a | 57 | void getXYZ(double& x, double& y, double& z); |
john_ghielec | 2:6ab46f2e851a | 58 | double convert(char* buffer); |
john_ghielec | 2:6ab46f2e851a | 59 | void printDouble(double value, int x, int y); |
john_ghielec | 2:6ab46f2e851a | 60 | |
john_ghielec | 2:6ab46f2e851a | 61 | void drawAxes(); |
john_ghielec | 2:6ab46f2e851a | 62 | void drawPoint(int axis, double value); |
john_ghielec | 2:6ab46f2e851a | 63 | void checkGraphReset(); |
john_ghielec | 2:6ab46f2e851a | 64 | |
john_ghielec | 1:cd8a3926f263 | 65 | void initialize(); |
john_ghielec | 1:cd8a3926f263 | 66 | void initializeBall(); |
john_ghielec | 1:cd8a3926f263 | 67 | |
john_ghielec | 1:cd8a3926f263 | 68 | void drawString(const char* str, int y); |
john_ghielec | 1:cd8a3926f263 | 69 | |
john_ghielec | 1:cd8a3926f263 | 70 | void clearBall(); |
john_ghielec | 1:cd8a3926f263 | 71 | void drawBall(); |
john_ghielec | 1:cd8a3926f263 | 72 | void updateBall(); |
loop | 5:8a26ad9d9ea1 | 73 | void readAccel(); |
john_ghielec | 2:6ab46f2e851a | 74 | void checkButtons(); |
john_ghielec | 1:cd8a3926f263 | 75 | void checkCollision(); |
john_ghielec | 1:cd8a3926f263 | 76 | void checkPwm(); |
john_ghielec | 1:cd8a3926f263 | 77 | void checkLives(); |
john_ghielec | 1:cd8a3926f263 | 78 | |
john_ghielec | 1:cd8a3926f263 | 79 | public: |
john_ghielec | 1:cd8a3926f263 | 80 | Game(); |
john_ghielec | 1:cd8a3926f263 | 81 | |
john_ghielec | 1:cd8a3926f263 | 82 | void showSplashScreen(); |
john_ghielec | 1:cd8a3926f263 | 83 | void tick(); |
john_ghielec | 1:cd8a3926f263 | 84 | }; |