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 May 27 02:06:05 2020 +0000
Revision:
87:832ca78426b5
Parent:
48:e308067cfea5
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 48:e308067cfea5 1 /* mbed Microcontroller Library
evanso 48:e308067cfea5 2 * Copyright (c) 2006-2012 ARM Limited
evanso 48:e308067cfea5 3 *
evanso 48:e308067cfea5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
evanso 48:e308067cfea5 5 * of this software and associated documentation files (the "Software"), to deal
evanso 48:e308067cfea5 6 * in the Software without restriction, including without limitation the rights
evanso 48:e308067cfea5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
evanso 48:e308067cfea5 8 * copies of the Software, and to permit persons to whom the Software is
evanso 48:e308067cfea5 9 * furnished to do so, subject to the following conditions:
evanso 48:e308067cfea5 10 *
evanso 48:e308067cfea5 11 * The above copyright notice and this permission notice shall be included in
evanso 48:e308067cfea5 12 * all copies or substantial portions of the Software.
evanso 48:e308067cfea5 13 *
evanso 48:e308067cfea5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
evanso 48:e308067cfea5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
evanso 48:e308067cfea5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
evanso 48:e308067cfea5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
evanso 48:e308067cfea5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
evanso 48:e308067cfea5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
evanso 48:e308067cfea5 20 * SOFTWARE.
evanso 48:e308067cfea5 21 */
evanso 48:e308067cfea5 22 #include "ff.h"
evanso 48:e308067cfea5 23 #include "ffconf.h"
evanso 48:e308067cfea5 24 #include "mbed_debug.h"
evanso 48:e308067cfea5 25
evanso 48:e308067cfea5 26 #include "FATFileHandle.h"
evanso 48:e308067cfea5 27
evanso 48:e308067cfea5 28 FATFileHandle::FATFileHandle(FIL fh) {
evanso 48:e308067cfea5 29 _fh = fh;
evanso 48:e308067cfea5 30 }
evanso 48:e308067cfea5 31
evanso 48:e308067cfea5 32 int FATFileHandle::close() {
evanso 48:e308067cfea5 33 int retval = f_close(&_fh);
evanso 48:e308067cfea5 34 delete this;
evanso 48:e308067cfea5 35 return retval;
evanso 48:e308067cfea5 36 }
evanso 48:e308067cfea5 37
evanso 48:e308067cfea5 38 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
evanso 48:e308067cfea5 39 UINT n;
evanso 48:e308067cfea5 40 FRESULT res = f_write(&_fh, buffer, length, &n);
evanso 48:e308067cfea5 41 if (res) {
evanso 48:e308067cfea5 42 debug_if(FFS_DBG, "f_write() failed: %d", res);
evanso 48:e308067cfea5 43 return -1;
evanso 48:e308067cfea5 44 }
evanso 48:e308067cfea5 45 return n;
evanso 48:e308067cfea5 46 }
evanso 48:e308067cfea5 47
evanso 48:e308067cfea5 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
evanso 48:e308067cfea5 49 debug_if(FFS_DBG, "read(%d)\n", length);
evanso 48:e308067cfea5 50 UINT n;
evanso 48:e308067cfea5 51 FRESULT res = f_read(&_fh, buffer, length, &n);
evanso 48:e308067cfea5 52 if (res) {
evanso 48:e308067cfea5 53 debug_if(FFS_DBG, "f_read() failed: %d\n", res);
evanso 48:e308067cfea5 54 return -1;
evanso 48:e308067cfea5 55 }
evanso 48:e308067cfea5 56 return n;
evanso 48:e308067cfea5 57 }
evanso 48:e308067cfea5 58
evanso 48:e308067cfea5 59 int FATFileHandle::isatty() {
evanso 48:e308067cfea5 60 return 0;
evanso 48:e308067cfea5 61 }
evanso 48:e308067cfea5 62
evanso 48:e308067cfea5 63 off_t FATFileHandle::lseek(off_t position, int whence) {
evanso 48:e308067cfea5 64 if (whence == SEEK_END) {
evanso 48:e308067cfea5 65 position += _fh.fsize;
evanso 48:e308067cfea5 66 } else if(whence==SEEK_CUR) {
evanso 48:e308067cfea5 67 position += _fh.fptr;
evanso 48:e308067cfea5 68 }
evanso 48:e308067cfea5 69 FRESULT res = f_lseek(&_fh, position);
evanso 48:e308067cfea5 70 if (res) {
evanso 48:e308067cfea5 71 debug_if(FFS_DBG, "lseek failed: %d\n", res);
evanso 48:e308067cfea5 72 return -1;
evanso 48:e308067cfea5 73 } else {
evanso 48:e308067cfea5 74 debug_if(FFS_DBG, "lseek OK, returning %i\n", _fh.fptr);
evanso 48:e308067cfea5 75 return _fh.fptr;
evanso 48:e308067cfea5 76 }
evanso 48:e308067cfea5 77 }
evanso 48:e308067cfea5 78
evanso 48:e308067cfea5 79 int FATFileHandle::fsync() {
evanso 48:e308067cfea5 80 FRESULT res = f_sync(&_fh);
evanso 48:e308067cfea5 81 if (res) {
evanso 48:e308067cfea5 82 debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
evanso 48:e308067cfea5 83 return -1;
evanso 48:e308067cfea5 84 }
evanso 48:e308067cfea5 85 return 0;
evanso 48:e308067cfea5 86 }
evanso 48:e308067cfea5 87
evanso 48:e308067cfea5 88 off_t FATFileHandle::flen() {
evanso 48:e308067cfea5 89 return _fh.fsize;
evanso 48:e308067cfea5 90 }