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@15:dde4ce4bf7fe, 2020-04-06 (annotated)
- Committer:
- josh_ohara
- Date:
- Mon Apr 06 15:37:02 2020 +0000
- Revision:
- 15:dde4ce4bf7fe
- Parent:
- 14:e88bcf5c0887
- Child:
- 16:987f72d9bb8f
Cover for ship completed. Next task is to add timeout to the ship bullet
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 | 11:c174d84e4866 | 14 | } |
| josh_ohara | 2:c2316b659b97 | 15 | |
| josh_ohara | 11:c174d84e4866 | 16 | void BulletS::render(N5110 &lcd) { |
| josh_ohara | 11:c174d84e4866 | 17 | for (unsigned int i =0; i < bullet_vector.size(); i++) { |
| josh_ohara | 11:c174d84e4866 | 18 | bullet_vector[i].render(lcd); |
| josh_ohara | 11:c174d84e4866 | 19 | } |
| josh_ohara | 11:c174d84e4866 | 20 | } |
| josh_ohara | 2:c2316b659b97 | 21 | |
| josh_ohara | 12:be491ab6e742 | 22 | void BulletS::update(Gamepad &pad, N5110 &lcd, int shipx, int shipy) { |
| josh_ohara | 11:c174d84e4866 | 23 | X = shipx; |
| josh_ohara | 11:c174d84e4866 | 24 | Y = shipy; |
| josh_ohara | 15:dde4ce4bf7fe | 25 | ticker.attach(this,&BulletS::flag_set,0.5); |
| josh_ohara | 15:dde4ce4bf7fe | 26 | if((pad.A_pressed()==true)&& |
| josh_ohara | 15:dde4ce4bf7fe | 27 | (Shoot == 1)) { |
| josh_ohara | 11:c174d84e4866 | 28 | Bullet new_bullet; |
| josh_ohara | 11:c174d84e4866 | 29 | new_bullet.init(X,Y); |
| josh_ohara | 11:c174d84e4866 | 30 | bullet_vector.push_back(new_bullet); |
| josh_ohara | 15:dde4ce4bf7fe | 31 | Shoot = 0; |
| josh_ohara | 11:c174d84e4866 | 32 | } |
| josh_ohara | 14:e88bcf5c0887 | 33 | for (int i = 0; i < bullet_vector.size(); i++) { |
| josh_ohara | 12:be491ab6e742 | 34 | bullet_vector[i].update(pad,lcd); |
| josh_ohara | 11:c174d84e4866 | 35 | } |
| josh_ohara | 14:e88bcf5c0887 | 36 | } |
| josh_ohara | 14:e88bcf5c0887 | 37 | |
| josh_ohara | 14:e88bcf5c0887 | 38 | vector<Bullet> BulletS::get_vector() |
| josh_ohara | 14:e88bcf5c0887 | 39 | { |
| josh_ohara | 14:e88bcf5c0887 | 40 | vector<Bullet> v = bullet_vector; |
| josh_ohara | 14:e88bcf5c0887 | 41 | return v; |
| josh_ohara | 14:e88bcf5c0887 | 42 | } |
| josh_ohara | 14:e88bcf5c0887 | 43 | |
| josh_ohara | 14:e88bcf5c0887 | 44 | void BulletS::set_hit(int i, bool x) |
| josh_ohara | 14:e88bcf5c0887 | 45 | { |
| josh_ohara | 14:e88bcf5c0887 | 46 | bullet_vector[i].set_hit(x); |
| josh_ohara | 14:e88bcf5c0887 | 47 | } |
| josh_ohara | 15:dde4ce4bf7fe | 48 | |
| josh_ohara | 15:dde4ce4bf7fe | 49 | void BulletS::flag_set() |
| josh_ohara | 15:dde4ce4bf7fe | 50 | { |
| josh_ohara | 15:dde4ce4bf7fe | 51 | Shoot = 1; |
| josh_ohara | 15:dde4ce4bf7fe | 52 | Gamepad pad1; |
| josh_ohara | 15:dde4ce4bf7fe | 53 | pad1.leds_on(); |
| josh_ohara | 15:dde4ce4bf7fe | 54 | wait(1); |
| josh_ohara | 15:dde4ce4bf7fe | 55 | pad1.leds_off(); |
| josh_ohara | 15:dde4ce4bf7fe | 56 | } |
| josh_ohara | 15:dde4ce4bf7fe | 57 |