harry rance
/
Revised_Space_Invaders
Harry Rance 200925395 Embedded Systems Project
Diff: Bullet.cpp
- Revision:
- 1:95d7dd44bb0d
- Child:
- 2:50feb42b982c
diff -r c9bf674fe0c7 -r 95d7dd44bb0d Bullet.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bullet.cpp Thu Apr 13 13:30:39 2017 +0000 @@ -0,0 +1,79 @@ +#include "Bullet.h" + +Bullet::Bullet() +{ + +} + +Bullet::~Bullet() +{ + +} + +void Bullet::initialise(int x_origin, int y_origin, int speed, int button_check) +{ + _x = x_origin; + _y = y_origin; + _button_check = button_check; + _speed = speed; + +} + +void Bullet::check_button_press(Gamepad &pad) +{ + if (pad.check_event(Gamepad::A_PRESSED)){ + _button_check = 1; + _speed = 1; + } +} + +void Bullet::draw(N5110 &lcd) +{ + _y_origin = _y; + _x_origin = _x; + + if (_button_check){ + lcd.setPixel(_x_origin,_y_origin); + lcd.setPixel(_x_origin,_y_origin-1); + } +} + +void Bullet::update() +{ + _x += _velocity.x; + _y -= _velocity.y; + + int direction = 0; + + if(direction == 0) + { + _velocity.y = _speed; + } +} + +void Bullet::set_velocity(Vector2D v) +{ + _velocity.x = v.x; + _velocity.y = v.y; +} + +void Bullet::set_position(Vector2D p) +{ + _x = p.x; + _y = p.y; +} + +Vector2D Bullet::get_velocity() +{ + Vector2D v = {_velocity.x,_velocity.y}; + + return v; +} + +Vector2D Bullet::get_position() +{ + Vector2D p = {_x,_y}; + + return p; +} +