Matis Requis 201241242

Dependencies:   mbed

Tempest Game

Game Screen

https://os.mbed.com/media/uploads/MatisRequis/tempest_board_wiki.png The board is made of 12 columns. The Hero stays at the top of the column

Game Controls

https://os.mbed.com/media/uploads/MatisRequis/gamepad_buttons.png

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-25
Revision:
7:94bc3e21d664
Parent:
6:037dfa5064a1
Child:
8:5feb1913bc92

File content as of revision 7:94bc3e21d664:

#include "TempestEngine.h"

TempestEngine::TempestEngine() {
    
}

TempestEngine::~TempestEngine() {
    
}


void TempestEngine::init() {
    _hero.init(0);
    }
    

void TempestEngine::draw(N5110 &lcd) {
    _board.draw(lcd);
    
    //draw hero ship
    _hero.draw(lcd);
    
    //draw bullets
    draw_bullets(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();
}

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 = 5;  
        }
    //}  
    //_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++) {
        bullet_vect[i].update();   
        //draws current bullet
        bullet_vect[i].draw(lcd);
        
        //checks if bullet needs to be deleted
        if (bullet_vect[i].checkdelete()) {
            bullet_vect.erase(bullet_vect.begin() + i);
        }
    }
}