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:
85:87bc28b151d8
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 33:7fedd8029473 1 #include "People.h"
evanso 33:7fedd8029473 2
evanso 85:87bc28b151d8 3 // Constant Definitions
evanso 82:3211b31e9421 4 #define SPRITE_X_LENGTH 4
evanso 82:3211b31e9421 5 #define SPRITE_Y_LENGTH 5
evanso 82:3211b31e9421 6 #define STARTING_Y_POS 42
evanso 82:3211b31e9421 7
evanso 82:3211b31e9421 8 const int k_people_sprite[SPRITE_Y_LENGTH][SPRITE_X_LENGTH] = {
evanso 33:7fedd8029473 9 { 0,1,1,0,},
evanso 33:7fedd8029473 10 { 1,1,1,1,},
evanso 33:7fedd8029473 11 { 1,1,1,1,},
evanso 33:7fedd8029473 12 { 0,1,1,0,},
evanso 33:7fedd8029473 13 { 0,1,1,0,},
evanso 33:7fedd8029473 14 };
evanso 33:7fedd8029473 15
evanso 33:7fedd8029473 16 People::People() {
evanso 33:7fedd8029473 17
evanso 33:7fedd8029473 18 }
evanso 33:7fedd8029473 19
evanso 33:7fedd8029473 20 People::~People() {
evanso 33:7fedd8029473 21
evanso 33:7fedd8029473 22 }
evanso 33:7fedd8029473 23
evanso 33:7fedd8029473 24 void People::init(Gamepad &pad, int position_x_start) {
evanso 36:27aa597db3d2 25 // Define variables
evanso 82:3211b31e9421 26 sprite_x_length = SPRITE_X_LENGTH;
evanso 82:3211b31e9421 27 sprite_y_length = SPRITE_Y_LENGTH;
evanso 33:7fedd8029473 28 position_x_ = position_x_start;
evanso 82:3211b31e9421 29 position_y_ = STARTING_Y_POS;
evanso 34:85ccc16f24d2 30 alien_collision_flag = false;
evanso 34:85ccc16f24d2 31 people_move_counter_ = 0;
evanso 34:85ccc16f24d2 32 random_move_counter_ = 0;
evanso 33:7fedd8029473 33 }
evanso 33:7fedd8029473 34
evanso 34:85ccc16f24d2 35 void People::draw_people(N5110 &lcd, Direction d_, int map_length_,
evanso 82:3211b31e9421 36 int position_x_map_) {
evanso 34:85ccc16f24d2 37 position_x_ += calc_sprite_movement(d_);
evanso 82:3211b31e9421 38 lcd.drawSprite(position_x_, position_y_, SPRITE_Y_LENGTH, SPRITE_X_LENGTH,
evanso 82:3211b31e9421 39 (int*)k_people_sprite);
evanso 34:85ccc16f24d2 40 off_screen_x_y_checker(map_length_, position_x_map_);
evanso 34:85ccc16f24d2 41
evanso 82:3211b31e9421 42 // Move alien to top of screen if collision with alien
evanso 36:27aa597db3d2 43 collision_with_alien();
evanso 36:27aa597db3d2 44
evanso 34:85ccc16f24d2 45 people_move_counter_++;
evanso 34:85ccc16f24d2 46 }
evanso 34:85ccc16f24d2 47
evanso 82:3211b31e9421 48 void People::collision_with_alien() {
evanso 82:3211b31e9421 49 if(alien_collision_flag && !alien_track) {
evanso 85:87bc28b151d8 50 // People move on there own but at half speed of spaceship
evanso 36:27aa597db3d2 51 if (people_move_counter_%2 == 0) {
evanso 82:3211b31e9421 52 if (random_move_counter_ == 0) {
evanso 82:3211b31e9421 53 // Move alien to top of screen
evanso 36:27aa597db3d2 54 random_direction_ = 6;
evanso 36:27aa597db3d2 55 random_move_counter_ = 43;
evanso 36:27aa597db3d2 56 }
evanso 36:27aa597db3d2 57
evanso 85:87bc28b151d8 58 // Move people
evanso 36:27aa597db3d2 59 move_direction();
evanso 36:27aa597db3d2 60 random_move_counter_ --;
evanso 36:27aa597db3d2 61 }
evanso 36:27aa597db3d2 62 }
evanso 36:27aa597db3d2 63 }
evanso 36:27aa597db3d2 64
evanso 82:3211b31e9421 65 void People::off_screen_x_y_checker(int map_length_, int position_x_map_) {
evanso 82:3211b31e9421 66 // Loops the people round if it reaches the end of the map
evanso 82:3211b31e9421 67 if(position_x_ <= (84 - map_length_)) {
evanso 34:85ccc16f24d2 68 position_x_ += map_length_;
evanso 82:3211b31e9421 69 }else if (position_x_ >= map_length_) {
evanso 34:85ccc16f24d2 70 position_x_ -= map_length_ + 10;
evanso 34:85ccc16f24d2 71 }
evanso 34:85ccc16f24d2 72 }
evanso 34:85ccc16f24d2 73
evanso 82:3211b31e9421 74 bool People::get_alien_collision_flag() {
evanso 34:85ccc16f24d2 75 return alien_collision_flag;
evanso 85:87bc28b151d8 76 }