Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void boat_update(boat_t& b, float t, float dt, int numWaves)
- {
- float wave = 0.0f;
- float dydx;
- float dydz;
- for(int n = 0; n < numWaves; n++)
- {
- wave += m_calculateSine(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
- dydx += m_calcDYDX(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
- dydz += m_calcDYDZ(a[n], kx[n], kz[n], w[n], b.position.x, b.position.z, t);
- }
- float theta = ARTAN(b.position.z/b.position.x);
- b.heading = theta;
- b.dydx = dydx;
- b.dydz = dydz;
- b.xRot = COS(dydx) * dt;
- b.zRot = COS(dydz) * dt;
- b.position.y = wave + 0.1f;
- float distance = v_Magnitude(b.position);
- b.delayTime -= 0.22f;
- if(distance <= 4.0f)
- {
- b.heading = ANG_2_DEGREES(theta);
- if(b.delayTime <= 0.0f)
- {
- boat_shoot(b);
- b.delayTime = BOAT_FIRE_DELAY;
- }
- return ;
- }
- // This acts _kinda_ strange, but it's actually kinda fun
- // The boats slow down as they come in, which presents a pretty fun
- // challenge. It's not like this is a really big hack or anything!
- // (yes James, I'm looking at you :] )
- b.velocity.z = -b.position.x * TAN(theta) * dt * 0.2f;
- b.velocity.x = -b.position.z / TAN(theta) * dt * 0.2f;
- b.position.x += b.velocity.x * 0.4f;
- b.position.z += b.velocity.z * 0.4f;
- b.position.i += b.velocity.x * 0.4f;
- b.position.k += b.velocity.z * 0.4f;
- }
- void boat_shoot(boat_t& b)
- {
- float vz;
- float vx;
- /**
- * Don't ask how this works.. Seriously...
- * tan(90) == tan(270) which is UNDEFINED!
- * Seriously, it's a division by zero... How this works is beyond me...
- */
- if(b.position.x < 0.0f)
- {
- vx = b.position.x / TAN(270.0f) * 0.1f;
- }
- else
- {
- vx = b.position.x / TAN(90.0f) * 1.1f;
- }
- if(b.position.z < 0.0f)
- {
- vz = b.position.z / TAN(270.0f) * 0.1f;
- }
- else
- {
- vz = b.position.z / TAN(90.0f) * 1.1f;
- }
- projectile_create(b.position.x, b.position.y + 0.2f, b.position.z, 35.0f, vx, vz, 4.5f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement