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:
Tue May 19 17:08:06 2020 +0000
Revision:
52:feb8cf28bcff
Parent:
51:35cb8e604b72
Child:
53:01be7898c23f
Added add_saved_data function to savedata class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 49:ed569eceeaa4 1 #include "SavedGames.h"
evanso 49:ed569eceeaa4 2
evanso 49:ed569eceeaa4 3 SavedGames::SavedGames() {
evanso 49:ed569eceeaa4 4
evanso 49:ed569eceeaa4 5 }
evanso 49:ed569eceeaa4 6
evanso 49:ed569eceeaa4 7 SavedGames::~SavedGames() {
evanso 49:ed569eceeaa4 8
evanso 49:ed569eceeaa4 9 }
evanso 49:ed569eceeaa4 10
evanso 50:13c8710985f4 11 void SavedGames::init(SDFileSystem &sd,N5110 &lcd){
evanso 50:13c8710985f4 12 error_ = false;
evanso 50:13c8710985f4 13 check_sd_present(sd,lcd);
evanso 51:35cb8e604b72 14 check_open_file(sd,lcd);
evanso 50:13c8710985f4 15 }
evanso 49:ed569eceeaa4 16
evanso 50:13c8710985f4 17 void SavedGames::check_sd_present(SDFileSystem &sd,N5110 &lcd){
evanso 50:13c8710985f4 18 if(!sd.card_present()) {
evanso 50:13c8710985f4 19 error_ = true;
evanso 51:35cb8e604b72 20
evanso 51:35cb8e604b72 21 //print error screen
evanso 50:13c8710985f4 22 lcd.clear();
evanso 50:13c8710985f4 23 lcd.printString("SD card not ",9,3);
evanso 50:13c8710985f4 24 lcd.printString(" present ",9,4);
evanso 50:13c8710985f4 25 lcd.refresh();
evanso 50:13c8710985f4 26 wait(3);
evanso 50:13c8710985f4 27 }
evanso 50:13c8710985f4 28 }
evanso 50:13c8710985f4 29
evanso 51:35cb8e604b72 30 void SavedGames::check_open_file(SDFileSystem &sd,N5110 &lcd){
evanso 51:35cb8e604b72 31 //opens file
evanso 51:35cb8e604b72 32 FILE *fp;
evanso 51:35cb8e604b72 33 fp = fopen("/sd/SavedGames.text", "a");
evanso 51:35cb8e604b72 34
evanso 51:35cb8e604b72 35 //checks if file is opened corectly
evanso 51:35cb8e604b72 36 if (fp == NULL) {
evanso 51:35cb8e604b72 37 error_ = true;
evanso 51:35cb8e604b72 38
evanso 51:35cb8e604b72 39 //print error screen
evanso 51:35cb8e604b72 40 lcd.clear();
evanso 51:35cb8e604b72 41 lcd.printString(" Unable to ",9,3);
evanso 51:35cb8e604b72 42 lcd.printString(" open file ",9,4);
evanso 51:35cb8e604b72 43 lcd.refresh();
evanso 51:35cb8e604b72 44 wait(3);
evanso 51:35cb8e604b72 45 }
evanso 51:35cb8e604b72 46 }
evanso 51:35cb8e604b72 47
evanso 52:feb8cf28bcff 48 void SavedGames::add_saved_data(SDFileSystem &sd, SavedGamesData data,
evanso 52:feb8cf28bcff 49 N5110 &lcd){
evanso 52:feb8cf28bcff 50 check_open_file(sd,lcd);
evanso 52:feb8cf28bcff 51
evanso 52:feb8cf28bcff 52 //opens file
evanso 52:feb8cf28bcff 53 FILE *fp;
evanso 52:feb8cf28bcff 54 fp = fopen("/sd/SavedGames.text", "a");
evanso 52:feb8cf28bcff 55
evanso 52:feb8cf28bcff 56 //Adda data to file if no error
evanso 52:feb8cf28bcff 57 if(!error_){
evanso 52:feb8cf28bcff 58 fprintf(fp, "%d\n", data.score);
evanso 52:feb8cf28bcff 59 fprintf(fp, "%d\n", data.lives);
evanso 52:feb8cf28bcff 60 fprintf(fp, "%d\n", data.smart_bombs);
evanso 52:feb8cf28bcff 61 fprintf(fp, "%d\n", data.alien_number);
evanso 52:feb8cf28bcff 62 fclose(fp);
evanso 52:feb8cf28bcff 63 }
evanso 51:35cb8e604b72 64
evanso 51:35cb8e604b72 65 }
evanso 51:35cb8e604b72 66
evanso 50:13c8710985f4 67 bool SavedGames::get_error(){
evanso 50:13c8710985f4 68 return error_;
evanso 50:13c8710985f4 69 }
evanso 50:13c8710985f4 70
evanso 50:13c8710985f4 71