Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

GameEngine/GameEngine.cpp

Committer:
evanso
Date:
2020-05-03
Revision:
19:1bc0a2d22054
Parent:
18:11068b98e261
Child:
20:febd920ec29e

File content as of revision 19:1bc0a2d22054:

#include "GameEngine.h"

GameEngine::GameEngine() {
    
}
 
GameEngine::~GameEngine() {
    
}

void GameEngine::init() {
    pad.init();
    lcd.init();
    spaceship.init();
    map.init(pad);
}

void GameEngine::gameplay_loop() {
    // clear screen 
    lcd.setContrast(pad.read_pot1());          
    lcd.clear();
    
    // Gets movements  
    read_joystick_direction();
    spaceship.movement(d_);
    create_bullet();

    // Draws 
    spaceship.draw(lcd);
    map.draw_map(lcd, d_);
    draw_bullets();

    // refresh's screen
    lcd.refresh(); 
}

void GameEngine::read_joystick_direction(){
    d_ = pad.get_direction();
}

void GameEngine::create_bullet(){
    if (pad.A_pressed()){
        // Bullet object
        Weapons new_bullet;
        
        new_bullet.init(spaceship.get_pos(), spaceship.get_spaceship_sprite_direction());
        
        // Stores bullet object on vector 
        bullet_vector.push_back(new_bullet);
    }   
}

void GameEngine::draw_bullets(){
    // interates over bullet vector and get each new_bullet draw it's self with their updated postion 
    for (int i = 0; i < bullet_vector.size(); i++){
        bullet_vector[i].draw_bullet(lcd);
    }
}