Ben Evans University Second Year Project. Game Called Defender.
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.
Weapons/Weapons.h@28:a5958497d5ce, 2020-05-13 (annotated)
- Committer:
- evanso
- Date:
- Wed May 13 23:07:52 2020 +0000
- Revision:
- 28:a5958497d5ce
- Parent:
- 27:8bb2bd97c319
- Child:
- 31:6015e8ed859c
Added Random Movement base class which is inherited by alien bullets and alien direction. Alien now shoots bullets randomly towards the spaceship.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 17:25d79cca203a | 1 | #ifndef WEAPONS_H |
evanso | 17:25d79cca203a | 2 | #define WEAPONS_H |
evanso | 16:1ee3d3804557 | 3 | |
evanso | 22:053c11a202e1 | 4 | // Included libraries ---------------------------------------------------------- |
evanso | 16:1ee3d3804557 | 5 | #include "mbed.h" |
evanso | 16:1ee3d3804557 | 6 | #include "N5110.h" |
evanso | 16:1ee3d3804557 | 7 | #include "Gamepad.h" |
evanso | 28:a5958497d5ce | 8 | #include "RandomMovement.h" |
evanso | 16:1ee3d3804557 | 9 | |
evanso | 16:1ee3d3804557 | 10 | /** Weapons class |
evanso | 27:8bb2bd97c319 | 11 | * @brief Draws and moves weapons |
evanso | 27:8bb2bd97c319 | 12 | * @author Benjamin Evans, University of Leeds |
evanso | 27:8bb2bd97c319 | 13 | * @date April 2020 |
evanso | 27:8bb2bd97c319 | 14 | */ |
evanso | 28:a5958497d5ce | 15 | class Weapons: private RandomMovement { |
evanso | 16:1ee3d3804557 | 16 | public: |
evanso | 16:1ee3d3804557 | 17 | /** Constructor */ |
evanso | 16:1ee3d3804557 | 18 | Weapons(); |
evanso | 16:1ee3d3804557 | 19 | |
evanso | 16:1ee3d3804557 | 20 | /** Destructor */ |
evanso | 16:1ee3d3804557 | 21 | ~Weapons(); |
evanso | 16:1ee3d3804557 | 22 | |
evanso | 27:8bb2bd97c319 | 23 | /** Initalises Weapons |
evanso | 28:a5958497d5ce | 24 | * @param sprite_pos @details vector 2D of sprite xy position |
evanso | 28:a5958497d5ce | 25 | * @param sprite_direction @details sprite direction bool, |
evanso | 27:8bb2bd97c319 | 26 | * true = E, false = W |
evanso | 28:a5958497d5ce | 27 | * @param bullet_type @details true = spaceship, false = alien |
evanso | 27:8bb2bd97c319 | 28 | */ |
evanso | 28:a5958497d5ce | 29 | void init(Vector2D sprite_pos, bool sprite_direction,bool bullet_type); |
evanso | 16:1ee3d3804557 | 30 | |
evanso | 18:11068b98e261 | 31 | /** Draws the bullet and moves it in x direction each frame |
evanso | 27:8bb2bd97c319 | 32 | * @param lcd @details N5110 object |
evanso | 18:11068b98e261 | 33 | */ |
evanso | 18:11068b98e261 | 34 | void draw_bullet(N5110 &lcd); |
evanso | 28:a5958497d5ce | 35 | |
evanso | 28:a5958497d5ce | 36 | /** Draws the aliens bullet and moves it in xy direction each frame |
evanso | 28:a5958497d5ce | 37 | * @param lcd @details N5110 object |
evanso | 28:a5958497d5ce | 38 | * @param d_ @details : Direction object of joystick |
evanso | 28:a5958497d5ce | 39 | */ |
evanso | 28:a5958497d5ce | 40 | void draw_alien_bullet(N5110 &lcd, Direction d_); |
evanso | 18:11068b98e261 | 41 | |
evanso | 22:053c11a202e1 | 42 | // Accessors and mutators -------------------------------------------------- |
evanso | 18:11068b98e261 | 43 | |
evanso | 17:25d79cca203a | 44 | /** Gets the xy position of the bullet |
evanso | 27:8bb2bd97c319 | 45 | * @return position_x_bullet_ |
evanso | 27:8bb2bd97c319 | 46 | * @return position_x_bullet_ |
evanso | 17:25d79cca203a | 47 | */ |
evanso | 18:11068b98e261 | 48 | Vector2D get_pos_one(); |
evanso | 18:11068b98e261 | 49 | |
evanso | 22:053c11a202e1 | 50 | /** sets the xy position of the bullet |
evanso | 22:053c11a202e1 | 51 | * @param pos @details vector 2D of bullet xy position |
evanso | 22:053c11a202e1 | 52 | */ |
evanso | 22:053c11a202e1 | 53 | void set_pos_one(Vector2D pos); |
evanso | 22:053c11a202e1 | 54 | |
evanso | 18:11068b98e261 | 55 | /** Gets the 2nd xy position of the bullet for colition detection |
evanso | 27:8bb2bd97c319 | 56 | * @return position_x_bullet_ + 1 |
evanso | 27:8bb2bd97c319 | 57 | * @return position_x_bullet_ |
evanso | 18:11068b98e261 | 58 | */ |
evanso | 18:11068b98e261 | 59 | Vector2D get_pos_two(); |
evanso | 19:1bc0a2d22054 | 60 | |
evanso | 20:febd920ec29e | 61 | /** Gets the bullet distance counter |
evanso | 27:8bb2bd97c319 | 62 | * @return bullet_distance_counter |
evanso | 20:febd920ec29e | 63 | */ |
evanso | 20:febd920ec29e | 64 | int get_bullet_delete_counter(); |
evanso | 20:febd920ec29e | 65 | |
evanso | 20:febd920ec29e | 66 | /** Gets the bullet direction |
evanso | 27:8bb2bd97c319 | 67 | * @return bullet_direction_ |
evanso | 20:febd920ec29e | 68 | */ |
evanso | 20:febd920ec29e | 69 | bool get_direction(); |
evanso | 19:1bc0a2d22054 | 70 | |
evanso | 19:1bc0a2d22054 | 71 | /** Sets the bullets movment direction when it is fired |
evanso | 27:8bb2bd97c319 | 72 | * @param spaceship_sprite_direction_ @details sprite direction bool, |
evanso | 27:8bb2bd97c319 | 73 | * true = E, false = W |
evanso | 19:1bc0a2d22054 | 74 | */ |
evanso | 28:a5958497d5ce | 75 | void set_direction(bool sprite_direction_); |
evanso | 18:11068b98e261 | 76 | |
evanso | 22:053c11a202e1 | 77 | private: |
evanso | 22:053c11a202e1 | 78 | // Function prototypes ----------------------------------------------------- |
evanso | 22:053c11a202e1 | 79 | |
evanso | 19:1bc0a2d22054 | 80 | /** Calculates bullets start postion |
evanso | 19:1bc0a2d22054 | 81 | * @param spaceship_pos @details x and y postion of spaceship |
evanso | 27:8bb2bd97c319 | 82 | * @param spaceship_sprite_direction_ @details sprite direction bool, |
evanso | 27:8bb2bd97c319 | 83 | * true = E, false = W |
evanso | 19:1bc0a2d22054 | 84 | */ |
evanso | 27:8bb2bd97c319 | 85 | void calc_bullets_start_pos(Vector2D spaceship_pos, |
evanso | 27:8bb2bd97c319 | 86 | bool spaceship_sprite_direction_); |
evanso | 28:a5958497d5ce | 87 | |
evanso | 28:a5958497d5ce | 88 | /** Calculates allien bullets start postion |
evanso | 28:a5958497d5ce | 89 | * @param alien_pos @details x and y postion of spaceship |
evanso | 28:a5958497d5ce | 90 | * @param alien_sprite_direction_ @details sprite direction bool, |
evanso | 28:a5958497d5ce | 91 | * true = E, false = W |
evanso | 28:a5958497d5ce | 92 | */ |
evanso | 28:a5958497d5ce | 93 | void calc_alien_bullets_start_pos(Vector2D alien_pos, |
evanso | 28:a5958497d5ce | 94 | bool alien_sprite_direction_); |
evanso | 28:a5958497d5ce | 95 | |
evanso | 28:a5958497d5ce | 96 | /** Calulates the bullet movement depeding on spaceship positions and |
evanso | 28:a5958497d5ce | 97 | * joystick input |
evanso | 28:a5958497d5ce | 98 | * @param d_ @details : Direction object of joystick |
evanso | 28:a5958497d5ce | 99 | * @retrun integer @details move bullet value for bullet draw function |
evanso | 28:a5958497d5ce | 100 | */ |
evanso | 28:a5958497d5ce | 101 | int calc_bullet_movement(Direction d_); |
evanso | 20:febd920ec29e | 102 | |
evanso | 16:1ee3d3804557 | 103 | // Variables --------------------------------------------------------------- |
evanso | 16:1ee3d3804557 | 104 | |
evanso | 27:8bb2bd97c319 | 105 | /** Counter to deleted bullet */ |
evanso | 28:a5958497d5ce | 106 | int bullet_delete_counter_; |
evanso | 16:1ee3d3804557 | 107 | }; |
evanso | 16:1ee3d3804557 | 108 | |
evanso | 16:1ee3d3804557 | 109 | #endif |