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
- Committer:
- MatisRequis
- Date:
- 2020-05-26
- Revision:
- 9:759b419fec3b
- Parent:
- 8:5feb1913bc92
- Child:
- 10:2ae9d4145410
File content as of revision 9:759b419fec3b:
#include "TempestEngine.h" TempestEngine::TempestEngine() { } TempestEngine::~TempestEngine() { } void TempestEngine::init() { _hero.init(0); _alienspeed = 6; } void TempestEngine::draw(N5110 &lcd) { _board.draw(lcd); //draw hero ship _hero.draw(lcd); //draw bullets draw_bullets(lcd); draw_aliens(lcd); } void TempestEngine::read_input(Gamepad &pad) { _d = pad.get_angle(); _mag = pad.get_mag(); _a = pad.A_pressed(); } void TempestEngine::update() { _hero.update(_d, _mag); create_bullets(); update_bullets(); create_aliens(); update_aliens(); } ////////////////////////////////////////////////////////////BULLET BEHAVIOR///////////////////////////// void TempestEngine::create_bullets() { if (_bullet_timer <= 0) { if (_a) { Bullet new_bullet; new_bullet.init(_hero.get_column()); bullet_vect.push_back(new_bullet); _bullet_timer = 2; } } _bullet_timer--; } //draws all the bullets void TempestEngine::draw_bullets(N5110 &lcd) { //iterates through the bullet objects for (int i = 0; i< bullet_vect.size(); i++) { //draws current bullet bullet_vect[i].draw(lcd); } } void TempestEngine::update_bullets() { for (int i =0; i< bullet_vect.size(); i++) { bullet_vect[i].update(); //checks if bullet needs to be deleted if (bullet_vect[i].checkdelete()) { bullet_vect.erase(bullet_vect.begin() + i); } } } ///////////////////////////////////////////////////////////////ALIEN BEHAVIOR////////////////////////////// void TempestEngine::create_aliens() { if (_alien_timer <= 0) { Alien new_alien; new_alien.init((rand() % 12), _alienspeed); alien_vect.push_back(new_alien); _alien_timer = (rand() % 10) + 10; } _alien_timer--; } //draws all the aliens void TempestEngine::draw_aliens(N5110 &lcd) { //iterates through the alien objects for (int i = 0; i< alien_vect.size(); i++) { //draws current alien alien_vect[i].draw(lcd); } } void TempestEngine::update_aliens() { for (int i =0; i< alien_vect.size(); i++) { alien_vect[i].update(); //checks if alien needs to be deleted if (alien_vect[i].checkdelete()) { alien_vect.erase(alien_vect.begin() + i); } } }