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:
Wed Apr 22 20:02:22 2020 +0000
Revision:
10:aca793aa7abc
Parent:
9:1ddb8dc93e48
Child:
11:ab578a151f67
Reduced length of spaceship movement function using a switch statement. In the previous commit, I changed the draw line function in the LCD class; I changed its unassigned int variables to normal int variables as it was crashing the game.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b7f1f47bb26a 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
evanso 1:1f2ae263248e 7 Name:Benjamin Evans
evanso 1:1f2ae263248e 8 Username:el18bpe
evanso 1:1f2ae263248e 9 Student ID Number:201216635
evanso 1:1f2ae263248e 10 Date:23/02/2020
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
evanso 3:dee187b8b30c 13 // Includes libaries
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
evanso 3:dee187b8b30c 17 #include "Spaceship.h"
evanso 6:12e8433382b3 18 #include "Map.h"
evanso 8:dd1037c5435b 19 #include "GameEngine.h"
eencae 0:b7f1f47bb26a 20
evanso 9:1ddb8dc93e48 21 // to do
evanso 9:1ddb8dc93e48 22 // add debug functions for variables
evanso 9:1ddb8dc93e48 23 // make random calss
evanso 9:1ddb8dc93e48 24 // fix if statmet in spaceship
evanso 9:1ddb8dc93e48 25 // add structs in things
evanso 9:1ddb8dc93e48 26 // use bitmap for sprite
evanso 10:aca793aa7abc 27 // next commit say had to change lcd class becuse causes crash in prevous commit
evanso 10:aca793aa7abc 28 // add test files
evanso 9:1ddb8dc93e48 29
eencae 0:b7f1f47bb26a 30
evanso 3:dee187b8b30c 31 // Objects
eencae 0:b7f1f47bb26a 32 Gamepad pad;
eencae 0:b7f1f47bb26a 33 N5110 lcd;
evanso 3:dee187b8b30c 34 Ticker ticker;
evanso 8:dd1037c5435b 35 GameEngine engine;
evanso 4:0df2b85e47f1 36 AnalogIn pot_1(PTB2);
evanso 8:dd1037c5435b 37 Spaceship spaceship;
evanso 6:12e8433382b3 38 Map map;
evanso 8:dd1037c5435b 39 AnalogIn adc(PTD5);
evanso 9:1ddb8dc93e48 40 //Serial usb(USBTX, USBRX);
evanso 3:dee187b8b30c 41
evanso 3:dee187b8b30c 42 // Global varable definitions
evanso 7:0af4ced868f5 43 volatile int g_lcd_frame_time_flag = 0;
evanso 3:dee187b8b30c 44
evanso 3:dee187b8b30c 45 // Function definitions
evanso 4:0df2b85e47f1 46 void lcd_frame_time_isr();
eencae 0:b7f1f47bb26a 47
eencae 0:b7f1f47bb26a 48 int main()
evanso 3:dee187b8b30c 49 {
evanso 3:dee187b8b30c 50 // Sets fram rate of lcd by using time-triggered tasks
evanso 7:0af4ced868f5 51 ticker.attach(&lcd_frame_time_isr,0.03);
evanso 8:dd1037c5435b 52 engine.init(lcd, spaceship, map, pad, adc);
eencae 0:b7f1f47bb26a 53
evanso 3:dee187b8b30c 54 while (1) {
evanso 8:dd1037c5435b 55
evanso 3:dee187b8b30c 56 // Checks flag and prints spaceship on lcd then resets flag
evanso 3:dee187b8b30c 57 if (g_lcd_frame_time_flag) {
evanso 8:dd1037c5435b 58 g_lcd_frame_time_flag = 0; // resets flag
evanso 7:0af4ced868f5 59
evanso 8:dd1037c5435b 60 engine.gameplay_loop(lcd, spaceship, map, pad, pot_1);
evanso 3:dee187b8b30c 61 }
evanso 8:dd1037c5435b 62
evanso 3:dee187b8b30c 63 // MCU put to sleep between each frame to save power
evanso 3:dee187b8b30c 64 sleep();
evanso 3:dee187b8b30c 65 }
eencae 0:b7f1f47bb26a 66 }
eencae 0:b7f1f47bb26a 67
evanso 3:dee187b8b30c 68 // Time-triggered interrupt to wake MCU from sleep
evanso 4:0df2b85e47f1 69 void lcd_frame_time_isr()
evanso 3:dee187b8b30c 70 {
evanso 3:dee187b8b30c 71 g_lcd_frame_time_flag = 1; // set flag in ISR
evanso 3:dee187b8b30c 72 }