Advertisement
Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. void boat_update(boat_t& b, float t, float dt, int numWaves)
  2. {
  3.     float wave = 0.0f;
  4.     float dydx;
  5.     float dydz;
  6.  
  7.     for(int n = 0; n < numWaves; n++)
  8.     {
  9.         wave += m_calculateSine(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
  10.         dydx += m_calcDYDX(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
  11.         dydz += m_calcDYDZ(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
  12.     }
  13.  
  14.     float theta = ARTAN(b.position.z/b.position.x);
  15.  
  16.     b.heading = theta;
  17.  
  18.     b.dydx = dydx;
  19.     b.dydz = dydz;
  20.  
  21.     b.xRot = COS(dydx) * dt;
  22.     b.zRot = COS(dydz) * dt;
  23.  
  24.     b.position.y = wave + 0.1f;
  25.  
  26.     float distance = v_Magnitude(b.position);
  27.  
  28.     b.delayTime -= 0.22f;
  29.  
  30.     if(distance <= 4.0f)
  31.     {
  32.         b.heading = ANG_2_DEGREES(theta);
  33.         if(b.delayTime <= 0.0f)
  34.         {
  35.             boat_shoot(b);
  36.             b.delayTime = BOAT_FIRE_DELAY;
  37.         }
  38.         return ;
  39.     }
  40.  
  41.     // This acts _kinda_ strange, but it's actually kinda fun
  42.     // The boats slow down as they come in, which presents a pretty fun
  43.     // challenge. It's not like this is a really big hack or anything!
  44.     // (yes James, I'm looking at you :] )
  45.     b.velocity.z = -b.position.x * TAN(theta) * dt * 0.2f;
  46.     b.velocity.x = -b.position.z / TAN(theta) * dt * 0.2f;
  47.  
  48.     b.position.x += b.velocity.x * 0.4f;
  49.     b.position.z += b.velocity.z * 0.4f;
  50.     b.position.i += b.velocity.x * 0.4f;
  51.     b.position.k += b.velocity.z * 0.4f;
  52. }
  53.  
  54. void boat_shoot(boat_t& b)
  55. {
  56.     float vz;
  57.     float vx;
  58.  
  59.     /**
  60.      *  Don't ask how this works.. Seriously...
  61.      *  tan(90) == tan(270) which is UNDEFINED!
  62.      *  Seriously, it's a division by zero... How this works is beyond me...
  63.      */
  64.     if(b.position.x < 0.0f)
  65.     {
  66.         vx = b.position.x / TAN(270.0f) * 0.1f;
  67.     }
  68.     else
  69.     {
  70.         vx = b.position.x / TAN(90.0f) * 1.1f;
  71.     }
  72.  
  73.     if(b.position.z < 0.0f)
  74.     {
  75.         vz = b.position.z / TAN(270.0f) * 0.1f;
  76.     }
  77.     else
  78.     {
  79.         vz = b.position.z / TAN(90.0f) * 1.1f;
  80.     }
  81.  
  82.     projectile_create(b.position.x, b.position.y + 0.2f, b.position.z, 35.0f, vx, vz, 4.5f);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement