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:
Tue May 12 15:08:56 2020 +0000
Revision:
24:479da6ca0e7e
Parent:
22:053c11a202e1
Child:
25:70b55f5bfc87
Alien moves randomly and loops with the map when the spaceship get to the edge of the map. Alien also cant move off the map and can move towards the spaceship.

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 19:1bc0a2d22054 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 19:1bc0a2d22054 9
evanso 20:febd920ec29e 10 /** Alien class
evanso 20:febd920ec29e 11 @brief Draws and moves aliens
evanso 19:1bc0a2d22054 12 @author Benjamin Evans, University of Leeds
evanso 22:053c11a202e1 13 @date May 2020
evanso 19:1bc0a2d22054 14 */
evanso 19:1bc0a2d22054 15
evanso 19:1bc0a2d22054 16 class Alien {
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 19:1bc0a2d22054 24 /** Initalises Alien */
evanso 24:479da6ca0e7e 25 void init(Gamepad &pad);
evanso 20:febd920ec29e 26
evanso 20:febd920ec29e 27 /** Draws the alien
evanso 20:febd920ec29e 28 * @param lcd @details : N5110 object
evanso 20:febd920ec29e 29 */
evanso 24:479da6ca0e7e 30 void draw_alien(N5110 &lcd,Vector2D spaceship_pos,Direction d_, int map_length_, int position_x_map_);
evanso 19:1bc0a2d22054 31
evanso 20:febd920ec29e 32 /** Checks if bullet collides with a alien
evanso 20:febd920ec29e 33 * @param lcd @details : N5110 object
evanso 20:febd920ec29e 34 */
evanso 20:febd920ec29e 35 bool check_collision(Weapons bullet);
evanso 19:1bc0a2d22054 36
evanso 21:f7d7834e3af1 37 // Accessors and mutators --------------------------------------------------
evanso 20:febd920ec29e 38
evanso 22:053c11a202e1 39 /** Gets the xy position of the alien
evanso 22:053c11a202e1 40 * @returns position_x_alien_, position_x_alien_
evanso 22:053c11a202e1 41 */
evanso 22:053c11a202e1 42 Vector2D get_pos();
evanso 22:053c11a202e1 43
evanso 19:1bc0a2d22054 44 private:
evanso 19:1bc0a2d22054 45 // Function prototypes -----------------------------------------------------
evanso 21:f7d7834e3af1 46
evanso 21:f7d7834e3af1 47 /** Moves the alien towards the spaceship and around the map
evanso 21:f7d7834e3af1 48 * @param spaceship_pos @details : Position of the spaceship
evanso 21:f7d7834e3af1 49 */
evanso 24:479da6ca0e7e 50 void move_hunt_mode(Vector2D spaceship_pos);
evanso 21:f7d7834e3af1 51
evanso 21:f7d7834e3af1 52 /** Calulates the aliens movement depeding on spaceship positions and joystick input
evanso 21:f7d7834e3af1 53 * @param d_ @details : Direction object of joystick
evanso 21:f7d7834e3af1 54 * @retrun integer @details move alien value for alien draw function
evanso 21:f7d7834e3af1 55 */
evanso 21:f7d7834e3af1 56 int calc_alien_movement(Direction d_);
evanso 19:1bc0a2d22054 57
evanso 24:479da6ca0e7e 58 /** Generates the random move dirction and length for the alien*/
evanso 24:479da6ca0e7e 59 void set_random_move();
evanso 24:479da6ca0e7e 60
evanso 24:479da6ca0e7e 61 /** Gets the movement direction of the alien */
evanso 24:479da6ca0e7e 62 void move_direction();
evanso 24:479da6ca0e7e 63
evanso 24:479da6ca0e7e 64 /** Changes the x and y positions of the alien depeding on the movement direction
evanso 24:479da6ca0e7e 65 * @param x_change @details : number to change alien x position by
evanso 24:479da6ca0e7e 66 * @param y_change @detials : number to change alien y position by
evanso 24:479da6ca0e7e 67 */
evanso 24:479da6ca0e7e 68 void set_alien_direction(int x_change,int y_change);
evanso 24:479da6ca0e7e 69
evanso 24:479da6ca0e7e 70 /** Stops the alien from moving off the edge of the map and moves alien if the map loops
evanso 24:479da6ca0e7e 71 * @param map_length_@details : length of the map
evanso 24:479da6ca0e7e 72 * @param position_x_map_ @detials : the drawing start posisiton of the map
evanso 24:479da6ca0e7e 73 */
evanso 24:479da6ca0e7e 74 void off_screen_x_y_checker(int map_length_, int position_x_map_);
evanso 24:479da6ca0e7e 75
evanso 19:1bc0a2d22054 76 // Variables ---------------------------------------------------------------
evanso 19:1bc0a2d22054 77
evanso 19:1bc0a2d22054 78 //Aliens x position on lcd
evanso 19:1bc0a2d22054 79 int position_x_alien_;
evanso 19:1bc0a2d22054 80
evanso 19:1bc0a2d22054 81 // Aliens y position on lcd
evanso 19:1bc0a2d22054 82 int position_y_alien_;
evanso 21:f7d7834e3af1 83
evanso 21:f7d7834e3af1 84 // Alien movement counter
evanso 24:479da6ca0e7e 85 int alien_move_counter;
evanso 24:479da6ca0e7e 86
evanso 24:479da6ca0e7e 87 // Alien randome move counter
evanso 24:479da6ca0e7e 88 int random_move_counter_;
evanso 21:f7d7834e3af1 89
evanso 24:479da6ca0e7e 90 // Random direction variable
evanso 24:479da6ca0e7e 91 int random_direction_;
evanso 24:479da6ca0e7e 92
evanso 24:479da6ca0e7e 93 // Aliens genreal movement direction, 1 = East , 0 = West
evanso 24:479da6ca0e7e 94 int alien_general_direction;
evanso 19:1bc0a2d22054 95 };
evanso 19:1bc0a2d22054 96
evanso 19:1bc0a2d22054 97 #endif