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.
Dependencies: mbed
Bullet.cpp
00001 #include "Bullet.h" 00002 00003 00004 void Bullet::init(int x,int size,int speed,int height) 00005 { 00006 _size = size; 00007 00008 _x = 24; 00009 _y = 28; 00010 00011 srand(time(NULL)); 00012 int direction = rand() % 2; // randomise initial direction. 00013 00014 // 4 possibilities. Get random modulo and set velocities accordingly 00015 if (direction == 0) { 00016 _velocity.x = speed; 00017 _velocity.y = -speed; 00018 } else if (direction == 1) { 00019 _velocity.x = -speed; 00020 _velocity.y = -speed; 00021 } 00022 } 00023 00024 void Bullet::draw(N5110 &lcd) 00025 { 00026 lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); 00027 /* if((_y >= 0)&&(_y <= 24)) 00028 { 00029 X=_x; 00030 Y=_y; 00031 00032 } 00033 lcd.clearPixel(_x,_y);*/ 00034 } 00035 00036 void Bullet::update(N5110 &lcd) 00037 { 00038 _x += _velocity.x; 00039 _y += _velocity.y; 00040 /* if(( _y >= 0)&&( _y <= 24)) 00041 { 00042 00043 // lcd.clearPixel(_x,_y-1); 00044 X=_x; 00045 Y=_y; 00046 } 00047 lcd.clearPixel(X,Y-1);*/ 00048 } 00049 00050 void Bullet::set_velocity(Vector2D v) 00051 { 00052 _velocity.x = v.x; 00053 _velocity.y = v.y; 00054 } 00055 00056 Vector2D Bullet::get_velocity() 00057 { 00058 Vector2D v = {_velocity.x,_velocity.y}; 00059 return v; 00060 } 00061 00062 Vector2D Bullet::get_pos() 00063 { 00064 Vector2D p = {_x,_y}; 00065 return p; 00066 } 00067 00068 void Bullet::set_pos(Vector2D p) 00069 { 00070 _x = p.x; 00071 _y = p.y; 00072 }
Generated on Wed Jul 13 2022 04:23:58 by
1.7.2