Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of fy15raf by
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 }
Generated on Thu Jul 14 2022 18:15:41 by
