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 24 19:20:23 2020 +0000
Revision:
77:2ee9d1f9e282
Parent:
76:6daba3002424
Child:
78:6a6c93c19ed1
High score area in the menu now displays the high score. High score updates correctly and correct error messages show when sd card isn't present or no high score is set.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 75:643a509cf9ed 1 #include "HighScore.h"
evanso 75:643a509cf9ed 2
evanso 76:6daba3002424 3 HighScore::HighScore() {
evanso 76:6daba3002424 4
evanso 76:6daba3002424 5 }
evanso 76:6daba3002424 6
evanso 76:6daba3002424 7 HighScore::~HighScore() {
evanso 76:6daba3002424 8
evanso 76:6daba3002424 9 }
evanso 76:6daba3002424 10
evanso 76:6daba3002424 11 void HighScore::init(){
evanso 76:6daba3002424 12 error_ = false;
evanso 76:6daba3002424 13 }
evanso 76:6daba3002424 14
evanso 76:6daba3002424 15 void HighScore::no_high_scores(N5110 &lcd){
evanso 76:6daba3002424 16 //print error screen
evanso 76:6daba3002424 17 lcd.clear();
evanso 76:6daba3002424 18 lcd.printString("No High Scores",0,3);
evanso 77:2ee9d1f9e282 19 lcd.printString("Or No SD Card",3,4);
evanso 76:6daba3002424 20 lcd.refresh();
evanso 76:6daba3002424 21 wait(3);
evanso 76:6daba3002424 22 }
evanso 76:6daba3002424 23
evanso 76:6daba3002424 24 void HighScore::error_open_file(N5110 &lcd){
evanso 76:6daba3002424 25 error_ = true;
evanso 76:6daba3002424 26
evanso 76:6daba3002424 27 //print error screen
evanso 76:6daba3002424 28 lcd.clear();
evanso 76:6daba3002424 29 lcd.printString(" Unable to ",9,3);
evanso 77:2ee9d1f9e282 30 lcd.printString("Save",30,4);
evanso 77:2ee9d1f9e282 31 lcd.printString("High Score",12,4);
evanso 76:6daba3002424 32 lcd.refresh();
evanso 76:6daba3002424 33 }
evanso 76:6daba3002424 34
evanso 76:6daba3002424 35 void HighScore::save_new_high_score(SDFileSystem &sd, N5110 &lcd,
evanso 76:6daba3002424 36 int new_high_score){
evanso 76:6daba3002424 37 FILE *fp;
evanso 76:6daba3002424 38
evanso 76:6daba3002424 39 //overwirtes previous high score
evanso 77:2ee9d1f9e282 40 fp = fopen("/sd/HighScore.csv", "w");
evanso 76:6daba3002424 41
evanso 76:6daba3002424 42
evanso 76:6daba3002424 43 if (fp == NULL) {
evanso 76:6daba3002424 44 error_open_file(lcd);
evanso 76:6daba3002424 45
evanso 76:6daba3002424 46 }else{
evanso 76:6daba3002424 47
evanso 76:6daba3002424 48 //Adda data to file if no error
evanso 76:6daba3002424 49 fprintf(fp, "%d", new_high_score);
evanso 76:6daba3002424 50 fclose(fp);
evanso 76:6daba3002424 51 }
evanso 76:6daba3002424 52 }
evanso 76:6daba3002424 53
evanso 76:6daba3002424 54 int HighScore::read_high_score(SDFileSystem &sd){
evanso 76:6daba3002424 55 FILE *fp;
evanso 76:6daba3002424 56 int saved_high_score = 0;
evanso 76:6daba3002424 57
evanso 76:6daba3002424 58 fp = fopen("/sd/HighScore.csv", "r");
evanso 76:6daba3002424 59
evanso 76:6daba3002424 60 //check if highscore game files
evanso 76:6daba3002424 61 if (fp == NULL) {
evanso 76:6daba3002424 62 error_ = true;
evanso 76:6daba3002424 63
evanso 76:6daba3002424 64 //Reads current high score if no high score is set zero is returned
evanso 76:6daba3002424 65 }else{
evanso 76:6daba3002424 66
evanso 76:6daba3002424 67 //read save file and add values to saved_high_score int
evanso 76:6daba3002424 68 fscanf(fp, "%d", &saved_high_score);
evanso 76:6daba3002424 69
evanso 76:6daba3002424 70 fclose(fp);
evanso 76:6daba3002424 71 }
evanso 76:6daba3002424 72
evanso 76:6daba3002424 73 return saved_high_score;
evanso 76:6daba3002424 74 }
evanso 76:6daba3002424 75
evanso 76:6daba3002424 76 bool HighScore::get_error(){
evanso 76:6daba3002424 77 return error_;
evanso 76:6daba3002424 78 }
evanso 76:6daba3002424 79
evanso 76:6daba3002424 80
evanso 76:6daba3002424 81 void HighScore::set_error(bool error){
evanso 76:6daba3002424 82 error_ = error;
evanso 76:6daba3002424 83 }