1 
2 #include "tuxkart.h"
3 
4 
update()5 void Projectile::update ()
6 {
7   wheelie_angle = 0 ;
8   zipper_time_left = 0.0f ;
9 
10   if ( type == COLLECT_HOMING_MISSILE )
11     velocity.xyz[1] = MAX_HOMING_PROJECTILE_VELOCITY ;
12   else
13   if ( type == COLLECT_MISSILE )
14     velocity.xyz[1] = MAX_PROJECTILE_VELOCITY ;
15   else
16     velocity.xyz[1] = MAX_PROJECTILE_VELOCITY / 5.0f ;
17 
18   Driver::update () ;
19   wheelie_angle = 0 ;
20   zipper_time_left = 0.0f ;
21 }
22 
doObjectInteractions()23 void Projectile::doObjectInteractions ()
24 {
25   float ndist = SG_MAX ;
26   int nearest = -1 ;
27 
28   for ( int i = 0 ; i < num_karts ; i++ )
29   {
30     sgCoord *pos ;
31 
32     pos = kart [ i ] -> getCoord () ;
33 
34     if ( type != COLLECT_NOTHING && kart[i] != owner )
35     {
36       float d = sgDistanceSquaredVec3 ( pos->xyz, getCoord()->xyz ) ;
37 
38       if ( d < 2.0f )
39       {
40         kart [ i ] -> forceCrash () ;
41         curr_pos.xyz[2] += 1.2f ;
42         explosion[0]->start(curr_pos.xyz);
43         off () ;
44       }
45       else
46       if ( d < ndist )
47       {
48         ndist = d ;
49         nearest = i ;
50       }
51     }
52   }
53 
54   if ( type == COLLECT_HOMING_MISSILE && nearest != -1 &&
55         ndist < MAX_HOME_DIST_SQD )
56   {
57     sgVec3 delta ;
58     sgVec3 hpr ;
59     sgCoord *k = kart[nearest]->getCoord() ;
60 
61     sgSubVec3 ( delta, k->xyz, curr_pos.xyz ) ;
62 
63 delta[2] = 0.0f ;
64 
65     sgHPRfromVec3 ( hpr, delta ) ;
66 
67     sgSubVec3 ( hpr, curr_pos.hpr ) ;
68 
69     if ( hpr[0] >  180.0f ) hpr[0] -= 360.0f ;
70     if ( hpr[0] < -180.0f ) hpr[0] += 360.0f ;
71     if ( hpr[1] >  180.0f ) hpr[1] -= 360.0f ;
72     if ( hpr[1] < -180.0f ) hpr[1] += 360.0f ;
73 
74     if ( hpr[0] > 80.0f || hpr[0] < -80.0f )
75       velocity.hpr[0] = 0.0f ;
76     else
77     {
78       if ( hpr[0] > 3.0f )
79         velocity.hpr[0] = HOMING_MISSILE_TURN_RATE ;
80       else
81       if ( hpr[0] < -3.0f )
82         velocity.hpr[0] = -HOMING_MISSILE_TURN_RATE ;
83       else
84         velocity.hpr[0] = 0.0f ;
85 
86       if ( hpr[1] > 1.0f )
87         velocity.hpr[1] = HOMING_MISSILE_PITCH_RATE ;
88       else
89       if ( hpr[1] < -1.0f )
90         velocity.hpr[1] = -HOMING_MISSILE_PITCH_RATE ;
91       else
92         velocity.hpr[1] = 0.0f ;
93     }
94   }
95   else
96     velocity.hpr[0] = velocity.hpr[1] = 0.0f ;
97 
98 }
99 
doLapCounting()100 void Projectile::doLapCounting        () {}
doZipperProcessing()101 void Projectile::doZipperProcessing   () {}
102 
doCollisionAnalysis(float)103 void Projectile::doCollisionAnalysis  ( float /* hot */ )
104 {
105   if ( collided || crashed )
106   {
107     if ( type == COLLECT_SPARK )
108     {
109       sgVec3 bouncevec ;
110       sgVec3 direction ;
111 
112       sgNormalizeVec3 ( bouncevec, surface_avoidance_vector ) ;
113       sgSubVec3 ( direction, curr_pos.xyz, last_pos.xyz ) ;
114       sgReflectInPlaneVec3 ( direction, bouncevec ) ;
115 
116       sgHPRfromVec3 ( curr_pos.hpr, direction ) ;
117     }
118     else
119     if ( type != COLLECT_NOTHING )
120     {
121       curr_pos.xyz[2] += 1.2f ;
122       explosion[0]->start(curr_pos.xyz);
123       off () ;
124     }
125   }
126 }
127 
128 
129