[Opentnl-cvs] tnl/zap CTFGame.cpp,1.17,1.18 UIGame.cpp,1.12,1.13 game.cpp,1.14,1.15 ship.cpp,1.19,1.
Brought to you by:
mark_frohnmayer,
s_alanet
From: Ben G. <s_a...@us...> - 2004-04-30 21:58:19
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16758/zap Modified Files: CTFGame.cpp UIGame.cpp game.cpp ship.cpp ship.h sparkManager.cpp sparkManager.h Log Message: Implemented energy on ships. Added boost (hold space) and shields (toggle w/ F). Rebound joystick buttons - shoulder buttons do boost/shield and buttons 3/4 do commander map/scoreboard. Motion trails change color during boost. Render energy bar as part of gametype GUI, with markers showing 100%, 15%, and 5%. Refactored motion trail rendering to be done globally. This reduces state changes and prevents ugly popping issues. Index: ship.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ship.h 30 Apr 2004 20:27:42 -0000 1.11 --- ship.h 30 Apr 2004 21:58:10 -0000 1.12 *************** *** 48,51 **** --- 48,53 ---- MaxVelocity = 450, // points per second Acceleration = 2500, // points per second per second + TurboMaxVelocity = 700, // points per second + TurboAcceleration = 5000, // points per second per second InterpMaxVelocity = 900, // velocity to use to interpolate to proper position InterpAcceleration = 1800, *************** *** 58,61 **** --- 60,64 ---- MaxControlObjectInterpDistance = 200, TrailCount = 2, + RechargeRate = 3, // How many percent/second }; *************** *** 67,70 **** --- 70,74 ---- ExplosionMask = BIT(4), HealthMask = BIT(5), + PowersMask = BIT(6), }; *************** *** 73,79 **** F32 mHealth; F32 mEnergy; - bool mShieldActive; - StringTableEntry mPlayerName; S32 mLastTrailPoint[TrailCount]; --- 77,82 ---- F32 mHealth; F32 mEnergy; StringTableEntry mPlayerName; + bool mShield, mTurbo, mCooldown; S32 mLastTrailPoint[TrailCount]; *************** *** 95,98 **** --- 98,102 ---- F32 getHealth() { return mHealth; } + void burnEnergy(U32 dT); void emitMovementSparks(); void emitShipExplosion(Point pos); Index: CTFGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** CTFGame.cpp 30 Apr 2004 20:27:41 -0000 1.17 --- CTFGame.cpp 30 Apr 2004 21:58:10 -0000 1.18 *************** *** 146,149 **** --- 146,195 ---- UserInterface::drawStringf(pos.x, pos.y, 32, "%d", mTeams[i].score); } + + // Render current ship's energy, too. + if(gClientGame && gClientGame->getConnectionToServer()) + { + Ship *s = dynamic_cast<Ship*>(gClientGame->getConnectionToServer()->getControlObject()); + if(s) + { + static F32 curEnergy = 0.f; + + curEnergy = (curEnergy + s->mEnergy) * 0.5f; + + const F32 offset = 50; + + glColor3f(0.0, 0.0, 1); + glBegin(GL_POLYGON); + glVertex2f(15, 515 + offset); + glVertex2f(15 + curEnergy, 515 + offset); + glVertex2f(15 + curEnergy, 535 + offset); + glVertex2f(15, 535 + offset); + glEnd(); + + // Show danger line. + glColor3f(1, 0, 0); + glBegin(GL_LINES); + glVertex2f(15 + 5, 512 + offset); + glVertex2f(15 + 5, 539 + offset); + glEnd(); + + // Show safety line. + glColor3f(1, 1, 0); + glBegin(GL_LINES); + glVertex2f(15 + 15, 512 + offset); + glVertex2f(15 + 15, 539 + offset); + glEnd(); + + // Show full marker + glColor3f(0, 1, 0); + glBegin(GL_LINE_STRIP); + glVertex2f(15 + 90, 512 + offset); + glVertex2f(15 + 101, 512 + offset); + glVertex2f(15 + 101, 539 + offset); + glVertex2f(15 + 90, 539 + offset); + glEnd(); + + } + } } } Index: sparkManager.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sparkManager.cpp 30 Apr 2004 08:33:20 -0000 1.4 --- sparkManager.cpp 30 Apr 2004 21:58:10 -0000 1.5 *************** *** 166,176 **** }; fxTrail::fxTrail(U32 dropFrequency, U32 len) { mDropFreq = dropFrequency; mLength = len; } ! void fxTrail::update(Point pos) { if(mNodes.size() < mLength) --- 166,184 ---- }; + //----------------------------------------------------------------------------- + fxTrail::fxTrail(U32 dropFrequency, U32 len) { mDropFreq = dropFrequency; mLength = len; + registerTrail(); } ! fxTrail::~fxTrail() ! { ! unregisterTrail(); ! } ! ! void fxTrail::update(Point pos, bool boosted) { if(mNodes.size() < mLength) *************** *** 179,187 **** --- 187,200 ---- t.pos = pos; t.ttl = mDropFreq; + t.boosted = boosted; mNodes.push_front(t); } else + { mNodes[0].pos = pos; + if(boosted) + mNodes[0].boosted = true; + } } *************** *** 198,204 **** void fxTrail::render() { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBegin(GL_LINE_STRIP); --- 211,214 ---- *************** *** 206,217 **** { F32 t = ((F32)i/(F32)mNodes.size()); ! glColor4f(1.f - 2*t, 1.f - 2*t, 1.f, 1.f-t); glVertex2f(mNodes[i].pos.x, mNodes[i].pos.y); } glEnd(); - - glDisable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ZERO); } --- 216,229 ---- { F32 t = ((F32)i/(F32)mNodes.size()); ! ! if(mNodes[i].boosted) ! glColor4f(1.f - t, 1.f - t, 0.f, 1.f-t); ! else ! glColor4f(1.f - 2*t, 1.f - 2*t, 1.f, 0.7f-0.7*t); ! glVertex2f(mNodes[i].pos.x, mNodes[i].pos.y); } glEnd(); } *************** *** 231,233 **** --- 243,292 ---- } + fxTrail * fxTrail::mHead = NULL; + + void fxTrail::registerTrail() + { + fxTrail *n = mHead; + mHead = this; + mNext = n; + } + + void fxTrail::unregisterTrail() + { + // Find ourselves in the list (lame O(n) solution) + fxTrail *w = mHead, *p = NULL; + while(w) + { + if(w == this) + { + if(p) + { + p->mNext = w->mNext; + } + else + { + mHead = w->mNext; + } + } + p = w; + w = w->mNext; + } + } + + void fxTrail::renderTrails() + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + fxTrail *w = mHead; + while(w) + { + w->render(); + w = w->mNext; + } + + glDisable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ZERO); + } + }; \ No newline at end of file Index: game.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** game.cpp 30 Apr 2004 20:27:41 -0000 1.14 --- game.cpp 30 Apr 2004 21:58:10 -0000 1.15 *************** *** 492,495 **** --- 492,496 ---- SparkManager::render(); + fxTrail::renderTrails(); glPopMatrix(); Index: sparkManager.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sparkManager.h 30 Apr 2004 08:33:20 -0000 1.3 --- sparkManager.h 30 Apr 2004 21:58:10 -0000 1.4 *************** *** 51,54 **** --- 51,55 ---- Point pos; S32 ttl; + bool boosted; }; *************** *** 56,66 **** U32 mDropFreq; ! U32 mLength; public: fxTrail(U32 dropFrequency = 32, U32 len = 15); /// Update the point this trail is attached to. ! void update(Point pos); void tick(U32 dT); --- 57,76 ---- U32 mDropFreq; ! S32 mLength; ! ! fxTrail *mNext; ! ! ! static fxTrail *mHead; ! void registerTrail(); ! void unregisterTrail(); ! public: fxTrail(U32 dropFrequency = 32, U32 len = 15); + ~fxTrail(); /// Update the point this trail is attached to. ! void update(Point pos, bool boosted = false); void tick(U32 dT); *************** *** 71,74 **** --- 81,86 ---- Point getLastPos(); + + static void renderTrails(); }; Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** UIGame.cpp 28 Apr 2004 01:34:57 -0000 1.12 --- UIGame.cpp 30 Apr 2004 21:58:10 -0000 1.13 *************** *** 255,259 **** switch(buttonIndex) { ! case 6: { mInScoreboardMode = true; --- 255,259 ---- switch(buttonIndex) { ! case 3: { mInScoreboardMode = true; *************** *** 263,269 **** break; } ! case 7: gClientGame->zoomCommanderMap(); break; } } --- 263,277 ---- break; } ! case 2: gClientGame->zoomCommanderMap(); break; + + case 7: + mCurrentMove.boost = true; + break; + + case 6: + mCurrentMove.shield = true; + break; } } *************** *** 273,277 **** switch(buttonIndex) { ! case 6: { mInScoreboardMode = false; --- 281,285 ---- switch(buttonIndex) { ! case 3: { mInScoreboardMode = false; *************** *** 281,284 **** --- 289,300 ---- break; } + + case 7: + mCurrentMove.boost = false; + break; + + case 6: + mCurrentMove.shield = false; + break; } } *************** *** 312,315 **** --- 328,335 ---- mCurrentMove.right = 1.0; break; + case ' ': + mCurrentMove.boost = true; + break; + case 27: if(!gClientGame->isConnectedToServer()) *************** *** 407,410 **** --- 427,437 ---- mCurrentMove.right = 0; break; + + case ' ': + mCurrentMove.boost = false; + break; + case 'F': + mCurrentMove.shield = !mCurrentMove.shield; + break; } } Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ship.cpp 30 Apr 2004 20:27:41 -0000 1.19 --- ship.cpp 30 Apr 2004 21:58:10 -0000 1.20 *************** *** 69,72 **** --- 69,77 ---- for(S32 i=0; i<TrailCount; i++) mTrail[i].reset(); + + mEnergy = 100.f; + mShield = false; + mTurbo = false; + mCooldown = false; } *************** *** 102,117 **** mMoveState[LastProcessState] = mMoveState[stateIndex]; ! float time = theMove->time * 0.001; Point requestVel(theMove->right - theMove->left, theMove->down - theMove->up); ! requestVel *= MaxVelocity; F32 len = requestVel.len(); ! if(len > MaxVelocity) ! requestVel *= MaxVelocity / len; Point velDelta = requestVel - mMoveState[stateIndex].vel; ! float accRequested = velDelta.len(); ! float maxAccel = Acceleration * time; if(accRequested > maxAccel) { --- 107,122 ---- mMoveState[LastProcessState] = mMoveState[stateIndex]; ! F32 time = theMove->time * 0.001; Point requestVel(theMove->right - theMove->left, theMove->down - theMove->up); ! requestVel *= (mTurbo ? TurboMaxVelocity : MaxVelocity); F32 len = requestVel.len(); ! if(len > (mTurbo ? TurboMaxVelocity : MaxVelocity)) ! requestVel *= (mTurbo ? TurboMaxVelocity : MaxVelocity) / len; Point velDelta = requestVel - mMoveState[stateIndex].vel; ! F32 accRequested = velDelta.len(); ! F32 maxAccel = (mTurbo ? TurboAcceleration : Acceleration) * time; if(accRequested > maxAccel) { *************** *** 135,138 **** --- 140,144 ---- mMoveState[RenderState] = mMoveState[ActualState]; setMaskBits(PositionMask); + if(!theMove->isEqualMove(&lastMove)) { *************** *** 140,143 **** --- 146,150 ---- setMaskBits(MoveMask); } + if(theMove->fire) { *************** *** 145,158 **** if(currentTime - lastFireTime > FireDelay) { lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); ! Point projVel = dir * 600 + dir * mMoveState[ActualState].vel.dot(dir); //mMoveState[ActualState].vel + dir * 500; Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * (CollisionRadius-1), projVel, 500, this); proj->addToGame(getGame()); } } updateExtent(); } void Ship::damageObject(DamageInfo *theInfo) { --- 152,216 ---- if(currentTime - lastFireTime > FireDelay) { + mEnergy -= 1.f; lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); ! Point projVel = dir * 600 + dir * mMoveState[ActualState].vel.dot(dir); Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * (CollisionRadius-1), projVel, 500, this); proj->addToGame(getGame()); } } + + if(mTurbo != theMove->boost || mShield != theMove->shield) + setMaskBits(PowersMask); + + mShield = theMove->shield; + mTurbo = theMove->boost; + + burnEnergy(theMove->time); updateExtent(); } + void Ship::burnEnergy( U32 dT ) + { + if(isGhost()) return; + + F32 scaleFactor = ((F32)dT) / 1000.f; + + // Update things based on available energy... + if(mEnergy <= 5.f || mCooldown) + { + mShield = false; + mTurbo = false; + mCooldown = true; + } + + if(mCooldown && mEnergy >= 15.f) + { + mCooldown = false; + } + + if(mShield) + { + mEnergy -= 7.0f * scaleFactor; + } + + if(mTurbo) + { + mEnergy -= 20.0f * scaleFactor; + } + + + if(mEnergy < 100.f) + { + mEnergy += (F32)(dT * RechargeRate) / 1000.f; + + if(mEnergy < 0.f) + mEnergy = 0.f; + } + + if(mEnergy >= 100.f) + mEnergy = 100.f; + } + void Ship::damageObject(DamageInfo *theInfo) { *************** *** 160,163 **** --- 218,228 ---- return; + // Factor in shields + if(mShield && mEnergy >= 10.f) + { + mEnergy -= 10.f; + return; + } + mHealth -= theInfo->damageAmount; setMaskBits(HealthMask); *************** *** 275,278 **** --- 340,344 ---- setMaskBits(PositionMask); } + burnEnergy(deltaT); updateExtent(); } *************** *** 286,289 **** --- 352,357 ---- stream->write(mMoveState[ActualState].vel.y); stream->write(mEnergy); + stream->writeFlag(mTurbo); + stream->writeFlag(mShield); } *************** *** 296,299 **** --- 364,369 ---- stream->read(&mMoveState[ActualState].vel.y); stream->read(&mEnergy); + mTurbo = stream->readFlag(); + mShield = stream->readFlag(); Point delta = mMoveState[ActualState].pos - mMoveState[RenderState].pos; *************** *** 334,337 **** --- 404,413 ---- stream->writeFloat(mHealth, 6); + if(stream->writeFlag(updateMask & PowersMask)) + { + stream->writeFlag(mTurbo); + stream->writeFlag(mShield); + } + stream->writeFlag(hasExploded); *************** *** 388,395 **** --- 464,479 ---- } } + if(stream->readFlag()) mHealth = stream->readFloat(6); + if(stream->readFlag()) + { + mTurbo = stream->readFlag(); + mShield = stream->readFlag(); + } + bool explode = stream->readFlag(); + if(stream->readFlag()) { *************** *** 625,630 **** if(leftId == mLastTrailPoint[0] && rightId == mLastTrailPoint[1]) { ! mTrail[0].update(leftPt); ! mTrail[1].update(rightPt); mLastTrailPoint[0] = leftId; mLastTrailPoint[1] = rightId; --- 709,714 ---- if(leftId == mLastTrailPoint[0] && rightId == mLastTrailPoint[1]) { ! mTrail[0].update(leftPt, mTurbo); ! mTrail[1].update(rightPt, mTurbo); mLastTrailPoint[0] = leftId; mLastTrailPoint[1] = rightId; *************** *** 632,637 **** else if(leftId == mLastTrailPoint[1] && rightId == mLastTrailPoint[0]) { ! mTrail[1].update(leftPt); ! mTrail[0].update(rightPt); mLastTrailPoint[1] = leftId; mLastTrailPoint[0] = rightId; --- 716,721 ---- else if(leftId == mLastTrailPoint[1] && rightId == mLastTrailPoint[0]) { ! mTrail[1].update(leftPt, mTurbo); ! mTrail[0].update(rightPt, mTurbo); mLastTrailPoint[1] = leftId; mLastTrailPoint[0] = rightId; *************** *** 639,644 **** else { ! mTrail[0].update(leftPt); ! mTrail[1].update(rightPt); mLastTrailPoint[0] = leftId; mLastTrailPoint[1] = rightId; --- 723,728 ---- else { ! mTrail[0].update(leftPt, mTurbo); ! mTrail[1].update(rightPt, mTurbo); mLastTrailPoint[0] = leftId; mLastTrailPoint[1] = rightId; *************** *** 652,658 **** return; - for(U32 i=0; i<TrailCount; i++) - mTrail[i].render(); - if(posSegments.size()) { --- 736,739 ---- *************** *** 725,728 **** --- 806,815 ---- thrusts[3] += 0.25; + if(mTurbo) + { + for(U32 i = 0; i < 4; i++) + thrusts[i] *= 1.3; + } + // first render the thrusters *************** *** 825,828 **** --- 912,916 ---- glVertex2f(12.5, 0); glEnd(); + glColor4f(color.r,color.g,color.b, alpha); glBegin(GL_LINE_LOOP); *************** *** 831,834 **** --- 919,923 ---- glVertex2f(12, -13); glEnd(); + U32 health = 14 * mHealth; glBegin(GL_LINES); *************** *** 848,851 **** --- 937,951 ---- glEnd(); + // Render shield if appropriate + if(mShield) + { + glColor4f(1,1,0, alpha); + glBegin(GL_LINE_LOOP); + glVertex2f(-23, -18); + glVertex2f(0, 27); + glVertex2f(23, -18); + glEnd(); + } + if(hasExploded) { *************** *** 854,857 **** --- 954,958 ---- } + glPopMatrix(); *************** *** 862,864 **** } ! }; \ No newline at end of file --- 963,965 ---- } ! }; |