Stephen Ralph / Mbed 2 deprecated Asteroids

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ConcreteAsteroid1.cpp Source File

ConcreteAsteroid1.cpp

00001 #include "uLCD_4DGL.h"
00002 #include "ConcreteAsteroid1.h"
00003 #include "AbsAst.h"
00004 #include <math.h>
00005 extern int asteroid_sprite_1;
00006 extern uLCD_4DGL uLCD;
00007 
00008 #define ASTEROID_HEIGHT 12
00009 #define ASTEROID_WIDTH 15
00010 #define SPRITE_MAX 15
00011 #define SCREEN_MAX 125
00012 #define SCREEN_MIN 1
00013 #define NUM_ASTEROIDS 4
00014 
00015 
00016 ConcreteAsteroid1::ConcreteAsteroid1(){
00017     //START IN RANDOM XPOS AND ZERO YPOS
00018     xpos = (rand() % SCREEN_MAX );
00019     ypos = 0;
00020     //VELOCITY VECTOR, X VECTOR IS -5 TO +5, Y VECTOR IS 1-11
00021     dx = (rand() % 10) - 5;
00022     dy = (rand() % 10 +1);
00023 }
00024 
00025 void ConcreteAsteroid1::draw(){
00026         uLCD.BLIT(xpos, ypos, ASTEROID_WIDTH, ASTEROID_HEIGHT, &asteroid_sprite_1);
00027     }
00028     
00029 // MOVE BY ONE UNIT OF THE VELOCITY VECTOR
00030 void ConcreteAsteroid1::update(){
00031      xpos= xpos + dx;
00032      ypos = ypos + dy;
00033 }