Changeset 10661
- Timestamp:
- Oct 19, 2015, 2:53:51 PM (9 years ago)
- Location:
- code/branches/hoverHS15/src/modules/hover
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hoverHS15/src/modules/hover/HoverShip.cc
r10659 r10661 42 42 { 43 43 RegisterObject(HoverShip); 44 45 speed = 830;46 isFireing = false;47 damping = 10;48 49 // not sure if has to be zero?50 lastTimeFront = 0;51 lastTimeLeft = 0;52 lastTime = 0;53 44 } 54 45 55 46 void HoverShip::tick(float dt) 56 47 { 57 Vector3 pos = getPosition();58 59 //Movement calculation60 lastTimeFront += dt * damping;61 lastTimeLeft += dt * damping;62 lastTime += dt;63 64 velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);65 velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);66 67 //Execute movement68 if (this->hasLocalController())69 {70 float dist_y = velocity.y * dt;71 //float dist_x = velocity.x * dt;72 if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)73 posforeward += dist_y;74 else75 {76 velocity.y = 0;77 // restart if game ended78 /*79 if (getGame())80 if (getGame()->bEndGame)81 {82 getGame()->start();83 return;84 }*/85 }86 87 pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;88 }89 90 91 // Camera92 Camera* camera = this->getCamera();93 if (camera != NULL)94 {95 // camera->setPosition(Vector3(-pos.z, -posforeward, 0));96 camera->setOrientation(Vector3::UNIT_Z, Degree(0));97 }98 99 100 101 // bring back on track!102 if(pos.y != 0)103 {104 pos.y = 0;105 }106 107 setPosition(pos);108 setOrientation(Vector3::UNIT_Y, Degree(270));109 110 // Level up!111 if (pos.x > 42000)112 {113 updateLevel();114 setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)115 }116 117 48 SUPER(HoverShip, tick, dt); 118 }119 120 void HoverShip::updateLevel()121 {122 lastTime = 0;123 if (getGame())124 getGame()->levelUp();125 }126 127 void HoverShip::moveFrontBack(const Vector2& value)128 {129 //lastTimeFront = 0;130 //desiredVelocity.y = value.y * speed * 42;131 132 }133 134 void HoverShip::moveRightLeft(const Vector2& value)135 {136 lastTimeLeft = 0;137 desiredVelocity.x = value.x * speed;138 }139 void HoverShip::boost(bool bBoost)140 {141 //getGame()->bEndGame = bBoost;142 }143 144 inline bool HoverShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)145 {146 147 removeHealth(100);148 this->death();149 return false;150 49 } 151 50 152 51 Hover* HoverShip::getGame() 153 52 { 154 if (game == NULL)53 /*if (game == NULL) 155 54 { 156 55 for (ObjectList<Hover>::iterator it = ObjectList<Hover>::begin(); it != ObjectList<Hover>::end(); ++it) … … 159 58 } 160 59 } 161 return game; 162 } 163 164 void HoverShip::death() 165 { 166 getGame()->costLife(); 167 SpaceShip::death(); 60 return game;*/ 168 61 } 169 62 } -
code/branches/hoverHS15/src/modules/hover/HoverShip.h
r10659 r10661 43 43 44 44 #include "Hover.h" // Is necessary for getGame function 45 //#include "DodgeRaceCenterPoint.h"46 45 47 46 namespace orxonox 48 47 { 49 class _ DodgeRaceExport DodgeRaceShip : public SpaceShip48 class _HoverExport HoverShip : public SpaceShip 50 49 { 51 50 public: 52 DodgeRaceShip(Context* context);51 HoverShip(Context* context); 53 52 54 53 virtual void tick(float dt); 55 56 // overwrite for 2d movement57 virtual void moveFrontBack(const Vector2& value);58 virtual void moveRightLeft(const Vector2& value);59 60 // Starts or stops fireing61 virtual void boost(bool bBoost);62 63 //no rotation!64 virtual void rotateYaw(const Vector2& value){};65 virtual void rotatePitch(const Vector2& value){};66 67 //return to main menu if game has ended.68 virtual void rotateRoll(const Vector2& value){if (getGame()) if (getGame()->bEndGame) getGame()->end();};69 70 virtual void updateLevel();71 72 float speed, damping, posforeward;73 bool isFireing;74 75 protected:76 virtual void death();77 78 private:79 virtual inline bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);80 DodgeRace* getGame();81 WeakPtr<DodgeRace> game;82 WeakPtr<WorldEntity> lastEntity;83 Camera* camera;84 float lastTimeFront, lastTimeLeft, lastTime;85 struct Velocity86 {87 float x;88 float y;89 } velocity, desiredVelocity;90 54 91 55 };
Note: See TracChangeset
for help on using the changeset viewer.