Reham Faqehi / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Fork of fy15raf by ELEC2645 (2017/18)

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Asteroid.cpp Source File

Asteroid.cpp

00001 #include "Asteroid.h"
00002 
00003 Asteroid::Asteroid()
00004 {
00005 
00006 }
00007 
00008 Asteroid::~Asteroid()
00009 {
00010 
00011 }
00012 
00013 void Asteroid::init(float speed)
00014 {
00015     //initialise the Asteroid position, speed and size
00016     _size = 5;
00017 
00018     _x = WIDTH - _size;
00019     _y1 = rand()%(HEIGHT); // random initial position on y-axis.
00020 
00021     _velocity.x = speed;
00022 }
00023 
00024 void Asteroid::draw(N5110 &lcd)
00025 {
00026 
00027     int sprite[6][11] =   {
00028 
00029 
00030         { 0,0,1,1,0,1,0,0,1,1,0, },
00031         { 0,1,1,1,1,1,1,0,0,0,0, },
00032         { 1,1,0,1,1,1,0,1,0,0,0, },
00033         { 1,1,1,1,1,1,1,1,0,1,1, },
00034         { 0,1,1,1,0,1,1,0,0,0,0, },
00035         { 0,0,0,1,1,1,0,0,1,1,0, },
00036 
00037     };
00038     lcd.drawSprite(_x,_y1,6,11,(int *)sprite);
00039 }
00040 
00041 void Asteroid::update()
00042 {
00043     if(_x>0) {
00044         _x -= _velocity.x;
00045     } else {
00046         _x = WIDTH - _size;      //start from the begining again
00047         _y1= rand()%(HEIGHT-6);    // with random position on y-axis.
00048     }
00049 }
00050 
00051 Vector2D Asteroid::get_pos()
00052 {
00053     Vector2D p = {_x,_y1};
00054     return p;
00055 }