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 15:13:47 2020 +0000
Revision:
48:e308067cfea5
Added sd card class folder to project folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 48:e308067cfea5 1 /* mbed Microcontroller Library - MemFileSystem
evanso 48:e308067cfea5 2 * Copyright (c) 2008, sford
evanso 48:e308067cfea5 3 */
evanso 48:e308067cfea5 4
evanso 48:e308067cfea5 5
evanso 48:e308067cfea5 6 #ifndef MBED_MEMFILESYSTEM_H
evanso 48:e308067cfea5 7 #define MBED_MEMFILESYSTEM_H
evanso 48:e308067cfea5 8
evanso 48:e308067cfea5 9 #include "FATFileSystem.h"
evanso 48:e308067cfea5 10
evanso 48:e308067cfea5 11 namespace mbed
evanso 48:e308067cfea5 12 {
evanso 48:e308067cfea5 13
evanso 48:e308067cfea5 14 class MemFileSystem : public FATFileSystem
evanso 48:e308067cfea5 15 {
evanso 48:e308067cfea5 16 public:
evanso 48:e308067cfea5 17
evanso 48:e308067cfea5 18 // 2000 sectors, each 512 bytes (malloced as required)
evanso 48:e308067cfea5 19 char *sectors[2000];
evanso 48:e308067cfea5 20
evanso 48:e308067cfea5 21 MemFileSystem(const char* name) : FATFileSystem(name) {
evanso 48:e308067cfea5 22 memset(sectors, 0, sizeof(sectors));
evanso 48:e308067cfea5 23 }
evanso 48:e308067cfea5 24
evanso 48:e308067cfea5 25 virtual ~MemFileSystem() {
evanso 48:e308067cfea5 26 for(int i = 0; i < 2000; i++) {
evanso 48:e308067cfea5 27 if(sectors[i]) {
evanso 48:e308067cfea5 28 free(sectors[i]);
evanso 48:e308067cfea5 29 }
evanso 48:e308067cfea5 30 }
evanso 48:e308067cfea5 31 }
evanso 48:e308067cfea5 32
evanso 48:e308067cfea5 33 // read a sector in to the buffer, return 0 if ok
evanso 48:e308067cfea5 34 virtual int disk_read(char *buffer, int sector) {
evanso 48:e308067cfea5 35 if(sectors[sector] == 0) {
evanso 48:e308067cfea5 36 // nothing allocated means sector is empty
evanso 48:e308067cfea5 37 memset(buffer, 0, 512);
evanso 48:e308067cfea5 38 } else {
evanso 48:e308067cfea5 39 memcpy(buffer, sectors[sector], 512);
evanso 48:e308067cfea5 40 }
evanso 48:e308067cfea5 41 return 0;
evanso 48:e308067cfea5 42 }
evanso 48:e308067cfea5 43
evanso 48:e308067cfea5 44 // write a sector from the buffer, return 0 if ok
evanso 48:e308067cfea5 45 virtual int disk_write(const char *buffer, int sector) {
evanso 48:e308067cfea5 46 // if buffer is zero deallocate sector
evanso 48:e308067cfea5 47 char zero[512];
evanso 48:e308067cfea5 48 memset(zero, 0, 512);
evanso 48:e308067cfea5 49 if(memcmp(zero, buffer, 512)==0) {
evanso 48:e308067cfea5 50 if(sectors[sector] != 0) {
evanso 48:e308067cfea5 51 free(sectors[sector]);
evanso 48:e308067cfea5 52 sectors[sector] = 0;
evanso 48:e308067cfea5 53 }
evanso 48:e308067cfea5 54 return 0;
evanso 48:e308067cfea5 55 }
evanso 48:e308067cfea5 56 // else allocate a sector if needed, and write
evanso 48:e308067cfea5 57 if(sectors[sector] == 0) {
evanso 48:e308067cfea5 58 char *sec = (char*)malloc(512);
evanso 48:e308067cfea5 59 if(sec==0) {
evanso 48:e308067cfea5 60 return 1; // out of memory
evanso 48:e308067cfea5 61 }
evanso 48:e308067cfea5 62 sectors[sector] = sec;
evanso 48:e308067cfea5 63 }
evanso 48:e308067cfea5 64 memcpy(sectors[sector], buffer, 512);
evanso 48:e308067cfea5 65 return 0;
evanso 48:e308067cfea5 66 }
evanso 48:e308067cfea5 67
evanso 48:e308067cfea5 68 // return the number of sectors
evanso 48:e308067cfea5 69 virtual int disk_sectors() {
evanso 48:e308067cfea5 70 return sizeof(sectors)/sizeof(sectors[0]);
evanso 48:e308067cfea5 71 }
evanso 48:e308067cfea5 72
evanso 48:e308067cfea5 73 };
evanso 48:e308067cfea5 74
evanso 48:e308067cfea5 75 }
evanso 48:e308067cfea5 76
evanso 48:e308067cfea5 77 #endif