#include <snipe_rifle.h>
Inheritance diagram for SnipeRifle:
Public Member Functions | |
SnipeRifle () | |
void | SignalProjectileGhostState () |
void | DrawBeam () |
void | Draw () |
Protected Member Functions | |
bool | p_Shoot () |
void | p_Deselect () |
WeaponProjectile * | GetProjectileInstance () |
Private Member Functions | |
bool | ComputeCrossPoint (bool force) |
Private Attributes | |
double | last_angle |
Point2i | last_rifle_pos |
Point2i | laser_beam_start |
Point2i | targeted_point |
bool | targeting_something |
Sprite * | m_laser_image |
Color | laser_beam_color |
Definition at line 38 of file snipe_rifle.h.
SnipeRifle::SnipeRifle | ( | ) |
Definition at line 53 of file snipe_rifle.cpp.
00053 : WeaponLauncher(WEAPON_SNIPE_RIFLE,"snipe_rifle", new ExplosiveWeaponConfig()) 00054 { 00055 m_name = _("Sniper Rifle"); 00056 00057 last_angle = 0.0; 00058 targeting_something = false; 00059 m_laser_image = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_laser")); 00060 m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_fire")); 00061 m_weapon_fire->EnableRotationCache(32); 00062 laser_beam_color = resource_manager.LoadColor(weapons_res_profile,m_id+"_laser_color"); 00063 00064 ReloadLauncher(); 00065 }
Here is the call graph for this function:
bool SnipeRifle::ComputeCrossPoint | ( | bool | force | ) | [private] |
Definition at line 93 of file snipe_rifle.cpp.
00094 { 00095 // Did the current character is moving ? 00096 Point2i pos = GetGunHolePosition(); 00097 double angle = ActiveCharacter().GetFiringAngle(); 00098 if ( !force && last_rifle_pos == pos && last_angle == angle ) return targeting_something; 00099 else { 00100 last_rifle_pos=pos; 00101 last_angle=angle; 00102 } 00103 00104 // Equation of movement : y = ax + b 00105 double a, b; 00106 a = sin(angle) / cos(angle); 00107 b = pos.y - ( a * pos.x ); 00108 Point2i delta_pos, size, start_point; 00109 start_point = pos; 00110 uint distance = 0; 00111 targeting_something = false; 00112 // While test is not finished 00113 while( distance < SNIPE_RIFLE_MAX_BEAM_SIZE ){ 00114 // going upwards ( -3pi/4 < angle <-pi/4 ) 00115 if (angle < -0.78 && angle > -2.36){ 00116 pos.x = (int)((pos.y-b)/a); //Calculate x 00117 delta_pos.y = -1; //Increment y 00118 // going downwards ( 3pi/4 > angle > pi/4 ) 00119 } else if (angle > 0.78 && angle < 2.36){ 00120 pos.x = (int)((pos.y-b)/a); //Calculate x 00121 delta_pos.y = 1; //Increment y 00122 // else going at right or left 00123 } else { 00124 pos.y = (int)((a*pos.x) + b); //Calculate y 00125 delta_pos.x = ActiveCharacter().GetDirection(); //Increment x 00126 } 00127 // start point of the laser beam 00128 if ( distance < SNIPE_RIFLE_BEAM_START ) laser_beam_start = pos; 00129 00130 // the point is outside the map 00131 if ( world.EstHorsMondeX(pos.x) || world.EstHorsMondeY(pos.y) ) break; 00132 00133 // is there a collision ?? 00134 if ( distance > 30 && !projectile->IsInVacuumXY( pos )){ 00135 targeting_something = true; 00136 break; 00137 } 00138 pos += delta_pos; 00139 distance = (int) start_point.Distance(pos); 00140 } 00141 targeted_point=pos; 00142 return targeting_something; 00143 }
Here is the call graph for this function:
Here is the caller graph for this function:
void SnipeRifle::Draw | ( | ) | [virtual] |
Reimplemented from WeaponLauncher.
Definition at line 197 of file snipe_rifle.cpp.
00198 { 00199 WeaponLauncher::Draw(); 00200 if( GameLoop::GetInstance()->ReadState() != GameLoop::PLAYING || IsActive() ) return; 00201 ComputeCrossPoint(); 00202 DrawBeam(); 00203 // Draw the laser impact 00204 if( targeting_something ) m_laser_image->Draw(targeted_point - (m_laser_image->GetSize()/2)); 00205 }
Here is the call graph for this function:
void SnipeRifle::DrawBeam | ( | ) |
Definition at line 151 of file snipe_rifle.cpp.
00152 { 00153 Point2i pos1 = laser_beam_start - camera.GetPosition(); 00154 Point2i pos2 = targeted_point - camera.GetPosition(); 00155 AppWormux::GetInstance()->video.window.AALineColor(pos1.x, pos2.x, pos1.y, pos2.y, laser_beam_color); 00156 00157 // Set area of the screen to be redrawn: 00158 // Splited into little rectangles to avoid too large area of redraw 00159 float redraw_size = 20.0; 00160 float dst = laser_beam_start.Distance(targeted_point); 00161 Point2f pos = Point2f((float)laser_beam_start.x, (float)laser_beam_start.y); 00162 Point2f delta = ( Point2f((float)targeted_point.x, (float)targeted_point.y) - pos ) * redraw_size / dst; 00163 Point2i delta_i((int)delta.x, (int)delta.y); 00164 00165 if(delta_i.x < 0) delta_i.x = - delta_i.x; // the Map::ToRedraw method doesn't support negative rectangles 00166 if(delta_i.y < 0) delta_i.y = - delta_i.y; 00167 delta_i.x += 6; // We have to increase the size of the rectangle so the corner of the rectangles overlaps 00168 delta_i.y += 6; 00169 00170 int i = 0; 00171 while( (float)i * redraw_size < dst ) 00172 { 00173 // float to int conversion... 00174 Point2i pos_i((int)pos.x, (int)pos.y); 00175 if(delta.x < 0.0) 00176 { 00177 pos_i.x -= delta_i.x; 00178 pos_i.x += 3; 00179 } 00180 else 00181 pos_i.x -= 3; 00182 00183 if(delta.y < 0.0) 00184 { 00185 pos_i.y -= delta_i.y; 00186 pos_i.y += 3; 00187 } 00188 else 00189 pos_i.y -= 3; 00190 00191 world.ToRedrawOnMap(Rectanglei( pos_i, delta_i )); 00192 pos += delta; 00193 i++; 00194 } 00195 }
Here is the call graph for this function:
Here is the caller graph for this function:
WeaponProjectile * SnipeRifle::GetProjectileInstance | ( | ) | [protected, virtual] |
Implements WeaponLauncher.
Definition at line 67 of file snipe_rifle.cpp.
00068 { 00069 return dynamic_cast<WeaponProjectile *> 00070 (new SnipeBullet(cfg(),dynamic_cast<WeaponLauncher *>(this))); 00071 }
Here is the call graph for this function:
void SnipeRifle::p_Deselect | ( | ) | [protected, virtual] |
Reimplemented from WeaponLauncher.
Definition at line 146 of file snipe_rifle.cpp.
00147 { 00148 ActiveCharacter().SetFiringAngle(0.); 00149 }
Here is the call graph for this function:
bool SnipeRifle::p_Shoot | ( | ) | [protected, virtual] |
Reimplemented from WeaponLauncher.
Definition at line 73 of file snipe_rifle.cpp.
00074 { 00075 if(m_is_active) 00076 return false; 00077 00078 m_is_active = true; 00079 projectile->Shoot (SNIPE_RIFLE_BULLET_SPEED); 00080 projectile = NULL; 00081 ReloadLauncher(); 00082 return true; 00083 }
Here is the call graph for this function:
void SnipeRifle::SignalProjectileGhostState | ( | ) | [virtual] |
Reimplemented from WeaponLauncher.
Definition at line 86 of file snipe_rifle.cpp.
00087 { 00088 m_is_active = false; 00089 ReloadLauncher(); 00090 ComputeCrossPoint(true); 00091 }
Here is the call graph for this function:
Color SnipeRifle::laser_beam_color [private] |
Definition at line 47 of file snipe_rifle.h.
Point2i SnipeRifle::laser_beam_start [private] |
Definition at line 43 of file snipe_rifle.h.
double SnipeRifle::last_angle [private] |
Definition at line 41 of file snipe_rifle.h.
Point2i SnipeRifle::last_rifle_pos [private] |
Definition at line 42 of file snipe_rifle.h.
Sprite* SnipeRifle::m_laser_image [private] |
Definition at line 46 of file snipe_rifle.h.
Point2i SnipeRifle::targeted_point [private] |
Definition at line 44 of file snipe_rifle.h.
bool SnipeRifle::targeting_something [private] |
Definition at line 45 of file snipe_rifle.h.