
Joshua O'hara 201291390
Dependencies: mbed
AlienBulletVector/AlienBulletVector.cpp@44:3b904d25ee12, 2020-05-26 (annotated)
- Committer:
- josh_ohara
- Date:
- Tue May 26 15:15:46 2020 +0000
- Revision:
- 44:3b904d25ee12
- Parent:
- 43:1ac200335a68
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
josh_ohara | 42:816e444e660b | 1 | #include "AlienBulletVector.h" |
josh_ohara | 42:816e444e660b | 2 | |
josh_ohara | 42:816e444e660b | 3 | AlienBulletVector::AlienBulletVector() |
josh_ohara | 42:816e444e660b | 4 | { |
josh_ohara | 42:816e444e660b | 5 | } |
josh_ohara | 42:816e444e660b | 6 | |
josh_ohara | 42:816e444e660b | 7 | AlienBulletVector::~AlienBulletVector() |
josh_ohara | 42:816e444e660b | 8 | { |
josh_ohara | 42:816e444e660b | 9 | } |
josh_ohara | 42:816e444e660b | 10 | |
josh_ohara | 42:816e444e660b | 11 | void AlienBulletVector::init() //set x and y position to 0 until set by update function |
josh_ohara | 42:816e444e660b | 12 | { |
josh_ohara | 42:816e444e660b | 13 | _x = 0; |
josh_ohara | 42:816e444e660b | 14 | _y = 0; |
josh_ohara | 42:816e444e660b | 15 | } |
josh_ohara | 42:816e444e660b | 16 | |
josh_ohara | 42:816e444e660b | 17 | void AlienBulletVector::render(N5110 &lcd) |
josh_ohara | 42:816e444e660b | 18 | { |
josh_ohara | 42:816e444e660b | 19 | for (int i = 0; i < _alien_bullet_vector.size(); i++) { //draw all bullets in the bullet vector |
josh_ohara | 42:816e444e660b | 20 | _alien_bullet_vector[i].render(lcd); |
josh_ohara | 42:816e444e660b | 21 | } |
josh_ohara | 42:816e444e660b | 22 | } |
josh_ohara | 42:816e444e660b | 23 | |
josh_ohara | 42:816e444e660b | 24 | void AlienBulletVector::update(int alien_x, int alien_y, bool shoot) |
josh_ohara | 42:816e444e660b | 25 | { |
josh_ohara | 42:816e444e660b | 26 | _x = alien_x; //set x and y of new bullet to x and y of ship |
josh_ohara | 42:816e444e660b | 27 | _y = alien_y; |
josh_ohara | 42:816e444e660b | 28 | bool shoot_ = shoot; //copy shoot for use inside function |
josh_ohara | 42:816e444e660b | 29 | |
josh_ohara | 42:816e444e660b | 30 | if(shoot_ == true) { //if shoot flg is set, add new bullet to the vector, initilise this bullet |
josh_ohara | 42:816e444e660b | 31 | AlienBullet new_bullet; |
josh_ohara | 42:816e444e660b | 32 | new_bullet.init(_x,_y); |
josh_ohara | 42:816e444e660b | 33 | _alien_bullet_vector.push_back(new_bullet); |
josh_ohara | 43:1ac200335a68 | 34 | //printf("new bullet added"); |
josh_ohara | 42:816e444e660b | 35 | } |
josh_ohara | 42:816e444e660b | 36 | |
josh_ohara | 42:816e444e660b | 37 | for (int i = 0; i < _alien_bullet_vector.size(); i++) { //update the bullets in the vector |
josh_ohara | 42:816e444e660b | 38 | _alien_bullet_vector[i].update(); |
josh_ohara | 42:816e444e660b | 39 | } |
josh_ohara | 42:816e444e660b | 40 | } |
josh_ohara | 42:816e444e660b | 41 | |
josh_ohara | 42:816e444e660b | 42 | vector<AlienBullet> AlienBulletVector::get_vector() |
josh_ohara | 42:816e444e660b | 43 | { |
josh_ohara | 42:816e444e660b | 44 | vector<AlienBullet> v = _alien_bullet_vector; |
josh_ohara | 42:816e444e660b | 45 | return v; //return a copy of the bullet vector |
josh_ohara | 42:816e444e660b | 46 | } |
josh_ohara | 42:816e444e660b | 47 | |
josh_ohara | 42:816e444e660b | 48 | void AlienBulletVector::set_hit(int i, bool x) |
josh_ohara | 42:816e444e660b | 49 | { |
josh_ohara | 42:816e444e660b | 50 | _alien_bullet_vector[i].set_hit(x); //set hit value of bullet i in the vector of bullets |
josh_ohara | 42:816e444e660b | 51 | } |