
Joshua O'hara 201291390
Dependencies: mbed
Alien/Alien.cpp@22:3e978b1d7958, 2020-05-13 (annotated)
- Committer:
- josh_ohara
- Date:
- Wed May 13 19:27:46 2020 +0000
- Revision:
- 22:3e978b1d7958
- Parent:
- 21:970807533b10
- Child:
- 24:ff5af5a013b5
Level progression programmed. Need to figure out how to delete objects when a new level commences.
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 | 22:3e978b1d7958 | 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 | 22:3e978b1d7958 | 54 | //printf("A = %2d ",Alive); |
josh_ohara | 22:3e978b1d7958 | 55 | return Alive; |
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 | 22:3e978b1d7958 | 60 | if(c%7 == 1){ |
josh_ohara | 20:0b6f1cfc5be6 | 61 | int r = rand()%20; |
josh_ohara | 20:0b6f1cfc5be6 | 62 | if((r < 2)&& |
josh_ohara | 20:0b6f1cfc5be6 | 63 | (Alive == true)) { |
josh_ohara | 18:828e9f6ddfdb | 64 | Shoot = true; |
josh_ohara | 19:43de9fd725ba | 65 | } |
josh_ohara | 18:828e9f6ddfdb | 66 | } |
josh_ohara | 18:828e9f6ddfdb | 67 | } |
josh_ohara | 18:828e9f6ddfdb | 68 | |
josh_ohara | 20:0b6f1cfc5be6 | 69 | vector<AlienBullet> Alien::get_bullet_vector(){ |
josh_ohara | 20:0b6f1cfc5be6 | 70 | vector<AlienBullet> v = alien_bullet_vector.get_vector(); |
josh_ohara | 20:0b6f1cfc5be6 | 71 | return v; |
josh_ohara | 20:0b6f1cfc5be6 | 72 | } |
josh_ohara | 20:0b6f1cfc5be6 | 73 | |
josh_ohara | 20:0b6f1cfc5be6 | 74 | void Alien::set_bullet_hit(int i, bool hit){ |
josh_ohara | 20:0b6f1cfc5be6 | 75 | alien_bullet_vector.set_hit(i,hit); |
josh_ohara | 20:0b6f1cfc5be6 | 76 | } |