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
Alien/Alien.cpp@14:e88bcf5c0887, 2020-04-03 (annotated)
- Committer:
- josh_ohara
- Date:
- Fri Apr 03 11:19:53 2020 +0000
- Revision:
- 14:e88bcf5c0887
- Parent:
- 13:b85f14d35be1
- Child:
- 15:dde4ce4bf7fe
Bullet and aliens now functioning correctly. Collision function completed using get_position method instead of checking if pixels were black (finally). Space invaders must use this method as we want alien bullets to go through aliens without collsion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
josh_ohara | 9:8e695df3cc36 | 1 | #include "Alien.h" |
josh_ohara | 6:5bea67cc96f9 | 2 | |
josh_ohara | 6:5bea67cc96f9 | 3 | |
josh_ohara | 12:be491ab6e742 | 4 | void Alien::init(int x, int y, int size) { |
josh_ohara | 10:9189419fda68 | 5 | Alive = true; |
josh_ohara | 13:b85f14d35be1 | 6 | StartX = x; |
josh_ohara | 13:b85f14d35be1 | 7 | StartY = y; |
josh_ohara | 12:be491ab6e742 | 8 | X = x; |
josh_ohara | 9:8e695df3cc36 | 9 | Y = y; |
josh_ohara | 9:8e695df3cc36 | 10 | Size = size; |
josh_ohara | 9:8e695df3cc36 | 11 | Speed = 1; |
josh_ohara | 9:8e695df3cc36 | 12 | } |
josh_ohara | 9:8e695df3cc36 | 13 | |
josh_ohara | 9:8e695df3cc36 | 14 | void Alien::render(N5110 &lcd) { |
josh_ohara | 10:9189419fda68 | 15 | if(Alive == true){ |
josh_ohara | 10:9189419fda68 | 16 | lcd.drawRect(X, Y, Size, Size, FILL_BLACK); |
josh_ohara | 10:9189419fda68 | 17 | } |
josh_ohara | 9:8e695df3cc36 | 18 | } |
josh_ohara | 6:5bea67cc96f9 | 19 | |
josh_ohara | 9:8e695df3cc36 | 20 | Vector2D Alien::get_position() { |
josh_ohara | 9:8e695df3cc36 | 21 | Vector2D p = {X,Y}; |
josh_ohara | 9:8e695df3cc36 | 22 | return p; |
josh_ohara | 9:8e695df3cc36 | 23 | } |
josh_ohara | 6:5bea67cc96f9 | 24 | |
josh_ohara | 14:e88bcf5c0887 | 25 | void Alien::update(int step_x, int remainder_x, Gamepad &pad) { |
josh_ohara | 9:8e695df3cc36 | 26 | X+=Speed; |
josh_ohara | 13:b85f14d35be1 | 27 | int _step_x = step_x; |
josh_ohara | 13:b85f14d35be1 | 28 | int _remainder_x = remainder_x; |
josh_ohara | 13:b85f14d35be1 | 29 | if (X < 1 + _remainder_x*_step_x) { |
josh_ohara | 13:b85f14d35be1 | 30 | X = 1 + _remainder_x*_step_x; |
josh_ohara | 9:8e695df3cc36 | 31 | Speed = -Speed; |
josh_ohara | 13:b85f14d35be1 | 32 | Y = Y + 2; |
josh_ohara | 9:8e695df3cc36 | 33 | } |
josh_ohara | 13:b85f14d35be1 | 34 | if (X > WIDTH - Size - 1 - (4-_remainder_x)*_step_x) { |
josh_ohara | 13:b85f14d35be1 | 35 | X = WIDTH - Size - 1 - (4-_remainder_x)*_step_x; |
josh_ohara | 9:8e695df3cc36 | 36 | Speed = -Speed; |
josh_ohara | 13:b85f14d35be1 | 37 | Y = Y + 2; |
josh_ohara | 9:8e695df3cc36 | 38 | } |
josh_ohara | 9:8e695df3cc36 | 39 | } |
josh_ohara | 6:5bea67cc96f9 | 40 | |
josh_ohara | 14:e88bcf5c0887 | 41 | void Alien::set_life(bool x){ |
josh_ohara | 14:e88bcf5c0887 | 42 | Alive = x; |
josh_ohara | 14:e88bcf5c0887 | 43 | } |
josh_ohara | 10:9189419fda68 | 44 |