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 06 11:24:22 2020 +0000
Revision:
22:053c11a202e1
Child:
26:1a7056eb3253
Now that the main code structure is finished for alien and weapons I can unit test those classes. Added a unit test for the alien class and it passed!

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 22:053c11a202e1 5 @brief Checks that the alien draws, moves and detects collisions
evanso 22:053c11a202e1 6 @author Benjamin Evans, University of Leeds
evanso 22:053c11a202e1 7 @date May 2020
evanso 22:053c11a202e1 8 @return true if test are passed
evanso 22:053c11a202e1 9 */
evanso 22:053c11a202e1 10
evanso 22:053c11a202e1 11 bool alien_collision_test(bool expected_collision, bool bullet_direction,int position_x_bullet,int position_y_bullet){
evanso 22:053c11a202e1 12 // Objects reqired for test
evanso 22:053c11a202e1 13 Alien alien;
evanso 22:053c11a202e1 14 Weapons bullet;
evanso 22:053c11a202e1 15
evanso 22:053c11a202e1 16 // Initialise alien in start postion of 10, 22
evanso 22:053c11a202e1 17 alien.init();
evanso 22:053c11a202e1 18
evanso 22:053c11a202e1 19 printf("collision = %s : " ,expected_collision ? "true" : "false");
evanso 22:053c11a202e1 20
evanso 22:053c11a202e1 21 //set bullet direction and posisiton
evanso 22:053c11a202e1 22 Vector2D pos = {position_x_bullet,position_y_bullet};
evanso 22:053c11a202e1 23 bullet.set_pos_one(pos);
evanso 22:053c11a202e1 24 bullet.set_direction(bullet_direction);
evanso 22:053c11a202e1 25
evanso 22:053c11a202e1 26 // Checks collision function
evanso 22:053c11a202e1 27 bool actual_collision = alien.check_collision(bullet);
evanso 22:053c11a202e1 28
evanso 22:053c11a202e1 29 // Checks if collision is espected
evanso 22:053c11a202e1 30 if (actual_collision == expected_collision) {
evanso 22:053c11a202e1 31 printf ( "Passed!\n");
evanso 22:053c11a202e1 32 return true;
evanso 22:053c11a202e1 33 } else {
evanso 22:053c11a202e1 34 printf ("Failed! value = %s (expecting %d)\n", actual_collision ? "true" : "false", expected_collision ? "true" : "false");
evanso 22:053c11a202e1 35 return false;
evanso 22:053c11a202e1 36 }
evanso 22:053c11a202e1 37 }
evanso 22:053c11a202e1 38
evanso 22:053c11a202e1 39 bool alien_movement_test(Direction d_, int expected_x_move, int expected_y_move){
evanso 22:053c11a202e1 40 // Objects reqired for test
evanso 22:053c11a202e1 41 Gamepad pad;
evanso 22:053c11a202e1 42 Alien alien;
evanso 22:053c11a202e1 43 Spaceship spaceship;
evanso 22:053c11a202e1 44 N5110 lcd;
evanso 22:053c11a202e1 45
evanso 22:053c11a202e1 46 // Initialise alien in start postion of 10, 22
evanso 22:053c11a202e1 47 pad.init();
evanso 22:053c11a202e1 48 alien.init();
evanso 22:053c11a202e1 49 spaceship.init();
evanso 22:053c11a202e1 50
evanso 22:053c11a202e1 51 Vector2D start_postion = alien.get_pos();
evanso 22:053c11a202e1 52 int start_x_postion = start_postion.x;
evanso 22:053c11a202e1 53 int start_y_postion = start_postion.y;
evanso 22:053c11a202e1 54 printf("move_alien = %d,%d : ", start_x_postion + expected_x_move, start_y_postion + expected_y_move);
evanso 22:053c11a202e1 55
evanso 22:053c11a202e1 56 // Moves alien
evanso 22:053c11a202e1 57 alien.draw_alien(lcd, spaceship.get_pos(), d_);
evanso 22:053c11a202e1 58
evanso 22:053c11a202e1 59 //Reads finish alien positon
evanso 22:053c11a202e1 60 Vector2D finish_postion = alien.get_pos();
evanso 22:053c11a202e1 61
evanso 22:053c11a202e1 62 // Checks final position with espected
evanso 22:053c11a202e1 63 if (finish_postion.x == start_postion.x + expected_x_move && start_postion.y + expected_y_move) {
evanso 22:053c11a202e1 64 printf ( "Passed!\n");
evanso 22:053c11a202e1 65 return true;
evanso 22:053c11a202e1 66 } else {
evanso 22:053c11a202e1 67 int finish_x_postion = finish_postion.x ;
evanso 22:053c11a202e1 68 int finish_y_postion = finish_postion.y ;
evanso 22:053c11a202e1 69 printf ("Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, finish_y_postion, start_x_postion + expected_x_move, start_y_postion + expected_x_move);
evanso 22:053c11a202e1 70 return false;
evanso 22:053c11a202e1 71 }
evanso 22:053c11a202e1 72 }
evanso 22:053c11a202e1 73
evanso 22:053c11a202e1 74 #endif