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@19:43de9fd725ba, 2020-05-01 (annotated)
- Committer:
- josh_ohara
- Date:
- Fri May 01 14:46:10 2020 +0000
- Revision:
- 19:43de9fd725ba
- Parent:
- 18:828e9f6ddfdb
- Child:
- 20:0b6f1cfc5be6
Alien bullets fire randomly
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 | 17:8b1d16d56ad2 | 6 | Shoot = false; |
josh_ohara | 13:b85f14d35be1 | 7 | StartX = x; |
josh_ohara | 13:b85f14d35be1 | 8 | StartY = y; |
josh_ohara | 12:be491ab6e742 | 9 | X = x; |
josh_ohara | 9:8e695df3cc36 | 10 | Y = y; |
josh_ohara | 9:8e695df3cc36 | 11 | Size = size; |
josh_ohara | 9:8e695df3cc36 | 12 | Speed = 1; |
josh_ohara | 18:828e9f6ddfdb | 13 | alien_bullet_vector.init(); |
josh_ohara | 18:828e9f6ddfdb | 14 | |
josh_ohara | 9:8e695df3cc36 | 15 | } |
josh_ohara | 9:8e695df3cc36 | 16 | |
josh_ohara | 9:8e695df3cc36 | 17 | void Alien::render(N5110 &lcd) { |
josh_ohara | 10:9189419fda68 | 18 | if(Alive == true){ |
josh_ohara | 10:9189419fda68 | 19 | lcd.drawRect(X, Y, Size, Size, FILL_BLACK); |
josh_ohara | 18:828e9f6ddfdb | 20 | alien_bullet_vector.render(lcd); |
josh_ohara | 10:9189419fda68 | 21 | } |
josh_ohara | 9:8e695df3cc36 | 22 | } |
josh_ohara | 6:5bea67cc96f9 | 23 | |
josh_ohara | 9:8e695df3cc36 | 24 | Vector2D Alien::get_position() { |
josh_ohara | 9:8e695df3cc36 | 25 | Vector2D p = {X,Y}; |
josh_ohara | 9:8e695df3cc36 | 26 | return p; |
josh_ohara | 9:8e695df3cc36 | 27 | } |
josh_ohara | 6:5bea67cc96f9 | 28 | |
josh_ohara | 18:828e9f6ddfdb | 29 | void Alien::update(int step_x, int remainder_x, Gamepad &pad, int counter) { |
josh_ohara | 9:8e695df3cc36 | 30 | X+=Speed; |
josh_ohara | 18:828e9f6ddfdb | 31 | int c = counter; |
josh_ohara | 13:b85f14d35be1 | 32 | int _step_x = step_x; |
josh_ohara | 13:b85f14d35be1 | 33 | int _remainder_x = remainder_x; |
josh_ohara | 13:b85f14d35be1 | 34 | if (X < 1 + _remainder_x*_step_x) { |
josh_ohara | 13:b85f14d35be1 | 35 | X = 1 + _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 | 13:b85f14d35be1 | 39 | if (X > WIDTH - Size - 1 - (4-_remainder_x)*_step_x) { |
josh_ohara | 13:b85f14d35be1 | 40 | X = WIDTH - Size - 1 - (4-_remainder_x)*_step_x; |
josh_ohara | 9:8e695df3cc36 | 41 | Speed = -Speed; |
josh_ohara | 13:b85f14d35be1 | 42 | Y = Y + 2; |
josh_ohara | 9:8e695df3cc36 | 43 | } |
josh_ohara | 18:828e9f6ddfdb | 44 | flag_set(c); |
josh_ohara | 18:828e9f6ddfdb | 45 | alien_bullet_vector.update(X,Y,Shoot); |
josh_ohara | 18:828e9f6ddfdb | 46 | Shoot = false; |
josh_ohara | 9:8e695df3cc36 | 47 | } |
josh_ohara | 6:5bea67cc96f9 | 48 | |
josh_ohara | 14:e88bcf5c0887 | 49 | void Alien::set_life(bool x){ |
josh_ohara | 14:e88bcf5c0887 | 50 | Alive = x; |
josh_ohara | 15:dde4ce4bf7fe | 51 | } |
josh_ohara | 10:9189419fda68 | 52 | |
josh_ohara | 15:dde4ce4bf7fe | 53 | bool Alien::get_life(){ |
josh_ohara | 15:dde4ce4bf7fe | 54 | bool x = Alive; |
josh_ohara | 15:dde4ce4bf7fe | 55 | return x; |
josh_ohara | 15:dde4ce4bf7fe | 56 | } |
josh_ohara | 15:dde4ce4bf7fe | 57 | |
josh_ohara | 18:828e9f6ddfdb | 58 | void Alien::flag_set(int counter){ |
josh_ohara | 18:828e9f6ddfdb | 59 | int c = counter; |
josh_ohara | 18:828e9f6ddfdb | 60 | if(c%7 == 1){ |
josh_ohara | 19:43de9fd725ba | 61 | int r = rand()%10; |
josh_ohara | 19:43de9fd725ba | 62 | if(r < 3) { |
josh_ohara | 18:828e9f6ddfdb | 63 | Shoot = true; |
josh_ohara | 19:43de9fd725ba | 64 | } |
josh_ohara | 18:828e9f6ddfdb | 65 | } |
josh_ohara | 18:828e9f6ddfdb | 66 | } |
josh_ohara | 18:828e9f6ddfdb | 67 |