ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed Apr 24 10:33:39 2019 +0000
Revision:
16:e0542761fc8c
Child:
17:74de8c17ddac
I added another folder for the bullets the doodler can fire controlled by the Y button. I created three bullets and once they reach the end of the screen they will go back and remain at the doodler's position.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 16:e0542761fc8c 1 #include "Bullet.h"
el17m2h 16:e0542761fc8c 2 Bullet::Bullet(){
el17m2h 16:e0542761fc8c 3 }
el17m2h 16:e0542761fc8c 4 Bullet::~Bullet(){
el17m2h 16:e0542761fc8c 5 }
el17m2h 16:e0542761fc8c 6
el17m2h 16:e0542761fc8c 7 void Bullet::init(float dood_position_x, float dood_position_y){
el17m2h 16:e0542761fc8c 8 _radius = 1;
el17m2h 16:e0542761fc8c 9 _position_x = dood_position_x; // initially in same position as doodler
el17m2h 16:e0542761fc8c 10 _position_y = dood_position_y;
el17m2h 16:e0542761fc8c 11 }
el17m2h 16:e0542761fc8c 12
el17m2h 16:e0542761fc8c 13 void Bullet::draw(N5110 &lcd){
el17m2h 16:e0542761fc8c 14 lcd.drawCircle(_position_x, _position_y, _radius, FILL_BLACK);
el17m2h 16:e0542761fc8c 15 }
el17m2h 16:e0542761fc8c 16
el17m2h 16:e0542761fc8c 17 void Bullet::update(float dood_position_x, float dood_position_y, bool button_Y){
el17m2h 16:e0542761fc8c 18 _position_x = get_position_x();
el17m2h 16:e0542761fc8c 19 _position_y = get_position_y();
el17m2h 16:e0542761fc8c 20 if (button_Y == true){
el17m2h 16:e0542761fc8c 21 _position_y -= 2; // moves upwards
el17m2h 16:e0542761fc8c 22 }
el17m2h 16:e0542761fc8c 23 if (_position_y < 0){ // checking it leaves screen
el17m2h 16:e0542761fc8c 24 _position_x =dood_position_x;
el17m2h 16:e0542761fc8c 25 _position_y =dood_position_y;
el17m2h 16:e0542761fc8c 26 }
el17m2h 16:e0542761fc8c 27 }
el17m2h 16:e0542761fc8c 28
el17m2h 16:e0542761fc8c 29 float Bullet::get_position_x(){
el17m2h 16:e0542761fc8c 30 float p_x = _position_x;
el17m2h 16:e0542761fc8c 31 return p_x;
el17m2h 16:e0542761fc8c 32 }
el17m2h 16:e0542761fc8c 33
el17m2h 16:e0542761fc8c 34 float Bullet::get_position_y(){
el17m2h 16:e0542761fc8c 35 float p_y = _position_y;
el17m2h 16:e0542761fc8c 36 return p_y;
el17m2h 16:e0542761fc8c 37 }
el17m2h 16:e0542761fc8c 38
el17m2h 16:e0542761fc8c 39 float Bullet::get_velocity_x(){
el17m2h 16:e0542761fc8c 40 float v_x = _velocity_x;
el17m2h 16:e0542761fc8c 41 return v_x;
el17m2h 16:e0542761fc8c 42 }
el17m2h 16:e0542761fc8c 43
el17m2h 16:e0542761fc8c 44 double Bullet::get_velocity_y(){
el17m2h 16:e0542761fc8c 45 double v_y = (double)_velocity_y;
el17m2h 16:e0542761fc8c 46 return (double)v_y;
el17m2h 16:e0542761fc8c 47 }
el17m2h 16:e0542761fc8c 48
el17m2h 16:e0542761fc8c 49 void Bullet::set_velocity(float vel_x, double vel_y){
el17m2h 16:e0542761fc8c 50 _velocity_x = vel_x;
el17m2h 16:e0542761fc8c 51 _velocity_y = (double)vel_y;
el17m2h 16:e0542761fc8c 52 }
el17m2h 16:e0542761fc8c 53
el17m2h 16:e0542761fc8c 54 void Bullet::set_position(float pos_x, float pos_y){
el17m2h 16:e0542761fc8c 55 _position_x = pos_x;
el17m2h 16:e0542761fc8c 56 _position_y = pos_y;
el17m2h 16:e0542761fc8c 57 }
el17m2h 16:e0542761fc8c 58