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.

Alien/Alien_test.h

Committer:
evanso
Date:
2020-05-27
Revision:
87:832ca78426b5
Parent:
85:87bc28b151d8

File content as of revision 87:832ca78426b5:

#ifndef ALIEN_TEST_H
#define ALIEN_TEST_H

/** Alien Test
 * @brief Checks that the alien draws, moves and detects collisions
 * @author Benjamin Evans, University of Leeds
 * @date May 2020
 * @return true if test are passed 
 */
bool check_collision_test(bool expected_collision, bool bullet_direction,
int position_x_bullet,int position_y_bullet) {
    // Objects required for test 
    Alien alien;
    Weapons bullet;
    Gamepad pad;
    
    // Initialise alien in start position of 10, 22 
    alien.init(pad,10,22); 
    
    printf("collision =  %s : " ,expected_collision ? "true" : "false");
    
    // Set bullet direction and position 
    Vector2D pos = {position_x_bullet,position_y_bullet};
    bullet.set_pos_one(pos);
    bullet.set_direction(bullet_direction);
    
    // Checks collision function
    bool actual_collision = alien.check_collision(bullet);
    
    // Checks if collision is expected 
    if (actual_collision == expected_collision) {
        printf ( "Passed!\n");
        return true;
    } else {
        printf ("Failed! value = %s (expecting  %d)\n", 
        actual_collision ? "true" : "false", 
        expected_collision ? "true" : "false");
        return false;
    } 
}

bool alien_draw_test(int expected_pixel_status,Direction direction, 
int expected_x, int expected_y) {
    // Objects required for test 
    Gamepad pad;
    Spaceship spaceship;
    Alien alien;
    N5110 lcd;
    Map map;
    Direction d_;
    d_ = direction;
   
    
    // Initialise alien to set start position 10,23
    pad.init();
    alien.init(pad,expected_x, expected_y); 
    spaceship.init();

    printf("draw_alien = %d,%d  ", expected_x, expected_y);
    
    // Draws alien
    alien.draw_alien(lcd,spaceship.get_pos(),d_, map.get_length_map(), 
    map.get_position_x_map(), false);
    
    // Gets the alien_pos as it is random
    Vector2D alien_pos = alien.get_pos();
    int actual_x = alien_pos.x;
    int actual_y = alien_pos.y;
  
   // Reads middle pixel of alien where it is expected to be drawn 
    int actual_pixel_status = lcd.getPixel(actual_x + 3, 
    actual_y);
    
     // Checks if pixel is drawn and therefor testing if it has gone of screen
    if (actual_pixel_status == expected_pixel_status) {
        printf ( "Passed!\n");
        return true;
    } else {
        printf ( "Failed! value = %d  (expecting  %d)\n", actual_pixel_status, 
        expected_pixel_status);
        return false;
        
    }
}

#endif