![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Matis Requis 201241242
Dependencies: mbed
Tempest Game
Game Screen
The board is made of 12 columns. The Hero stays at the top of the column
Game Controls
To control the hero spaceship point the joystick to the column you want the hero to go to.
Press the A button to shoot a bullet in the column you are currently in.
TempestEngine/TempestEngine.cpp@9:759b419fec3b, 2020-05-26 (annotated)
- Committer:
- MatisRequis
- Date:
- Tue May 26 07:26:13 2020 +0000
- Revision:
- 9:759b419fec3b
- Parent:
- 8:5feb1913bc92
- Child:
- 10:2ae9d4145410
Aliens working similar to bullets with random
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MatisRequis | 2:d59a92e65bd9 | 1 | #include "TempestEngine.h" |
MatisRequis | 2:d59a92e65bd9 | 2 | |
MatisRequis | 2:d59a92e65bd9 | 3 | TempestEngine::TempestEngine() { |
MatisRequis | 2:d59a92e65bd9 | 4 | |
MatisRequis | 2:d59a92e65bd9 | 5 | } |
MatisRequis | 2:d59a92e65bd9 | 6 | |
MatisRequis | 2:d59a92e65bd9 | 7 | TempestEngine::~TempestEngine() { |
MatisRequis | 2:d59a92e65bd9 | 8 | |
MatisRequis | 2:d59a92e65bd9 | 9 | } |
MatisRequis | 2:d59a92e65bd9 | 10 | |
MatisRequis | 2:d59a92e65bd9 | 11 | |
MatisRequis | 4:8e3ba8d6d915 | 12 | void TempestEngine::init() { |
MatisRequis | 4:8e3ba8d6d915 | 13 | _hero.init(0); |
MatisRequis | 9:759b419fec3b | 14 | _alienspeed = 6; |
MatisRequis | 2:d59a92e65bd9 | 15 | } |
MatisRequis | 2:d59a92e65bd9 | 16 | |
MatisRequis | 4:8e3ba8d6d915 | 17 | |
MatisRequis | 2:d59a92e65bd9 | 18 | void TempestEngine::draw(N5110 &lcd) { |
MatisRequis | 3:54132cf073d7 | 19 | _board.draw(lcd); |
MatisRequis | 4:8e3ba8d6d915 | 20 | |
MatisRequis | 4:8e3ba8d6d915 | 21 | //draw hero ship |
MatisRequis | 4:8e3ba8d6d915 | 22 | _hero.draw(lcd); |
MatisRequis | 2:d59a92e65bd9 | 23 | |
MatisRequis | 2:d59a92e65bd9 | 24 | //draw bullets |
MatisRequis | 6:037dfa5064a1 | 25 | draw_bullets(lcd); |
MatisRequis | 2:d59a92e65bd9 | 26 | |
MatisRequis | 9:759b419fec3b | 27 | draw_aliens(lcd); |
MatisRequis | 4:8e3ba8d6d915 | 28 | } |
MatisRequis | 9:759b419fec3b | 29 | |
MatisRequis | 9:759b419fec3b | 30 | |
MatisRequis | 4:8e3ba8d6d915 | 31 | void TempestEngine::read_input(Gamepad &pad) { |
MatisRequis | 4:8e3ba8d6d915 | 32 | _d = pad.get_angle(); |
MatisRequis | 7:94bc3e21d664 | 33 | _mag = pad.get_mag(); |
MatisRequis | 7:94bc3e21d664 | 34 | _a = pad.A_pressed(); |
MatisRequis | 4:8e3ba8d6d915 | 35 | } |
MatisRequis | 4:8e3ba8d6d915 | 36 | |
MatisRequis | 4:8e3ba8d6d915 | 37 | |
MatisRequis | 4:8e3ba8d6d915 | 38 | void TempestEngine::update() { |
MatisRequis | 6:037dfa5064a1 | 39 | _hero.update(_d, _mag); |
MatisRequis | 6:037dfa5064a1 | 40 | create_bullets(); |
MatisRequis | 9:759b419fec3b | 41 | update_bullets(); |
MatisRequis | 9:759b419fec3b | 42 | |
MatisRequis | 9:759b419fec3b | 43 | create_aliens(); |
MatisRequis | 9:759b419fec3b | 44 | update_aliens(); |
MatisRequis | 6:037dfa5064a1 | 45 | } |
MatisRequis | 6:037dfa5064a1 | 46 | |
MatisRequis | 9:759b419fec3b | 47 | |
MatisRequis | 9:759b419fec3b | 48 | |
MatisRequis | 9:759b419fec3b | 49 | |
MatisRequis | 9:759b419fec3b | 50 | |
MatisRequis | 9:759b419fec3b | 51 | |
MatisRequis | 9:759b419fec3b | 52 | |
MatisRequis | 9:759b419fec3b | 53 | |
MatisRequis | 9:759b419fec3b | 54 | |
MatisRequis | 9:759b419fec3b | 55 | ////////////////////////////////////////////////////////////BULLET BEHAVIOR///////////////////////////// |
MatisRequis | 6:037dfa5064a1 | 56 | void TempestEngine::create_bullets() { |
MatisRequis | 8:5feb1913bc92 | 57 | if (_bullet_timer <= 0) { |
MatisRequis | 7:94bc3e21d664 | 58 | if (_a) { |
MatisRequis | 6:037dfa5064a1 | 59 | Bullet new_bullet; |
MatisRequis | 6:037dfa5064a1 | 60 | |
MatisRequis | 6:037dfa5064a1 | 61 | new_bullet.init(_hero.get_column()); |
MatisRequis | 6:037dfa5064a1 | 62 | |
MatisRequis | 6:037dfa5064a1 | 63 | bullet_vect.push_back(new_bullet); |
MatisRequis | 6:037dfa5064a1 | 64 | |
MatisRequis | 8:5feb1913bc92 | 65 | _bullet_timer = 2; |
MatisRequis | 6:037dfa5064a1 | 66 | } |
MatisRequis | 8:5feb1913bc92 | 67 | } |
MatisRequis | 8:5feb1913bc92 | 68 | _bullet_timer--; |
MatisRequis | 6:037dfa5064a1 | 69 | } |
MatisRequis | 6:037dfa5064a1 | 70 | |
MatisRequis | 7:94bc3e21d664 | 71 | |
MatisRequis | 6:037dfa5064a1 | 72 | //draws all the bullets |
MatisRequis | 6:037dfa5064a1 | 73 | void TempestEngine::draw_bullets(N5110 &lcd) { |
MatisRequis | 6:037dfa5064a1 | 74 | //iterates through the bullet objects |
MatisRequis | 9:759b419fec3b | 75 | for (int i = 0; i< bullet_vect.size(); i++) { |
MatisRequis | 6:037dfa5064a1 | 76 | //draws current bullet |
MatisRequis | 6:037dfa5064a1 | 77 | bullet_vect[i].draw(lcd); |
MatisRequis | 9:759b419fec3b | 78 | } |
MatisRequis | 9:759b419fec3b | 79 | } |
MatisRequis | 9:759b419fec3b | 80 | |
MatisRequis | 9:759b419fec3b | 81 | |
MatisRequis | 9:759b419fec3b | 82 | void TempestEngine::update_bullets() { |
MatisRequis | 9:759b419fec3b | 83 | for (int i =0; i< bullet_vect.size(); i++) { |
MatisRequis | 9:759b419fec3b | 84 | bullet_vect[i].update(); |
MatisRequis | 6:037dfa5064a1 | 85 | |
MatisRequis | 6:037dfa5064a1 | 86 | //checks if bullet needs to be deleted |
MatisRequis | 6:037dfa5064a1 | 87 | if (bullet_vect[i].checkdelete()) { |
MatisRequis | 6:037dfa5064a1 | 88 | bullet_vect.erase(bullet_vect.begin() + i); |
MatisRequis | 6:037dfa5064a1 | 89 | } |
MatisRequis | 9:759b419fec3b | 90 | } |
MatisRequis | 9:759b419fec3b | 91 | } |
MatisRequis | 9:759b419fec3b | 92 | |
MatisRequis | 9:759b419fec3b | 93 | |
MatisRequis | 9:759b419fec3b | 94 | |
MatisRequis | 9:759b419fec3b | 95 | |
MatisRequis | 9:759b419fec3b | 96 | ///////////////////////////////////////////////////////////////ALIEN BEHAVIOR////////////////////////////// |
MatisRequis | 9:759b419fec3b | 97 | |
MatisRequis | 9:759b419fec3b | 98 | void TempestEngine::create_aliens() { |
MatisRequis | 9:759b419fec3b | 99 | if (_alien_timer <= 0) { |
MatisRequis | 9:759b419fec3b | 100 | |
MatisRequis | 9:759b419fec3b | 101 | Alien new_alien; |
MatisRequis | 9:759b419fec3b | 102 | |
MatisRequis | 9:759b419fec3b | 103 | new_alien.init((rand() % 12), _alienspeed); |
MatisRequis | 9:759b419fec3b | 104 | |
MatisRequis | 9:759b419fec3b | 105 | alien_vect.push_back(new_alien); |
MatisRequis | 9:759b419fec3b | 106 | |
MatisRequis | 9:759b419fec3b | 107 | _alien_timer = (rand() % 10) + 10; |
MatisRequis | 9:759b419fec3b | 108 | |
MatisRequis | 9:759b419fec3b | 109 | } |
MatisRequis | 9:759b419fec3b | 110 | _alien_timer--; |
MatisRequis | 9:759b419fec3b | 111 | } |
MatisRequis | 9:759b419fec3b | 112 | |
MatisRequis | 9:759b419fec3b | 113 | |
MatisRequis | 9:759b419fec3b | 114 | //draws all the aliens |
MatisRequis | 9:759b419fec3b | 115 | void TempestEngine::draw_aliens(N5110 &lcd) { |
MatisRequis | 9:759b419fec3b | 116 | //iterates through the alien objects |
MatisRequis | 9:759b419fec3b | 117 | for (int i = 0; i< alien_vect.size(); i++) { |
MatisRequis | 9:759b419fec3b | 118 | //draws current alien |
MatisRequis | 9:759b419fec3b | 119 | alien_vect[i].draw(lcd); |
MatisRequis | 6:037dfa5064a1 | 120 | } |
MatisRequis | 9:759b419fec3b | 121 | } |
MatisRequis | 9:759b419fec3b | 122 | |
MatisRequis | 9:759b419fec3b | 123 | |
MatisRequis | 9:759b419fec3b | 124 | void TempestEngine::update_aliens() { |
MatisRequis | 9:759b419fec3b | 125 | for (int i =0; i< alien_vect.size(); i++) { |
MatisRequis | 9:759b419fec3b | 126 | alien_vect[i].update(); |
MatisRequis | 9:759b419fec3b | 127 | |
MatisRequis | 9:759b419fec3b | 128 | //checks if alien needs to be deleted |
MatisRequis | 9:759b419fec3b | 129 | if (alien_vect[i].checkdelete()) { |
MatisRequis | 9:759b419fec3b | 130 | alien_vect.erase(alien_vect.begin() + i); |
MatisRequis | 9:759b419fec3b | 131 | } |
MatisRequis | 9:759b419fec3b | 132 | } |
MatisRequis | 9:759b419fec3b | 133 | } |