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@2:c2316b659b97, 2020-03-14 (annotated)
- Committer:
- josh_ohara
- Date:
- Sat Mar 14 20:52:07 2020 +0000
- Revision:
- 2:c2316b659b97
- Child:
- 3:8a140aa1ddcd
Created major folders. Brainstormed some ideas and concluded space invaders. Initial set up of .h and .cpp files for Ship bullets and Ship created.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| josh_ohara | 2:c2316b659b97 | 1 | #include Bullet.h |
| josh_ohara | 2:c2316b659b97 | 2 | |
| josh_ohara | 2:c2316b659b97 | 3 | Bullet::Bullet() |
| josh_ohara | 2:c2316b659b97 | 4 | { |
| josh_ohara | 2:c2316b659b97 | 5 | } |
| josh_ohara | 2:c2316b659b97 | 6 | |
| josh_ohara | 2:c2316b659b97 | 7 | void Bullet::init(int size, int speed, int x, int y) |
| josh_ohara | 2:c2316b659b97 | 8 | { |
| josh_ohara | 2:c2316b659b97 | 9 | Size = size; |
| josh_ohara | 2:c2316b659b97 | 10 | Speed = 0; |
| josh_ohara | 2:c2316b659b97 | 11 | X = WIDTH/2 - Size/2; //Middle of the ship |
| josh_ohara | 2:c2316b659b97 | 12 | Y = HEIGHT - Height; //Top of the ship |
| josh_ohara | 2:c2316b659b97 | 13 | } |
| josh_ohara | 2:c2316b659b97 | 14 | |
| josh_ohara | 2:c2316b659b97 | 15 | void Bullet::draw(N5110 &lcd) |
| josh_ohara | 2:c2316b659b97 | 16 | { |
| josh_ohara | 2:c2316b659b97 | 17 | lcd.drawRect(X,Y,Size,Size,FILL_BLACK); |
| josh_ohara | 2:c2316b659b97 | 18 | } |
| josh_ohara | 2:c2316b659b97 | 19 | |
| josh_ohara | 2:c2316b659b97 | 20 | void update(); |
| josh_ohara | 2:c2316b659b97 | 21 | if(pad.A_pressed()) { |
| josh_ohara | 2:c2316b659b97 | 22 | Speed = 1; //shoots bullet if pad a pressed |
| josh_ohara | 2:c2316b659b97 | 23 | Y -= Speed; |
| josh_ohara | 2:c2316b659b97 | 24 | } |
| josh_ohara | 2:c2316b659b97 | 25 | |
| josh_ohara | 2:c2316b659b97 | 26 | Vector2D Ship::get_position(); |
| josh_ohara | 2:c2316b659b97 | 27 | Vector2D p = {X,Y}; |
| josh_ohara | 2:c2316b659b97 | 28 | return p; |
| josh_ohara | 2:c2316b659b97 | 29 | } |
| josh_ohara | 2:c2316b659b97 | 30 | |
| josh_ohara | 2:c2316b659b97 | 31 | |
| josh_ohara | 2:c2316b659b97 | 32 | |
| josh_ohara | 2:c2316b659b97 | 33 |