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
BulletS/BulletS.cpp@16:987f72d9bb8f, 2020-05-01 (annotated)
- Committer:
- josh_ohara
- Date:
- Fri May 01 12:56:33 2020 +0000
- Revision:
- 16:987f72d9bb8f
- Parent:
- 15:dde4ce4bf7fe
Ship bullet timer added
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| josh_ohara | 2:c2316b659b97 | 1 | |
| josh_ohara | 11:c174d84e4866 | 2 | #include "BulletS.h" |
| josh_ohara | 2:c2316b659b97 | 3 | |
| josh_ohara | 11:c174d84e4866 | 4 | BulletS::BulletS() |
| josh_ohara | 11:c174d84e4866 | 5 | { |
| josh_ohara | 11:c174d84e4866 | 6 | } |
| josh_ohara | 11:c174d84e4866 | 7 | BulletS::~BulletS() |
| josh_ohara | 11:c174d84e4866 | 8 | { |
| josh_ohara | 11:c174d84e4866 | 9 | } |
| josh_ohara | 11:c174d84e4866 | 10 | |
| josh_ohara | 11:c174d84e4866 | 11 | void BulletS::init() { |
| josh_ohara | 11:c174d84e4866 | 12 | vector<Bullet> bullet_vector; |
| josh_ohara | 15:dde4ce4bf7fe | 13 | Shoot = 1; |
| josh_ohara | 16:987f72d9bb8f | 14 | OldCounter = 0; |
| josh_ohara | 11:c174d84e4866 | 15 | } |
| josh_ohara | 2:c2316b659b97 | 16 | |
| josh_ohara | 11:c174d84e4866 | 17 | void BulletS::render(N5110 &lcd) { |
| josh_ohara | 11:c174d84e4866 | 18 | for (unsigned int i =0; i < bullet_vector.size(); i++) { |
| josh_ohara | 11:c174d84e4866 | 19 | bullet_vector[i].render(lcd); |
| josh_ohara | 11:c174d84e4866 | 20 | } |
| josh_ohara | 11:c174d84e4866 | 21 | } |
| josh_ohara | 2:c2316b659b97 | 22 | |
| josh_ohara | 16:987f72d9bb8f | 23 | void BulletS::update(Gamepad &pad, N5110 &lcd, int shipx, int shipy, int counter) { |
| josh_ohara | 11:c174d84e4866 | 24 | X = shipx; |
| josh_ohara | 11:c174d84e4866 | 25 | Y = shipy; |
| josh_ohara | 16:987f72d9bb8f | 26 | int c = counter; |
| josh_ohara | 16:987f72d9bb8f | 27 | flag_set(c); |
| josh_ohara | 15:dde4ce4bf7fe | 28 | if((pad.A_pressed()==true)&& |
| josh_ohara | 15:dde4ce4bf7fe | 29 | (Shoot == 1)) { |
| josh_ohara | 11:c174d84e4866 | 30 | Bullet new_bullet; |
| josh_ohara | 11:c174d84e4866 | 31 | new_bullet.init(X,Y); |
| josh_ohara | 11:c174d84e4866 | 32 | bullet_vector.push_back(new_bullet); |
| josh_ohara | 15:dde4ce4bf7fe | 33 | Shoot = 0; |
| josh_ohara | 16:987f72d9bb8f | 34 | OldCounter = c; |
| josh_ohara | 11:c174d84e4866 | 35 | } |
| josh_ohara | 14:e88bcf5c0887 | 36 | for (int i = 0; i < bullet_vector.size(); i++) { |
| josh_ohara | 12:be491ab6e742 | 37 | bullet_vector[i].update(pad,lcd); |
| josh_ohara | 11:c174d84e4866 | 38 | } |
| josh_ohara | 14:e88bcf5c0887 | 39 | } |
| josh_ohara | 14:e88bcf5c0887 | 40 | |
| josh_ohara | 14:e88bcf5c0887 | 41 | vector<Bullet> BulletS::get_vector() |
| josh_ohara | 14:e88bcf5c0887 | 42 | { |
| josh_ohara | 14:e88bcf5c0887 | 43 | vector<Bullet> v = bullet_vector; |
| josh_ohara | 14:e88bcf5c0887 | 44 | return v; |
| josh_ohara | 14:e88bcf5c0887 | 45 | } |
| josh_ohara | 14:e88bcf5c0887 | 46 | |
| josh_ohara | 14:e88bcf5c0887 | 47 | void BulletS::set_hit(int i, bool x) |
| josh_ohara | 14:e88bcf5c0887 | 48 | { |
| josh_ohara | 14:e88bcf5c0887 | 49 | bullet_vector[i].set_hit(x); |
| josh_ohara | 14:e88bcf5c0887 | 50 | } |
| josh_ohara | 15:dde4ce4bf7fe | 51 | |
| josh_ohara | 16:987f72d9bb8f | 52 | void BulletS::flag_set(int counter) |
| josh_ohara | 15:dde4ce4bf7fe | 53 | { |
| josh_ohara | 16:987f72d9bb8f | 54 | int flag_counter = counter; |
| josh_ohara | 16:987f72d9bb8f | 55 | if (OldCounter + 6 <= flag_counter) { |
| josh_ohara | 16:987f72d9bb8f | 56 | Shoot = 1; |
| josh_ohara | 16:987f72d9bb8f | 57 | } |
| josh_ohara | 15:dde4ce4bf7fe | 58 | } |
| josh_ohara | 15:dde4ce4bf7fe | 59 |