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 26 19:38:48 2020 +0000
Revision:
85:87bc28b151d8
Parent:
82:3211b31e9421
Spell checked all of code and comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 36:27aa597db3d2 1 #include "CheckCollision.h"
evanso 36:27aa597db3d2 2
evanso 36:27aa597db3d2 3 bool CheckCollision::check_collision(Weapons bullet) {
evanso 36:27aa597db3d2 4 bool collision = false;
evanso 36:27aa597db3d2 5 Vector2D bullet_pos = bullet.get_pos();
evanso 82:3211b31e9421 6 // printf ("Collision 1 = %d\n", collision);
evanso 36:27aa597db3d2 7
evanso 82:3211b31e9421 8 // Checks collision if bullet is going in east direction
evanso 85:87bc28b151d8 9 if (bullet.get_direction()) {
evanso 82:3211b31e9421 10 // int bullet_pos_twox = bullet_pos.x;
evanso 82:3211b31e9421 11 // int bullet_pos_twoy = bullet_pos.y;
evanso 82:3211b31e9421 12 // printf ("alien x = %d, bullet x = %d\n", position_x_,bullet_pos_twox);
evanso 82:3211b31e9421 13 // printf ("alien y = %d, bullet y = %d\n", position_y_,bullet_pos_twoy);
evanso 36:27aa597db3d2 14
evanso 36:27aa597db3d2 15 // Collision if the bullet is inside of the xy ranges of sprite drawing
evanso 85:87bc28b151d8 16 if ((bullet_pos.x + 1) >= position_x_ &&
evanso 36:27aa597db3d2 17 (bullet_pos.x + 1) <= (position_x_ + sprite_x_length ) &&
evanso 36:27aa597db3d2 18 position_y_ <= bullet_pos.y &&
evanso 82:3211b31e9421 19 bullet_pos.y <= (position_y_ + sprite_y_length )) {
evanso 36:27aa597db3d2 20 collision = true;
evanso 36:27aa597db3d2 21 }
evanso 36:27aa597db3d2 22
evanso 82:3211b31e9421 23 // printf ("Collision 2 = %d\n", collision);
evanso 36:27aa597db3d2 24
evanso 82:3211b31e9421 25 // Checks collision if bullet is going in west direction
evanso 85:87bc28b151d8 26 }else if (!bullet.get_direction()) {
evanso 36:27aa597db3d2 27
evanso 85:87bc28b151d8 28 if (bullet_pos.x <= (position_x_ + sprite_x_length ) &&
evanso 36:27aa597db3d2 29 bullet_pos.x >= position_x_ &&
evanso 36:27aa597db3d2 30 position_y_ <= bullet_pos.y &&
evanso 82:3211b31e9421 31 bullet_pos.y <= (position_y_ + sprite_y_length )) {
evanso 36:27aa597db3d2 32 collision = true;
evanso 36:27aa597db3d2 33 }
evanso 36:27aa597db3d2 34
evanso 82:3211b31e9421 35 // printf ("Collision 3 = %d\n", collision);
evanso 36:27aa597db3d2 36 }
evanso 36:27aa597db3d2 37
evanso 82:3211b31e9421 38 // printf ("Collision 4 = %d\n", collision);
evanso 36:27aa597db3d2 39 return collision;
evanso 36:27aa597db3d2 40 }
evanso 36:27aa597db3d2 41