1 ///////////////////////////////////////// 2 // 3 // OpenLieroX 4 // 5 // code under LGPL, based on JasonBs work, 6 // enhanced by Dark Charlie and Albert Zeyer 7 // 8 // 9 ///////////////////////////////////////// 10 11 12 // Ninja rope class 13 // Created 6/2/02 14 // Jason Boettcher 15 16 17 #ifndef __CNINJAROPE_H__ 18 #define __CNINJAROPE_H__ 19 20 #include "CVec.h" 21 22 class CGameScript; 23 class CWorm; 24 struct SDL_Surface; 25 class CBytestream; 26 27 28 class CNinjaRope { 29 public: 30 // Constructor CNinjaRope()31 CNinjaRope() { 32 Clear(); 33 34 LastWrite = AbsTime(); 35 LastPosUpdate = AbsTime(); 36 Strength = 0.4f; 37 } 38 39 40 private: 41 // Attributes 42 43 bool Released; 44 bool HookShooting; 45 bool HookAttached; 46 bool PlayerAttached; 47 CWorm *Worm; 48 float RopeLength; 49 float RestLength; 50 51 float MinLength; 52 53 float Strength; 54 55 CVec HookVelocity; 56 57 CVec HookPos; 58 CVec HookDir; 59 CVec OldHookPos; 60 61 // Used for writeNeeded check 62 bool LastReleased; 63 bool LastHookShooting; 64 bool LastHookAttached; 65 bool LastPlayerAttached; 66 CWorm *LastWorm; 67 AbsTime LastWrite; 68 AbsTime LastPosUpdate; // Used for velocity counting (client don't send velocity) 69 70 71 public: 72 // Methods 73 74 void Clear(); 75 76 void Draw(SDL_Surface * bmpDest, CViewport *view, CVec ppos); 77 void Shoot(CWorm* owner, CVec pos, CVec dir); 78 79 CVec GetForce(CVec playerpos); 80 CVec CalculateForce(CVec playerpos); 81 82 83 void Setup(CGameScript *gs); 84 isReleased()85 int isReleased() { return Released; } 86 void Release(); 87 void UnAttachPlayer(); 88 void AttachToPlayer(CWorm *worm, CWorm *owner); 89 90 void updateCheckVariables(); 91 bool writeNeeded(); 92 void write(CBytestream *bs); 93 void read(CBytestream *bs, CWorm *worms, int owner); 94 getHookPos()95 CVec getHookPos() const { return HookPos; } isAttached()96 bool isAttached() const { return HookAttached; } isShooting()97 bool isShooting() const { return HookShooting; } setShooting(bool s)98 void setShooting(bool s) { HookShooting = s; } setAttached(bool a)99 void setAttached(bool a) { HookAttached = a; } getRestLength()100 float getRestLength() const { return RestLength; } getMaxLength()101 float getMaxLength() const { return RopeLength; } 102 updateOldHookPos()103 void updateOldHookPos() { OldHookPos = HookPos; } 104 getHookVel()105 const CVec& getHookVel() const { return HookVelocity; } hookVelocity()106 CVec& hookVelocity() { return HookVelocity; } hookPos()107 CVec& hookPos() { return HookPos; } 108 isPlayerAttached()109 bool isPlayerAttached() { return PlayerAttached; } getAttachedPlayer()110 CWorm* getAttachedPlayer() { return Worm; } 111 112 void changeRestLength(float); 113 114 }; 115 116 117 118 #endif // __CNINJAROPE_H__ 119