Ben Evans University Second Year Project. Game Called Defender.
Embed:
(wiki syntax)
Show/hide line numbers
Weapons.cpp
00001 #include "Weapons.h" 00002 00003 Weapons::Weapons() { 00004 00005 } 00006 00007 Weapons::~Weapons() { 00008 00009 } 00010 00011 void Weapons::init(Vector2D sprite_pos, bool sprite_direction, 00012 bool bullet_type) { 00013 // Bullet for alien or for spaceship 00014 set_direction(sprite_direction); 00015 if (bullet_type) { 00016 calc_bullets_start_pos(sprite_pos, sprite_direction); 00017 }else{ 00018 calc_alien_bullets_start_pos(sprite_pos, sprite_direction); 00019 } 00020 bullet_delete_counter_ = 0; 00021 } 00022 00023 void Weapons::smart_bomb(N5110 &lcd) { 00024 // Turn backlight off and on twice 00025 lcd.backLightOff(); 00026 wait(0.02); 00027 lcd.backLightOn(); 00028 wait(0.02); 00029 lcd.backLightOff(); 00030 wait(0.02); 00031 lcd.backLightOn(); 00032 } 00033 00034 00035 void Weapons::calc_bullets_start_pos(Vector2D spaceship_pos, 00036 bool spaceship_sprite_direction_) { 00037 // Sets start position of bullet to spaceships nose 00038 if (spaceship_sprite_direction_) { 00039 position_x_ = spaceship_pos.x + 13; 00040 position_y_ = spaceship_pos.y + 2; 00041 }else{ 00042 position_x_ = spaceship_pos.x; 00043 position_y_ = spaceship_pos.y + 2; 00044 } 00045 #ifdef POSITION_BULLET_DEBUG 00046 printf("X = %d\n", position_x_); 00047 printf("Y = %d\n", position_y_); 00048 #endif 00049 } 00050 00051 void Weapons::draw_bullet(N5110 &lcd) { 00052 // Draws then moves the bullet position 00053 lcd.drawLine(position_x_, position_y_, position_x_+1, position_y_, 1); 00054 if (direction_) { 00055 position_x_ += 3; 00056 }else{ 00057 position_x_ -= 3; 00058 } 00059 00060 // Increments counter 00061 bullet_delete_counter_++; 00062 } 00063 00064 void Weapons::calc_alien_bullets_start_pos(Vector2D alien_pos, 00065 bool alien_sprite_direction_) { 00066 // Sets start position of bullet to middle of alien 00067 position_x_ = alien_pos.x + 3; 00068 position_y_ = alien_pos.y + 3; 00069 00070 // Gets a random direction for the bullet to travel in 00071 set_random_move(); 00072 } 00073 00074 void Weapons::draw_alien_bullet(N5110 &lcd,Direction d_) { 00075 // Draws then moves the bullet position 00076 lcd.drawLine(position_x_, position_y_, position_x_+1, position_y_, 1); 00077 00078 // Moves bullet in random direction and accommodates for spaceship movement 00079 move_direction(); 00080 position_x_ += calc_sprite_movement(d_); 00081 00082 // Increments counter 00083 bullet_delete_counter_++; 00084 } 00085 00086 void Weapons::set_pos_one(Vector2D pos) { 00087 position_x_ = pos.x; 00088 position_y_ = pos.y; 00089 } 00090 00091 void Weapons::set_direction(bool sprite_direction) { 00092 direction_ = sprite_direction; 00093 } 00094 00095 int Weapons::get_bullet_delete_counter() { 00096 return bullet_delete_counter_; 00097 } 00098 00099 bool Weapons::get_direction() { 00100 return direction_; 00101 }
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2