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:
Fri May 15 12:05:33 2020 +0000
Revision:
34:85ccc16f24d2
Parent:
33:7fedd8029473
Child:
35:577c65bf914e
Added when aliens collide with people, the people are abducted to the top of the screen. Then that alien tracks the spaceship and moves towards it rather than randomly moving.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 19:1bc0a2d22054 1 #ifndef ALIEN_H
evanso 19:1bc0a2d22054 2 #define ALIEN_H
evanso 19:1bc0a2d22054 3
evanso 27:8bb2bd97c319 4 // Included libraries ----------------------------------------------------------
evanso 19:1bc0a2d22054 5 #include "mbed.h"
evanso 19:1bc0a2d22054 6 #include "N5110.h"
evanso 19:1bc0a2d22054 7 #include "Gamepad.h"
evanso 20:febd920ec29e 8 #include "Weapons.h"
evanso 28:a5958497d5ce 9 #include "RandomMovement.h"
evanso 19:1bc0a2d22054 10
evanso 20:febd920ec29e 11 /** Alien class
evanso 27:8bb2bd97c319 12 * @brief Draws and moves aliens
evanso 27:8bb2bd97c319 13 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 14 * @date May 2020
evanso 27:8bb2bd97c319 15 */
evanso 31:6015e8ed859c 16 class Alien: public RandomMovement {
evanso 19:1bc0a2d22054 17 public:
evanso 19:1bc0a2d22054 18 /** Constructor */
evanso 19:1bc0a2d22054 19 Alien();
evanso 19:1bc0a2d22054 20
evanso 19:1bc0a2d22054 21 /** Destructor */
evanso 19:1bc0a2d22054 22 ~Alien();
evanso 19:1bc0a2d22054 23
evanso 32:c006a9882778 24 /** Initalises Alien
evanso 32:c006a9882778 25 * @param position_x_start @details Random x start pos of alien
evanso 32:c006a9882778 26 * @param position_y_start @details Random y start pos of alien
evanso 32:c006a9882778 27 */
evanso 32:c006a9882778 28 void init(Gamepad &pad, int position_x_start, int position_y_start);
evanso 20:febd920ec29e 29
evanso 20:febd920ec29e 30 /** Draws the alien
evanso 27:8bb2bd97c319 31 * @param lcd @details N5110 object
evanso 27:8bb2bd97c319 32 * @param spaceship_pos @details xy spaceship position
evanso 27:8bb2bd97c319 33 * @param d_ @details Direction of joystick
evanso 27:8bb2bd97c319 34 * @param map_length_ @details length of map
evanso 27:8bb2bd97c319 35 * @param position_x_map_ @details x position of map
evanso 20:febd920ec29e 36 */
evanso 27:8bb2bd97c319 37 void draw_alien(N5110 &lcd, Vector2D spaceship_pos, Direction d_,
evanso 34:85ccc16f24d2 38 int map_length_, int position_x_map_, bool alien_collision);
evanso 19:1bc0a2d22054 39
evanso 20:febd920ec29e 40 /** Checks if bullet collides with a alien
evanso 27:8bb2bd97c319 41 * @param bullet @details Weapons object
evanso 20:febd920ec29e 42 */
evanso 20:febd920ec29e 43 bool check_collision(Weapons bullet);
evanso 19:1bc0a2d22054 44
evanso 21:f7d7834e3af1 45 // Accessors and mutators --------------------------------------------------
evanso 20:febd920ec29e 46
evanso 31:6015e8ed859c 47 /** Gets the counter for alien time to fire
evanso 31:6015e8ed859c 48 * @return alien_fire_counter_
evanso 22:053c11a202e1 49 */
evanso 31:6015e8ed859c 50 int get_alien_fire_counter();
evanso 28:a5958497d5ce 51
evanso 33:7fedd8029473 52 /** sets the position_x_ of alien
evanso 33:7fedd8029473 53 * @param position_x
evanso 33:7fedd8029473 54 */
evanso 33:7fedd8029473 55 void set_alien_x_pos(int position_x);
evanso 33:7fedd8029473 56
evanso 34:85ccc16f24d2 57 /** sets the collision_people_element number
evanso 34:85ccc16f24d2 58 * @param people_element
evanso 34:85ccc16f24d2 59 */
evanso 34:85ccc16f24d2 60 void set_collision_people_element(int people_element);
evanso 34:85ccc16f24d2 61
evanso 34:85ccc16f24d2 62 /** Gets the the collision_people_element number
evanso 34:85ccc16f24d2 63 * @return collision_people_element
evanso 34:85ccc16f24d2 64 */
evanso 34:85ccc16f24d2 65 int get_collision_people_element();
evanso 34:85ccc16f24d2 66
evanso 34:85ccc16f24d2 67 /** sets alien track_flag
evanso 34:85ccc16f24d2 68 * @param track_flag_
evanso 34:85ccc16f24d2 69 */
evanso 34:85ccc16f24d2 70 void set_track_flag(bool track_flag);
evanso 34:85ccc16f24d2 71
evanso 19:1bc0a2d22054 72 private:
evanso 19:1bc0a2d22054 73 // Function prototypes -----------------------------------------------------
evanso 21:f7d7834e3af1 74
evanso 21:f7d7834e3af1 75 /** Moves the alien towards the spaceship and around the map
evanso 21:f7d7834e3af1 76 * @param spaceship_pos @details : Position of the spaceship
evanso 21:f7d7834e3af1 77 */
evanso 24:479da6ca0e7e 78 void move_hunt_mode(Vector2D spaceship_pos);
evanso 19:1bc0a2d22054 79
evanso 27:8bb2bd97c319 80 /** Stops the alien from moving off the edge of the map and moves alien
evanso 27:8bb2bd97c319 81 * if the map loops
evanso 24:479da6ca0e7e 82 * @param map_length_@details : length of the map
evanso 27:8bb2bd97c319 83 * @param position_x_map_ @detials : the drawing start posisiton of the
evanso 27:8bb2bd97c319 84 * map
evanso 24:479da6ca0e7e 85 */
evanso 24:479da6ca0e7e 86 void off_screen_x_y_checker(int map_length_, int position_x_map_);
evanso 24:479da6ca0e7e 87
evanso 19:1bc0a2d22054 88 // Variables ---------------------------------------------------------------
evanso 19:1bc0a2d22054 89
evanso 27:8bb2bd97c319 90 /** Alien movement counter */
evanso 28:a5958497d5ce 91 int alien_move_counter_;
evanso 28:a5958497d5ce 92
evanso 28:a5958497d5ce 93 /** Alien fire bullet counter */
evanso 34:85ccc16f24d2 94 int alien_fire_counter_;
evanso 34:85ccc16f24d2 95
evanso 34:85ccc16f24d2 96 /** People element that alien as collided with */
evanso 34:85ccc16f24d2 97 int collision_people_element_;
evanso 34:85ccc16f24d2 98
evanso 34:85ccc16f24d2 99 /** Alien abducted people and now track spacehsip flag */
evanso 34:85ccc16f24d2 100 bool track_flag_;
evanso 28:a5958497d5ce 101
evanso 19:1bc0a2d22054 102 };
evanso 19:1bc0a2d22054 103
evanso 19:1bc0a2d22054 104 #endif