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

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

ConcreteAsteroid4.cpp

Committer:
sralph3
Date:
2019-01-03
Revision:
8:137330cfe63d
Parent:
1:79577bd1e4cb

File content as of revision 8:137330cfe63d:

#include "uLCD_4DGL.h"
#include "ConcreteAsteroid4.h"
#include "AbsAst.h"
#include <math.h>

extern int asteroid_sprite_4;
extern uLCD_4DGL uLCD;

#define ASTEROID_HEIGHT 12
#define ASTEROID_WIDTH 15
#define SPRITE_MAX 15
#define SCREEN_MAX 125
#define SCREEN_MIN 1
#define NUM_ASTEROIDS 4

ConcreteAsteroid4::ConcreteAsteroid4(){
    //START IN RANDOM YPOS AND ZERO XPOS
    xpos = 0;
    ypos = (rand() % SCREEN_MAX );;
    //VELOCITY VECTOR, Y VECTOR IS -5 TO +5, X VECTOR IS 1 TO 11
    dx = (rand() % 10) +1 ;
    dy = (rand() % 10 -5);
}

void ConcreteAsteroid4::draw(){
        uLCD.BLIT(xpos, ypos, ASTEROID_WIDTH, ASTEROID_HEIGHT, &asteroid_sprite_4);
    }
    
// MOVE BY ONE UNIT OF THE VELOCITY VECTOR
void ConcreteAsteroid4::update(){
     xpos= xpos + dx;
     ypos = ypos + dy;
}