Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Wed May 06 11:24:22 2020 +0000
Revision:
22:053c11a202e1
Parent:
20:febd920ec29e
Child:
23:cc44e26c08fa
Now that the main code structure is finished for alien and weapons I can unit test those classes. Added a unit test for the alien class and it passed!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 16:1ee3d3804557 1 #include "Weapons.h"
evanso 16:1ee3d3804557 2
evanso 16:1ee3d3804557 3 Weapons::Weapons() {
evanso 16:1ee3d3804557 4
evanso 16:1ee3d3804557 5 }
evanso 16:1ee3d3804557 6
evanso 16:1ee3d3804557 7 Weapons::~Weapons() {
evanso 16:1ee3d3804557 8
evanso 16:1ee3d3804557 9 }
evanso 16:1ee3d3804557 10
evanso 19:1bc0a2d22054 11 void Weapons::init(Vector2D spaceship_pos, bool spaceship_sprite_direction) {
evanso 19:1bc0a2d22054 12 calc_bullets_start_pos(spaceship_pos, spaceship_sprite_direction);
evanso 19:1bc0a2d22054 13 set_direction(spaceship_sprite_direction);
evanso 20:febd920ec29e 14 bullet_delete_cunter_ = 0;
evanso 16:1ee3d3804557 15 }
evanso 16:1ee3d3804557 16
evanso 17:25d79cca203a 17 void Weapons::calc_bullets_start_pos(Vector2D spaceship_pos, bool spaceship_sprite_direction_){
evanso 17:25d79cca203a 18 // Sets start position of bullet to spaceships nose
evanso 17:25d79cca203a 19 if (spaceship_sprite_direction_){
evanso 17:25d79cca203a 20 position_x_bullet_ = spaceship_pos.x + 13;
evanso 20:febd920ec29e 21 position_y_bullet_ = spaceship_pos.y + 2;
evanso 17:25d79cca203a 22 }else{
evanso 17:25d79cca203a 23 position_x_bullet_ = spaceship_pos.x;
evanso 20:febd920ec29e 24 position_y_bullet_ = spaceship_pos.y + 2;
evanso 17:25d79cca203a 25 }
evanso 17:25d79cca203a 26 #ifdef POSITION_BULLET_DEBUG
evanso 17:25d79cca203a 27 printf("X = %d\n", position_x_bullet_);
evanso 17:25d79cca203a 28 printf("Y = %d\n", position_y_bullet_);
evanso 17:25d79cca203a 29 #endif
evanso 17:25d79cca203a 30 }
evanso 17:25d79cca203a 31
evanso 18:11068b98e261 32 void Weapons::draw_bullet(N5110 &lcd){
evanso 20:febd920ec29e 33 // draws then moves the bullet
evanso 18:11068b98e261 34 lcd.drawLine(position_x_bullet_, position_y_bullet_, position_x_bullet_+1, position_y_bullet_, 1);
evanso 19:1bc0a2d22054 35 if(bullet_direction_){
evanso 19:1bc0a2d22054 36 position_x_bullet_ += 3;
evanso 19:1bc0a2d22054 37 }else{
evanso 19:1bc0a2d22054 38 position_x_bullet_ -= 3;
evanso 19:1bc0a2d22054 39 }
evanso 20:febd920ec29e 40
evanso 20:febd920ec29e 41 // increments counter
evanso 20:febd920ec29e 42 bullet_delete_cunter_++;
evanso 18:11068b98e261 43 }
evanso 18:11068b98e261 44
evanso 18:11068b98e261 45 Vector2D Weapons::get_pos_one(){
evanso 17:25d79cca203a 46 Vector2D pos = {position_x_bullet_,position_y_bullet_};
evanso 17:25d79cca203a 47 return pos;
evanso 18:11068b98e261 48 }
evanso 18:11068b98e261 49
evanso 22:053c11a202e1 50 void Weapons::set_pos_one(Vector2D pos){
evanso 22:053c11a202e1 51 position_x_bullet_ = pos.x;
evanso 22:053c11a202e1 52 position_y_bullet_ = pos.y;
evanso 22:053c11a202e1 53 }
evanso 22:053c11a202e1 54
evanso 18:11068b98e261 55 Vector2D Weapons::get_pos_two(){
evanso 18:11068b98e261 56 Vector2D pos = {position_x_bullet_+1,position_y_bullet_};
evanso 18:11068b98e261 57 return pos;
evanso 19:1bc0a2d22054 58 }
evanso 19:1bc0a2d22054 59
evanso 20:febd920ec29e 60 void Weapons::set_direction(bool spaceship_sprite_direction){
evanso 19:1bc0a2d22054 61 bullet_direction_ = spaceship_sprite_direction;
evanso 20:febd920ec29e 62 }
evanso 20:febd920ec29e 63
evanso 20:febd920ec29e 64 int Weapons::get_bullet_delete_counter(){
evanso 20:febd920ec29e 65 return bullet_delete_cunter_;
evanso 20:febd920ec29e 66 }
evanso 20:febd920ec29e 67
evanso 20:febd920ec29e 68 bool Weapons::get_direction(){
evanso 20:febd920ec29e 69 return bullet_direction_;
evanso 16:1ee3d3804557 70 }