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.

Committer:
evanso
Date:
Sun May 03 18:15:58 2020 +0000
Revision:
19:1bc0a2d22054
Parent:
18:11068b98e261
Child:
20:febd920ec29e
Bullets can now be shot in both directions. Began work on alien class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 8:dd1037c5435b 1 #include "GameEngine.h"
evanso 8:dd1037c5435b 2
evanso 8:dd1037c5435b 3 GameEngine::GameEngine() {
evanso 8:dd1037c5435b 4
evanso 8:dd1037c5435b 5 }
evanso 8:dd1037c5435b 6
evanso 8:dd1037c5435b 7 GameEngine::~GameEngine() {
evanso 8:dd1037c5435b 8
evanso 8:dd1037c5435b 9 }
evanso 8:dd1037c5435b 10
evanso 13:12276eed13ac 11 void GameEngine::init() {
evanso 8:dd1037c5435b 12 pad.init();
evanso 8:dd1037c5435b 13 lcd.init();
evanso 8:dd1037c5435b 14 spaceship.init();
evanso 13:12276eed13ac 15 map.init(pad);
evanso 8:dd1037c5435b 16 }
evanso 8:dd1037c5435b 17
evanso 13:12276eed13ac 18 void GameEngine::gameplay_loop() {
evanso 11:ab578a151f67 19 // clear screen
evanso 13:12276eed13ac 20 lcd.setContrast(pad.read_pot1());
evanso 8:dd1037c5435b 21 lcd.clear();
evanso 11:ab578a151f67 22
evanso 15:90b6821bcf64 23 // Gets movements
evanso 15:90b6821bcf64 24 read_joystick_direction();
evanso 13:12276eed13ac 25 spaceship.movement(d_);
evanso 19:1bc0a2d22054 26 create_bullet();
evanso 19:1bc0a2d22054 27
evanso 18:11068b98e261 28 // Draws
evanso 18:11068b98e261 29 spaceship.draw(lcd);
evanso 18:11068b98e261 30 map.draw_map(lcd, d_);
evanso 19:1bc0a2d22054 31 draw_bullets();
evanso 18:11068b98e261 32
evanso 18:11068b98e261 33 // refresh's screen
evanso 18:11068b98e261 34 lcd.refresh();
evanso 13:12276eed13ac 35 }
evanso 13:12276eed13ac 36
evanso 15:90b6821bcf64 37 void GameEngine::read_joystick_direction(){
evanso 13:12276eed13ac 38 d_ = pad.get_direction();
evanso 18:11068b98e261 39 }
evanso 18:11068b98e261 40
evanso 19:1bc0a2d22054 41 void GameEngine::create_bullet(){
evanso 19:1bc0a2d22054 42 if (pad.A_pressed()){
evanso 19:1bc0a2d22054 43 // Bullet object
evanso 19:1bc0a2d22054 44 Weapons new_bullet;
evanso 19:1bc0a2d22054 45
evanso 19:1bc0a2d22054 46 new_bullet.init(spaceship.get_pos(), spaceship.get_spaceship_sprite_direction());
evanso 19:1bc0a2d22054 47
evanso 19:1bc0a2d22054 48 // Stores bullet object on vector
evanso 19:1bc0a2d22054 49 bullet_vector.push_back(new_bullet);
evanso 19:1bc0a2d22054 50 }
evanso 19:1bc0a2d22054 51 }
evanso 19:1bc0a2d22054 52
evanso 19:1bc0a2d22054 53 void GameEngine::draw_bullets(){
evanso 19:1bc0a2d22054 54 // interates over bullet vector and get each new_bullet draw it's self with their updated postion
evanso 19:1bc0a2d22054 55 for (int i = 0; i < bullet_vector.size(); i++){
evanso 19:1bc0a2d22054 56 bullet_vector[i].draw_bullet(lcd);
evanso 19:1bc0a2d22054 57 }
evanso 19:1bc0a2d22054 58 }
evanso 19:1bc0a2d22054 59