A simple asteroids-like game utilizing various Mbed-compatible sensors
Dependencies: mbed 4DGL-uLCD-SE PinDetect
ConcreteAsteroid3.cpp@0:f2cc64948895, 2018-11-30 (annotated)
- Committer:
- sralph3
- Date:
- Fri Nov 30 04:49:11 2018 +0000
- Revision:
- 0:f2cc64948895
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sralph3 | 0:f2cc64948895 | 1 | #include "uLCD_4DGL.h" |
sralph3 | 0:f2cc64948895 | 2 | #include "ConcreteAsteroid3.h" |
sralph3 | 0:f2cc64948895 | 3 | #include "AbsAst.h" |
sralph3 | 0:f2cc64948895 | 4 | #include <math.h> |
sralph3 | 0:f2cc64948895 | 5 | |
sralph3 | 0:f2cc64948895 | 6 | extern int asteroid_sprite_3; |
sralph3 | 0:f2cc64948895 | 7 | extern uLCD_4DGL uLCD; |
sralph3 | 0:f2cc64948895 | 8 | |
sralph3 | 0:f2cc64948895 | 9 | #define ASTEROID_HEIGHT 12 |
sralph3 | 0:f2cc64948895 | 10 | #define ASTEROID_WIDTH 15 |
sralph3 | 0:f2cc64948895 | 11 | #define SPRITE_MAX 15 |
sralph3 | 0:f2cc64948895 | 12 | #define SCREEN_MAX 125 |
sralph3 | 0:f2cc64948895 | 13 | #define SCREEN_MIN 1 |
sralph3 | 0:f2cc64948895 | 14 | #define NUM_ASTEROIDS 4 |
sralph3 | 0:f2cc64948895 | 15 | |
sralph3 | 0:f2cc64948895 | 16 | ConcreteAsteroid3::ConcreteAsteroid3(){ |
sralph3 | 0:f2cc64948895 | 17 | //START IN RANDOM YPOS AND MAX XPOS |
sralph3 | 0:f2cc64948895 | 18 | xpos = SCREEN_MAX; |
sralph3 | 0:f2cc64948895 | 19 | ypos = (rand() % SCREEN_MAX ); |
sralph3 | 0:f2cc64948895 | 20 | //VELOCITY VECTOR, Y VECTOR IS -5 TO +5, X VECTOR IS -1 TO -11 |
sralph3 | 0:f2cc64948895 | 21 | dx = (rand() % 10) - 11; |
sralph3 | 0:f2cc64948895 | 22 | dy = (rand() % 10 -5); |
sralph3 | 0:f2cc64948895 | 23 | } |
sralph3 | 0:f2cc64948895 | 24 | |
sralph3 | 0:f2cc64948895 | 25 | void ConcreteAsteroid3::draw(){ |
sralph3 | 0:f2cc64948895 | 26 | uLCD.BLIT(xpos, ypos, ASTEROID_WIDTH, ASTEROID_HEIGHT, &asteroid_sprite_3); |
sralph3 | 0:f2cc64948895 | 27 | } |
sralph3 | 0:f2cc64948895 | 28 | |
sralph3 | 0:f2cc64948895 | 29 | // MOVE BY ONE UNIT OF THE VELOCITY VECTOR |
sralph3 | 0:f2cc64948895 | 30 | void ConcreteAsteroid3::update(){ |
sralph3 | 0:f2cc64948895 | 31 | xpos= xpos + dx; |
sralph3 | 0:f2cc64948895 | 32 | ypos = ypos + dy; |
sralph3 | 0:f2cc64948895 | 33 | } |