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 22:053c11a202e1 1 #ifndef ALIEN_TEST_H
evanso 22:053c11a202e1 2 #define ALIEN_TEST_H
evanso 22:053c11a202e1 3
evanso 22:053c11a202e1 4 /** Alien Test
evanso 27:8bb2bd97c319 5 * @brief Checks that the alien draws, moves and detects collisions
evanso 27:8bb2bd97c319 6 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 7 * @date May 2020
evanso 27:8bb2bd97c319 8 * @return true if test are passed
evanso 27:8bb2bd97c319 9 */
evanso 38:75bd968daa31 10 bool check_collision_test(bool expected_collision, bool bullet_direction,
evanso 82:3211b31e9421 11 int position_x_bullet,int position_y_bullet) {
evanso 85:87bc28b151d8 12 // Objects required for test
evanso 22:053c11a202e1 13 Alien alien;
evanso 22:053c11a202e1 14 Weapons bullet;
evanso 26:1a7056eb3253 15 Gamepad pad;
evanso 22:053c11a202e1 16
evanso 85:87bc28b151d8 17 // Initialise alien in start position of 10, 22
evanso 37:a05eac7fcb4c 18 alien.init(pad,10,22);
evanso 22:053c11a202e1 19
evanso 22:053c11a202e1 20 printf("collision = %s : " ,expected_collision ? "true" : "false");
evanso 22:053c11a202e1 21
evanso 85:87bc28b151d8 22 // Set bullet direction and position
evanso 22:053c11a202e1 23 Vector2D pos = {position_x_bullet,position_y_bullet};
evanso 22:053c11a202e1 24 bullet.set_pos_one(pos);
evanso 22:053c11a202e1 25 bullet.set_direction(bullet_direction);
evanso 22:053c11a202e1 26
evanso 22:053c11a202e1 27 // Checks collision function
evanso 22:053c11a202e1 28 bool actual_collision = alien.check_collision(bullet);
evanso 22:053c11a202e1 29
evanso 85:87bc28b151d8 30 // Checks if collision is expected
evanso 22:053c11a202e1 31 if (actual_collision == expected_collision) {
evanso 22:053c11a202e1 32 printf ( "Passed!\n");
evanso 22:053c11a202e1 33 return true;
evanso 22:053c11a202e1 34 } else {
evanso 27:8bb2bd97c319 35 printf ("Failed! value = %s (expecting %d)\n",
evanso 27:8bb2bd97c319 36 actual_collision ? "true" : "false",
evanso 27:8bb2bd97c319 37 expected_collision ? "true" : "false");
evanso 22:053c11a202e1 38 return false;
evanso 22:053c11a202e1 39 }
evanso 22:053c11a202e1 40 }
evanso 22:053c11a202e1 41
evanso 37:a05eac7fcb4c 42 bool alien_draw_test(int expected_pixel_status,Direction direction,
evanso 82:3211b31e9421 43 int expected_x, int expected_y) {
evanso 85:87bc28b151d8 44 // Objects required for test
evanso 22:053c11a202e1 45 Gamepad pad;
evanso 37:a05eac7fcb4c 46 Spaceship spaceship;
evanso 22:053c11a202e1 47 Alien alien;
evanso 22:053c11a202e1 48 N5110 lcd;
evanso 26:1a7056eb3253 49 Map map;
evanso 26:1a7056eb3253 50 Direction d_;
evanso 37:a05eac7fcb4c 51 d_ = direction;
evanso 37:a05eac7fcb4c 52
evanso 22:053c11a202e1 53
evanso 85:87bc28b151d8 54 // Initialise alien to set start position 10,23
evanso 22:053c11a202e1 55 pad.init();
evanso 37:a05eac7fcb4c 56 alien.init(pad,expected_x, expected_y);
evanso 22:053c11a202e1 57 spaceship.init();
evanso 37:a05eac7fcb4c 58
evanso 37:a05eac7fcb4c 59 printf("draw_alien = %d,%d ", expected_x, expected_y);
evanso 22:053c11a202e1 60
evanso 37:a05eac7fcb4c 61 // Draws alien
evanso 37:a05eac7fcb4c 62 alien.draw_alien(lcd,spaceship.get_pos(),d_, map.get_length_map(),
evanso 37:a05eac7fcb4c 63 map.get_position_x_map(), false);
evanso 22:053c11a202e1 64
evanso 82:3211b31e9421 65 // Gets the alien_pos as it is random
evanso 37:a05eac7fcb4c 66 Vector2D alien_pos = alien.get_pos();
evanso 37:a05eac7fcb4c 67 int actual_x = alien_pos.x;
evanso 37:a05eac7fcb4c 68 int actual_y = alien_pos.y;
evanso 37:a05eac7fcb4c 69
evanso 37:a05eac7fcb4c 70 // Reads middle pixel of alien where it is expected to be drawn
evanso 37:a05eac7fcb4c 71 int actual_pixel_status = lcd.getPixel(actual_x + 3,
evanso 37:a05eac7fcb4c 72 actual_y);
evanso 22:053c11a202e1 73
evanso 37:a05eac7fcb4c 74 // Checks if pixel is drawn and therefor testing if it has gone of screen
evanso 37:a05eac7fcb4c 75 if (actual_pixel_status == expected_pixel_status) {
evanso 22:053c11a202e1 76 printf ( "Passed!\n");
evanso 22:053c11a202e1 77 return true;
evanso 22:053c11a202e1 78 } else {
evanso 37:a05eac7fcb4c 79 printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status,
evanso 37:a05eac7fcb4c 80 expected_pixel_status);
evanso 22:053c11a202e1 81 return false;
evanso 37:a05eac7fcb4c 82
evanso 37:a05eac7fcb4c 83 }
evanso 22:053c11a202e1 84 }
evanso 22:053c11a202e1 85
evanso 85:87bc28b151d8 86 #endif