harry rance
/
Revised_Space_Invaders
Harry Rance 200925395 Embedded Systems Project
Bullet.cpp@1:95d7dd44bb0d, 2017-04-13 (annotated)
- Committer:
- harryrance
- Date:
- Thu Apr 13 13:30:39 2017 +0000
- Revision:
- 1:95d7dd44bb0d
- Child:
- 2:50feb42b982c
Does all as before, added in bullet firing function, but only one bullet can be fired at this time. WORK ON: generating multiple instances of the bullet in one game.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
harryrance | 1:95d7dd44bb0d | 1 | #include "Bullet.h" |
harryrance | 1:95d7dd44bb0d | 2 | |
harryrance | 1:95d7dd44bb0d | 3 | Bullet::Bullet() |
harryrance | 1:95d7dd44bb0d | 4 | { |
harryrance | 1:95d7dd44bb0d | 5 | |
harryrance | 1:95d7dd44bb0d | 6 | } |
harryrance | 1:95d7dd44bb0d | 7 | |
harryrance | 1:95d7dd44bb0d | 8 | Bullet::~Bullet() |
harryrance | 1:95d7dd44bb0d | 9 | { |
harryrance | 1:95d7dd44bb0d | 10 | |
harryrance | 1:95d7dd44bb0d | 11 | } |
harryrance | 1:95d7dd44bb0d | 12 | |
harryrance | 1:95d7dd44bb0d | 13 | void Bullet::initialise(int x_origin, int y_origin, int speed, int button_check) |
harryrance | 1:95d7dd44bb0d | 14 | { |
harryrance | 1:95d7dd44bb0d | 15 | _x = x_origin; |
harryrance | 1:95d7dd44bb0d | 16 | _y = y_origin; |
harryrance | 1:95d7dd44bb0d | 17 | _button_check = button_check; |
harryrance | 1:95d7dd44bb0d | 18 | _speed = speed; |
harryrance | 1:95d7dd44bb0d | 19 | |
harryrance | 1:95d7dd44bb0d | 20 | } |
harryrance | 1:95d7dd44bb0d | 21 | |
harryrance | 1:95d7dd44bb0d | 22 | void Bullet::check_button_press(Gamepad &pad) |
harryrance | 1:95d7dd44bb0d | 23 | { |
harryrance | 1:95d7dd44bb0d | 24 | if (pad.check_event(Gamepad::A_PRESSED)){ |
harryrance | 1:95d7dd44bb0d | 25 | _button_check = 1; |
harryrance | 1:95d7dd44bb0d | 26 | _speed = 1; |
harryrance | 1:95d7dd44bb0d | 27 | } |
harryrance | 1:95d7dd44bb0d | 28 | } |
harryrance | 1:95d7dd44bb0d | 29 | |
harryrance | 1:95d7dd44bb0d | 30 | void Bullet::draw(N5110 &lcd) |
harryrance | 1:95d7dd44bb0d | 31 | { |
harryrance | 1:95d7dd44bb0d | 32 | _y_origin = _y; |
harryrance | 1:95d7dd44bb0d | 33 | _x_origin = _x; |
harryrance | 1:95d7dd44bb0d | 34 | |
harryrance | 1:95d7dd44bb0d | 35 | if (_button_check){ |
harryrance | 1:95d7dd44bb0d | 36 | lcd.setPixel(_x_origin,_y_origin); |
harryrance | 1:95d7dd44bb0d | 37 | lcd.setPixel(_x_origin,_y_origin-1); |
harryrance | 1:95d7dd44bb0d | 38 | } |
harryrance | 1:95d7dd44bb0d | 39 | } |
harryrance | 1:95d7dd44bb0d | 40 | |
harryrance | 1:95d7dd44bb0d | 41 | void Bullet::update() |
harryrance | 1:95d7dd44bb0d | 42 | { |
harryrance | 1:95d7dd44bb0d | 43 | _x += _velocity.x; |
harryrance | 1:95d7dd44bb0d | 44 | _y -= _velocity.y; |
harryrance | 1:95d7dd44bb0d | 45 | |
harryrance | 1:95d7dd44bb0d | 46 | int direction = 0; |
harryrance | 1:95d7dd44bb0d | 47 | |
harryrance | 1:95d7dd44bb0d | 48 | if(direction == 0) |
harryrance | 1:95d7dd44bb0d | 49 | { |
harryrance | 1:95d7dd44bb0d | 50 | _velocity.y = _speed; |
harryrance | 1:95d7dd44bb0d | 51 | } |
harryrance | 1:95d7dd44bb0d | 52 | } |
harryrance | 1:95d7dd44bb0d | 53 | |
harryrance | 1:95d7dd44bb0d | 54 | void Bullet::set_velocity(Vector2D v) |
harryrance | 1:95d7dd44bb0d | 55 | { |
harryrance | 1:95d7dd44bb0d | 56 | _velocity.x = v.x; |
harryrance | 1:95d7dd44bb0d | 57 | _velocity.y = v.y; |
harryrance | 1:95d7dd44bb0d | 58 | } |
harryrance | 1:95d7dd44bb0d | 59 | |
harryrance | 1:95d7dd44bb0d | 60 | void Bullet::set_position(Vector2D p) |
harryrance | 1:95d7dd44bb0d | 61 | { |
harryrance | 1:95d7dd44bb0d | 62 | _x = p.x; |
harryrance | 1:95d7dd44bb0d | 63 | _y = p.y; |
harryrance | 1:95d7dd44bb0d | 64 | } |
harryrance | 1:95d7dd44bb0d | 65 | |
harryrance | 1:95d7dd44bb0d | 66 | Vector2D Bullet::get_velocity() |
harryrance | 1:95d7dd44bb0d | 67 | { |
harryrance | 1:95d7dd44bb0d | 68 | Vector2D v = {_velocity.x,_velocity.y}; |
harryrance | 1:95d7dd44bb0d | 69 | |
harryrance | 1:95d7dd44bb0d | 70 | return v; |
harryrance | 1:95d7dd44bb0d | 71 | } |
harryrance | 1:95d7dd44bb0d | 72 | |
harryrance | 1:95d7dd44bb0d | 73 | Vector2D Bullet::get_position() |
harryrance | 1:95d7dd44bb0d | 74 | { |
harryrance | 1:95d7dd44bb0d | 75 | Vector2D p = {_x,_y}; |
harryrance | 1:95d7dd44bb0d | 76 | |
harryrance | 1:95d7dd44bb0d | 77 | return p; |
harryrance | 1:95d7dd44bb0d | 78 | } |
harryrance | 1:95d7dd44bb0d | 79 |