Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Alien_test.h Source File

Alien_test.h

00001 #ifndef ALIEN_TEST_H
00002 #define ALIEN_TEST_H
00003 
00004 /** Alien Test
00005  * @brief Checks that the alien draws, moves and detects collisions
00006  * @author Benjamin Evans, University of Leeds
00007  * @date May 2020
00008  * @return true if test are passed 
00009  */
00010 bool check_collision_test(bool expected_collision, bool bullet_direction,
00011 int position_x_bullet,int position_y_bullet) {
00012     // Objects required for test 
00013     Alien alien;
00014     Weapons bullet;
00015     Gamepad pad;
00016     
00017     // Initialise alien in start position of 10, 22 
00018     alien.init(pad,10,22); 
00019     
00020     printf("collision =  %s : " ,expected_collision ? "true" : "false");
00021     
00022     // Set bullet direction and position 
00023     Vector2D pos = {position_x_bullet,position_y_bullet};
00024     bullet.set_pos_one(pos);
00025     bullet.set_direction(bullet_direction);
00026     
00027     // Checks collision function
00028     bool actual_collision = alien.check_collision(bullet);
00029     
00030     // Checks if collision is expected 
00031     if (actual_collision == expected_collision) {
00032         printf ( "Passed!\n");
00033         return true;
00034     } else {
00035         printf ("Failed! value = %s (expecting  %d)\n", 
00036         actual_collision ? "true" : "false", 
00037         expected_collision ? "true" : "false");
00038         return false;
00039     } 
00040 }
00041 
00042 bool alien_draw_test(int expected_pixel_status,Direction direction, 
00043 int expected_x, int expected_y) {
00044     // Objects required for test 
00045     Gamepad pad;
00046     Spaceship spaceship;
00047     Alien alien;
00048     N5110 lcd;
00049     Map map;
00050     Direction d_;
00051     d_ = direction;
00052    
00053     
00054     // Initialise alien to set start position 10,23
00055     pad.init();
00056     alien.init(pad,expected_x, expected_y); 
00057     spaceship.init();
00058 
00059     printf("draw_alien = %d,%d  ", expected_x, expected_y);
00060     
00061     // Draws alien
00062     alien.draw_alien(lcd,spaceship.get_pos(),d_, map.get_length_map(), 
00063     map.get_position_x_map(), false);
00064     
00065     // Gets the alien_pos as it is random
00066     Vector2D alien_pos = alien.get_pos();
00067     int actual_x = alien_pos.x;
00068     int actual_y = alien_pos.y;
00069   
00070    // Reads middle pixel of alien where it is expected to be drawn 
00071     int actual_pixel_status = lcd.getPixel(actual_x + 3, 
00072     actual_y);
00073     
00074      // Checks if pixel is drawn and therefor testing if it has gone of screen
00075     if (actual_pixel_status == expected_pixel_status) {
00076         printf ( "Passed!\n");
00077         return true;
00078     } else {
00079         printf ( "Failed! value = %d  (expecting  %d)\n", actual_pixel_status, 
00080         expected_pixel_status);
00081         return false;
00082         
00083     }
00084 }
00085 
00086 #endif