Meteor defense project

Dependencies:   N5110 mbed

GameEngine/GameEngine.cpp

Committer:
jasper0712
Date:
2017-03-30
Revision:
13:38cbce17d7d7
Parent:
11:1c48fe71045c
Child:
14:064b8d7f348d

File content as of revision 13:38cbce17d7d7:

#include "GameEngine.h"

GameEngine::GameEngine()
{

}

GameEngine::~GameEngine()
{

}

void GameEngine::drawSpawn(N5110 &lcd){
    //spawning every 2 second, moving every 1 seconds at 15 fps & drawit=15. 
    //It changes depending on the game FPS.
    if (drawit ==0) {
        drawit =30;
        spa.randomizeSpawn(Array2, charArray);
        spa.moveSpawnABC(Array1, Array2, charArray);
    } else {
        drawit -=0.5;
        spa.moveSpawnB(Array1, Array2, charArray);
    }
    spa.updateSpawn(Array1, Array2, charArray, lcd); 
    checkGameRule(lcd);
}
void GameEngine::drawLaserPlayer(Gamepad &pad, N5110 &lcd) {
    weap.laserDamage();
    weap.drawWeapon(pad, lcd);
    //draw a line for the laser when button is pressed
    if (pad.buttonhold_A == 1) {
        //printf("hi, button is working \n");
        weap.weaponMath(pad);
        weap.drawLaser(Array1, lcd);
    }
}

void GameEngine::checkGameRule(N5110 &lcd) {
    //the only way to lose is when the spawn reaches y = 46.
    for ( int x = 0; x < 84; x ++) {
        if (Array1[x][46] > 0) {
            while (1) {
                lcd.clear();
                lcd.printString("Game Over",10,3);
                lcd.refresh();
                wait(1.0);
            }
        }
    }       
}
void GameEngine::bomb(Gamepad &pad, N5110 &lcd) { //cooldown not yet implemented.
    weap.bombCooldown(Array1, pad, lcd);

}