A simple asteroids-like game utilizing various Mbed-compatible sensors

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

Committer:
sralph3
Date:
Thu Jan 03 19:56:27 2019 +0000
Revision:
8:137330cfe63d
Parent:
1:79577bd1e4cb
Jan 3, 2019

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sralph3 0:f2cc64948895 1 #include "uLCD_4DGL.h"
sralph3 0:f2cc64948895 2 #include "ConcreteAsteroid4.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_4;
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 ConcreteAsteroid4::ConcreteAsteroid4(){
sralph3 0:f2cc64948895 17 //START IN RANDOM YPOS AND ZERO XPOS
sralph3 0:f2cc64948895 18 xpos = 0;
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) +1 ;
sralph3 0:f2cc64948895 22 dy = (rand() % 10 -5);
sralph3 0:f2cc64948895 23 }
sralph3 0:f2cc64948895 24
sralph3 0:f2cc64948895 25 void ConcreteAsteroid4::draw(){
sralph3 0:f2cc64948895 26 uLCD.BLIT(xpos, ypos, ASTEROID_WIDTH, ASTEROID_HEIGHT, &asteroid_sprite_4);
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 ConcreteAsteroid4::update(){
sralph3 0:f2cc64948895 31 xpos= xpos + dx;
sralph3 0:f2cc64948895 32 ypos = ypos + dy;
sralph3 0:f2cc64948895 33 }