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

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

ConcreteAsteroid3.cpp

Committer:
sralph3
Date:
2019-01-03
Revision:
8:137330cfe63d
Parent:
0:f2cc64948895

File content as of revision 8:137330cfe63d:

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

extern int asteroid_sprite_3;
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

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

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