Changeset 11859 for code/branches/3DPacman_FS18/src/modules
- Timestamp:
- Apr 12, 2018, 4:12:25 PM (7 years ago)
- Location:
- code/branches/3DPacman_FS18/src/modules/Pacman
- Files:
-
- 2 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.cc
r11844 r11859 34 34 #include "3DPacman.h" 35 35 #include "core/CoreIncludes.h" 36 #include "PacmanGelb.h" 37 #include "PacmanGhost.h" 38 #include "PacmanPointSphere.h" 36 39 37 40 namespace orxonox … … 43 46 RegisterObject(3DPacman); 44 47 45 bEndGame = false;46 lives = 1;48 lives = 3; 49 point = 0: 47 50 level = 1; 48 point = 0;49 bShowLevel = false;50 multiplier = 1;51 b_combo = false;52 counter = 5000;53 pattern = 1;54 lastPosition = 0;55 // spawn enemy every 3.5 seconds56 //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));57 comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));58 this->numberOfBots_ = 0; //sets number of default bots temporarly to 059 this->center_ = nullptr;60 51 61 this->setHUDTemplate("DodgeRaceHUD");62 52 } 63 53 64 void DodgeRace::levelUp()54 void 3DPacman::levelUp() 65 55 { 66 level++; 67 if (getPlayer() != nullptr) 68 { 69 for (int i = 0; i < 7; i++) 70 { 71 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); 72 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); 73 chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() 74 chunk5->setScale(10); 75 chunk5->setEffect1("Orxonox/explosion2b"); 76 chunk5->setEffect2("Orxonox/smoke6"); 77 chunk5->Explode(); 78 79 } 80 } 81 addPoints(multiplier * 42); 82 multiplier *= 2; 83 toggleShowLevel(); 84 showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); 56 this->end(); 85 57 } 86 58 87 void DodgeRace::tick(float dt) 59 60 PacmanGhost[4] ghosts; 61 PacmanPointSphere[1] spheres; 62 63 64 void 3DPacman::tick(float dt) 88 65 { 89 DodgeRaceShip* player = this->getPlayer(); 66 int i = 0; 67 for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ 68 ghosts[i] = nextghost; 69 i++; 70 } 71 72 i = 0: 73 for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ 74 spheres[i] = nextsphere; 75 i++; 76 } 77 78 player = this->getPlayer(); 90 79 if (player != nullptr) 91 80 { 92 currentPosition = player->getWorldPosition().x; 93 counter = counter + (currentPosition - lastPosition); 94 lastPosition = currentPosition; 95 point = (int) currentPosition; 96 player->speed = 830.0f - (point / 1000); 81 currentPosition = player->getWorldPosition(); 82 } 97 83 98 for(unsigned int i=0; i < cubeList.size();i++) 99 { 100 if(cubeList.at(i)->getPosition().x < currentPosition-3000) 101 { 102 cubeList.at(i)->destroy(); 103 cubeList.erase(cubeList.begin()+i); 104 } 105 } 84 bool bcolli = false; 85 for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){ 86 bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition) 87 } 88 if(collis){ 89 this->catched(); 90 } 106 91 107 if(counter >= 3000) 108 { 109 counter = 0; 110 for(int i = 0; i<6; i++) 111 { 112 DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext()); 113 cubeList.push_back(cube); 114 switch(pattern) 115 { 116 case 1: cube->addTemplate("DodgeRaceCube01"); 117 break; 118 case 2: cube->addTemplate("DodgeRaceCube02"); 119 break; 92 SUPER(3DPacman, tick, dt); 120 93 121 } 122 123 cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); 124 //stEntity->setScale3D(50,50,50); 125 } 94 } 126 95 127 96 128 pattern %= 2;129 pattern ++;130 97 131 }132 133 }134 SUPER(DodgeRace, tick, dt);98 bool 3DPacman::collis(Vector3 one, Vector3 other){ 99 if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1)) 100 return true; 101 return false; 135 102 } 136 103 137 DodgeRaceShip* DodgeRace::getPlayer() 104 void 3DPacman::catched(){ 105 if(lives) this->end(); 106 --lives; 107 this->posreset(); 108 } 109 110 void 3DPacman::posreset(){ 111 int i = 0; 112 for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ 113 ghosts[i] = nextghost; 114 i++; 115 } 116 117 } 118 119 120 PacmanGelb* 3DPacman::getPlayer() 138 121 { 139 for ( DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())122 for (PacmanGelb* ship : ObjectList<PacmanGelb>()) 140 123 { 141 124 return ship; … … 144 127 } 145 128 146 void DodgeRace::costLife()147 {148 //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));149 lives = 0;150 };151 129 152 void DodgeRace::comboControll() 153 { 154 if (b_combo) 155 multiplier++; 156 // if no combo was performed before, reset multiplier 157 else 158 multiplier = 1; 159 b_combo = false; 160 } 161 162 void DodgeRace::start() 130 void 3DPacman::start() 163 131 { 164 132 orxout() << "start" << endl; 165 for(unsigned int i=0; i< cubeList.size();i++) 166 { 167 cubeList.at(i)->destroy(); 168 cubeList.erase(cubeList.begin()+i); 169 170 } 171 cubeList.clear(); 172 // Set variable to temporarily force the player to spawn. 173 this->bForceSpawn_ = false; 174 175 if (this->center_ == nullptr) // abandon mission! 176 { 177 orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; 178 GSLevel::startMainMenu(); 179 return; 180 } 181 // Call start for the parent class. 133 182 134 Deathmatch::start(); 183 135 } 184 136 185 void DodgeRace::playerPreSpawn(PlayerInfo* player)137 void 3DPacman::playerPreSpawn(PlayerInfo* player) 186 138 { 187 139 this->playerInfo_ = player; … … 190 142 this->end(); 191 143 } 192 193 // Reset all the cubes194 /*195 orxout() << "prespawn" << endl;196 for(int i=0; i< cubeList.size();i++)197 {198 cubeList.at(i)->destroy();199 cubeList.erase(cubeList.begin()+i);200 }201 cubeList.clear();202 lives = 1;203 point = 0;204 lastPosition = 0;205 */206 144 } 207 145 208 void DodgeRace::addPoints(int numPoints)209 {210 if (!bEndGame)211 {212 point += numPoints * multiplier;213 b_combo = true;214 }215 }216 146 217 void DodgeRace::end()147 void 3DPacman::end() 218 148 { 219 149 // DON'T CALL THIS! … … 224 154 { 225 155 int score = this->getPoints(); 226 Highscore::getInstance().storeScore(" Dodge Race", score, this->playerInfo_);156 Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); 227 157 } 228 158 GSLevel::startMainMenu(); -
code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.h
r11844 r11859 42 42 43 43 //#include "DodgeRaceHUDinfo.h" 44 #include "PacmanGelb.h" 44 45 45 46 … … 63 64 { 64 65 65 class _ DodgeRaceExport DodgeRace: public Deathmatch66 class _3DPacmanExport 3DPacman : public Deathmatch 66 67 { 67 68 public: 68 DodgeRace(Context* context);69 3DPacman(Context* context); 69 70 70 71 virtual void start() override; … … 100 101 101 102 private: 103 PacmanGelb* player; 104 PacmanGhost[] 105 Vector3 currentPosition; 106 107 108 102 109 Timer endGameTimer; 103 110 -
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.cc
r11849 r11859 46 46 RegisterObject(PacmanGhost); 47 47 48 this->localLinearAcceleration_.setValue(1, 1, 1);49 this->localAngularAcceleration_.setValue(1, 1, 1);50 51 48 this->velocity = Vector3(0, 0, 0); 52 49 … … 79 76 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 80 77 81 XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);82 XMLPortParam(PacmanGhost, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);83 XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);84 78 XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode); 85 79 } … … 87 81 88 82 89 Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215, 0,240)};83 Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,220)}; 90 84 91 85 /** … … 99 93 SUPER(PacmanGhost, tick, dt); 100 94 101 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_); 102 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_); 103 if (this->localLinearAcceleration_.z() > 0) 104 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_); 105 else 106 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 107 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 108 this->localLinearAcceleration_.setValue(0, 0, 0); 109 110 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 111 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 112 this->localAngularAcceleration_.setValue(0, 0, 0); 113 95 //setorientation 114 96 115 97 this->actuelposition = this->getPosition(); 116 98 117 99 //Stop, if target arrived 118 if(( (this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){100 if((abs(this->actuelposition.x - this->target_x)<0.1) && (abs(this->actuelposition.z - this->target_z)<0.1)){ 119 101 this->ismoving = false; 120 102 } … … 122 104 //Move, if ghost hasn't arrived yet 123 105 if(this->ismoving){ 124 if(!( (this->actuelposition.z-target_z)<0.1)) {125 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x), -sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));106 if(!(abs(this->actuelposition.z-target_z)<0.1)) { 107 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z)); 126 108 move(dt, actuelposition, velocity); 127 109 } 128 if(!( (this->actuelposition.x-target_x)<0.1)){129 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x), -sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));110 if(!(abs(this->actuelposition.x-target_x)<0.1)){ 111 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z)); 130 112 move(dt, actuelposition, velocity); 131 113 } … … 134 116 //Check on which position ghost has arrived and set new target 135 117 else{ 136 if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[0].z)<0.1)){ 137 this->target_x = possibleposition[1].x; 138 this->target_z = possibleposition[1].z; 139 this->ismoving = true; 118 if((abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){ 119 decision = rand()%1; 120 switch(decision){ 121 case 0: 122 this->target_x = possibleposition[1].x; 123 this->target_z = possibleposition[1].z; 124 this->ismoving = true; 140 125 } 141 else if(((actuelposition.x - possibleposition[1].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){ 142 this->target_x = possibleposition[0].x; 143 this->target_z = possibleposition[0].z; 144 this->ismoving = true; 126 145 127 } 128 else if((abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){ 129 decision = rand()%2; 130 switch(decision){ 131 case 0: 132 this->target_x = possibleposition[0].x; 133 this->target_z = possibleposition[0].z; 134 this->ismoving = true; 135 break; 136 case 1: 137 this->target_x = possibleposition[2].x; 138 this->target_z = possibleposition[2].z; 139 this->ismoving = true; 140 } 141 142 } 143 if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){ 144 decision = rand()%1; 145 switch(decision){ 146 case 0: 147 this->target_x = possibleposition[1].x; 148 this->target_z = possibleposition[1].z; 149 this->ismoving = true; 150 } 151 152 } 153 146 154 else{ 147 155 } //End of Position table … … 151 159 152 160 153 154 161 void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){ 155 156 this->setPosition(Vector3(actuelposition.x+velocity.x*dt,actuelposition.y+velocity.y*dt ,actuelposition.z+velocity.z*dt)); 162 this->setPosition(Vector3(actuelposition.x+20*velocity.x*dt,10,actuelposition.z+20*velocity.z*dt)); 157 163 } 158 164 159 160 /** 161 @brief 162 Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. 163 @param value 164 The vector determining the amount of the movement. 165 */ 166 void PacmanGhost::moveFrontBack(const Vector2& value) 167 { 168 //this->setPosition(dt*(actuelposition + velocity_)); 165 void PacmanGhost::resetGhost(){ 166 this->setPosition(resetposition); 169 167 } 170 171 /**172 @brief173 Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.174 @param value175 The vector determining the amount of the movement.176 */177 void PacmanGhost::moveRightLeft(const Vector2& value)178 {179 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);180 }181 182 /**183 @brief184 Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.185 @param value186 The vector determining the amount of the movement.187 */188 void PacmanGhost::moveUpDown(const Vector2& value)189 {190 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);191 }192 193 /**194 @brief195 Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.196 @param value197 The vector determining the amount of the angular movement.198 */199 void PacmanGhost::rotateYaw(const Vector2& value)200 {201 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);202 }203 204 /**205 @brief206 Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.207 @param value208 The vector determining the amount of the angular movement.209 */210 void PacmanGhost::rotatePitch(const Vector2& value)211 {212 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);213 }214 215 /**216 @brief217 Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.218 @param value219 The vector determining the amount of the angular movement.220 */221 void PacmanGhost::rotateRoll(const Vector2& value)222 {223 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);224 }225 226 168 } -
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.h
r11850 r11859 47 47 virtual void tick(float dt); //!< Defines which actions the AutonomousDrone has to take in each tick. 48 48 49 virtual void moveFrontBack(const Vector2& value);50 virtual void moveRightLeft(const Vector2& value);51 virtual void moveUpDown(const Vector2& value);52 53 virtual void rotateYaw(const Vector2& value);54 virtual void rotatePitch(const Vector2& value);55 virtual void rotateRoll(const Vector2& value);56 57 49 void move(float dt, Vector3 actuelposition, Vector3 velocity); 58 50 59 //virtual void resetGhost(); 60 /** 61 @brief Moves the Drone in the Front/Back-direction by the specifed amount. 62 @param value The amount by which the drone is to be moved. 63 */ 64 inline void moveFrontBack(float value) 65 { this->moveFrontBack(Vector2(value, 0)); } 66 /** 67 @brief Moves the Drone in the Right/Left-direction by the specifed amount. 68 @param value The amount by which the drone is to be moved. 69 */ 70 inline void moveRightLeft(float value) 71 { this->moveRightLeft(Vector2(value, 0)); } 72 /** 73 @brief Moves the Drone in the Up/Down-direction by the specifed amount. 74 @param value The amount by which the drone is to be moved. 75 */ 76 inline void moveUpDown(float value) 77 { this->moveUpDown(Vector2(value, 0)); } 78 79 /** 80 @brief Rotates the Drone around the y-axis by the specifed amount. 81 @param value The amount by which the drone is to be rotated. 82 */ 83 inline void rotateYaw(float value) 84 { this->rotateYaw(Vector2(value, 0)); } 85 /** 86 @brief Rotates the Drone around the x-axis by the specifed amount. 87 @param value The amount by which the drone is to be rotated. 88 */ 89 inline void rotatePitch(float value) 90 { this->rotatePitch(Vector2(value, 0)); } 91 /** 92 @brief Rotates the Drone around the z-axis by the specifed amount. 93 @param value The amount by which the drone is to be rotated. 94 */ 95 inline void rotateRoll(float value) 96 { this->rotateRoll(Vector2(value, 0)); } 97 98 /** 99 @brief Sets the primary thrust to the input amount. 100 @param thrust The amount of thrust. 101 */ 102 inline void setPrimaryThrust( float thrust ) 103 { this->primaryThrust_ = thrust; } 104 inline void setAuxiliaryThrust( float thrust ) 105 { this->auxiliaryThrust_ = thrust; } 106 inline void setRotationThrust( float thrust ) 107 { this->rotationThrust_ = thrust; } 51 void resetGhost(); 108 52 109 53 inline void setResetPosition(Vector3 rpos) 110 54 { this->resetposition = rpos; } 111 112 /**113 @brief Gets the primary thrust to the input amount.114 @return The amount of thrust.115 */116 inline float getPrimaryThrust()117 { return this->primaryThrust_; }118 inline float getAuxiliaryThrust()119 { return this->auxiliaryThrust_; }120 inline float getRotationThrust()121 { return this->rotationThrust_; }122 55 123 56 inline Vector3 getResetPosition() … … 127 60 128 61 private: 129 130 btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the AutonomousDrone the next tick.131 btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the AutonomousDrone the next tick.132 float primaryThrust_=100; //!< The amount of primary thrust. This is just used, when moving forward.133 float auxiliaryThrust_=100; //!< The amount of auxilliary thrust. Used for all other movements (except for rotations).134 float rotationThrust_=100; //!< The amount of rotation thrust. Used for rotations only.s135 //Vector3 resetposition; //Start position for Ghost136 137 PacmanGhost* myGhost = nullptr;138 139 62 bool ismoving = false; 63 int decision = 0; //Gives the random which way information to the ghost. 140 64 int target_x = 0; 141 65 int target_z = 0; -
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanPointSphere.cc
r11844 r11859 27 27 */ 28 28 29 #include "Pacman Ghost.h"29 #include "PacmanPointSphere.h" 30 30 31 31 #include "core/CoreIncludes.h" … … 34 34 namespace orxonox 35 35 { 36 RegisterClass(Pacman Ghost);36 RegisterClass(PacmanPointSphere); 37 37 38 38 /** … … 42 42 The creator of this object. 43 43 */ 44 Pacman Ghost::PacmanGhost(Context* context) : ControllableEntity(context)44 PacmanPointSphere::PacmanPointSphere(Context* context) : ControllableEntity(context) 45 45 { 46 RegisterObject(PacmanGhost); 47 48 this->myController_ = NULL; 49 50 this->localLinearAcceleration_.setValue(0, 0, 0); 51 this->localAngularAcceleration_.setValue(0, 0, 0); 52 this->primaryThrust_ = 100; 53 this->auxiliaryThrust_ = 100; 54 this->rotationThrust_ = 10; 55 56 this->setCollisionType(CollisionType::Dynamic); 46 RegisterObject(PacmanPointSphere); 47 this->setCollisionType(CollisionType::none); 57 48 } 58 49 … … 61 52 Destructor. Destroys controller, if present. 62 53 */ 63 Pacman Ghost::~PacmanGhost()54 PacmanPointSphere::~PacmanPointSphere() 64 55 { 65 56 // Deletes the controller if the object was initialized and the pointer to the controller is not NULL. 66 if( this->isInitialized() && this->myController_ != NULL )67 delete this->myController_;68 57 } 69 58 … … 72 61 Method for creating a AutonomousDrone through XML. 73 62 */ 74 void Pacman Ghost::XMLPort(Element& xmlelement, XMLPort::Mode mode)63 void PacmanPointSphere::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 64 { 76 // This calls the XMLPort function of the parent class 77 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 65 SUPER(PacmanPointSphere, XMLPort, xmlelement, mode); 78 66 79 XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); 80 // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort. 81 // Variables can be added by the following command 82 // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode); 83 // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there. 67 XMLPortParam(PacmanPointSphere, "resetposition", setResetPosition, getResetPosition, xmlelement, mode); 84 68 } 85 69 86 /** 87 @brief 88 Defines which actions the AutonomousDrone has to take in each tick. 89 @param dt 90 The length of the tick. 91 */ 92 void PacmanGhost::tick(float dt) 70 71 void PacmanPointSphere::tick(float dt) 93 72 { 94 73 SUPER(PacmanGhost, tick, dt); 95 96 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);97 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);98 if (this->localLinearAcceleration_.z() > 0)99 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);100 else101 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);102 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);103 this->localLinearAcceleration_.setValue(0, 0, 0);104 105 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;106 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);107 this->localAngularAcceleration_.setValue(0, 0, 0);108 109 74 } 110 75 111 /** 112 @brief 113 Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. 114 @param value 115 The vector determining the amount of the movement. 116 */ 117 void PacmanGhost::moveFrontBack(const Vector2& value) 76 bool PacmanPointSphere::taken(Vector3 playerpos) 118 77 { 119 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 78 if((abs(this->resetposition.x - playerpos.x)<0.1) && (abs(this->resetposition.z - playerpos.z)<0.1)){ 79 this->setPosition(Vector3(resetposition.x, -50, resetposition.z)); 80 return true; 81 } 82 83 return false; 120 84 } 121 85 122 /** 123 @brief 124 Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector. 125 @param value 126 The vector determining the amount of the movement. 127 */ 128 void PacmanGhost::moveRightLeft(const Vector2& value) 129 { 130 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 86 87 void PacmanPointSphere::resetPacmanPointSphere(){ 88 this->setPosition(resetposition); 131 89 } 132 133 /**134 @brief135 Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.136 @param value137 The vector determining the amount of the movement.138 */139 void PacmanGhost::moveUpDown(const Vector2& value)140 {141 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);142 }143 144 /**145 @brief146 Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.147 @param value148 The vector determining the amount of the angular movement.149 */150 void PacmanGhost::rotateYaw(const Vector2& value)151 {152 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);153 }154 155 /**156 @brief157 Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.158 @param value159 The vector determining the amount of the angular movement.160 */161 void PacmanGhost::rotatePitch(const Vector2& value)162 {163 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);164 }165 166 /**167 @brief168 Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.169 @param value170 The vector determining the amount of the angular movement.171 */172 void PacmanGhost::rotateRoll(const Vector2& value)173 {174 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);175 }176 177 90 } -
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanPointSphere.h
r11844 r11859 27 27 */ 28 28 29 #ifndef _Pacman Ghost_H__30 #define _Pacman Ghost_H__29 #ifndef _PacmanPointSphere_H__ 30 #define _PacmanPointSphere_H__ 31 31 32 32 #include "OrxonoxPrereqs.h" 33 33 34 34 #include "core/XMLPort.h" 35 #include "controllers/PacmanGhostController.h"36 35 37 #include " ControllableEntity.h"36 #include "worldentities/ControllableEntity.h" 38 37 39 38 namespace orxonox { 40 39 41 class _OrxonoxExport Pacman Ghost: public ControllableEntity40 class _OrxonoxExport PacmanPointSphere : public ControllableEntity 42 41 { 43 42 public: 44 Pacman Ghost(Context* context);45 virtual ~Pacman Ghost();43 PacmanPointSphere(Context* context); 44 virtual ~PacmanPointSphere(); 46 45 47 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating an AutonomousDrone through XML. 48 47 virtual void tick(float dt); //!< Defines which actions the AutonomousDrone has to take in each tick. 49 48 50 virtual void moveFrontBack(const Vector2& value); 51 virtual void moveRightLeft(const Vector2& value); 52 virtual void moveUpDown(const Vector2& value); 49 bool taken(Vector3 playerpos); 50 void resetPacmanPointSphere(); 53 51 54 virtual void rotateYaw(const Vector2& value); 55 virtual void rotatePitch(const Vector2& value); 56 virtual void rotateRoll(const Vector2& value); 57 58 /** 59 @brief Moves the Drone in the Front/Back-direction by the specifed amount. 60 @param value The amount by which the drone is to be moved. 61 */ 62 inline void moveFrontBack(float value) 63 { this->moveFrontBack(Vector2(value, 0)); } 64 /** 65 @brief Moves the Drone in the Right/Left-direction by the specifed amount. 66 @param value The amount by which the drone is to be moved. 67 */ 68 inline void moveRightLeft(float value) 69 { this->moveRightLeft(Vector2(value, 0)); } 70 /** 71 @brief Moves the Drone in the Up/Down-direction by the specifed amount. 72 @param value The amount by which the drone is to be moved. 73 */ 74 inline void moveUpDown(float value) 75 { this->moveUpDown(Vector2(value, 0)); } 76 77 /** 78 @brief Rotates the Drone around the y-axis by the specifed amount. 79 @param value The amount by which the drone is to be rotated. 80 */ 81 inline void rotateYaw(float value) 82 { this->rotateYaw(Vector2(value, 0)); } 83 /** 84 @brief Rotates the Drone around the x-axis by the specifed amount. 85 @param value The amount by which the drone is to be rotated. 86 */ 87 inline void rotatePitch(float value) 88 { this->rotatePitch(Vector2(value, 0)); } 89 /** 90 @brief Rotates the Drone around the z-axis by the specifed amount. 91 @param value The amount by which the drone is to be rotated. 92 */ 93 inline void rotateRoll(float value) 94 { this->rotateRoll(Vector2(value, 0)); } 95 96 /** 97 @brief Sets the primary thrust to the input amount. 98 @param thrust The amount of thrust. 99 */ 100 inline void setPrimaryThrust( float thrust ) 101 { this->primaryThrust_ = thrust; } 102 //TODO: Place your set-functions here. 103 // Hint: auxiliary thrust, rotation thrust. 52 inline void setResetPosition(Vector3 rpos) 53 { this->resetposition = rpos; } 104 54 105 /** 106 @brief Gets the primary thrust to the input amount. 107 @return The amount of thrust. 108 */ 109 inline float getPrimaryThrust() 110 { return this->primaryThrust_; } 111 //TODO: Place your get-functions here. 55 inline Vector3 getResetPosition() 56 { return this->resetposition; } 112 57 113 58 private: 114 PacmanGhostController *myController_; //!< The controller of the AutonomousDrone. 115 116 btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the AutonomousDrone the next tick. 117 btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the AutonomousDrone the next tick. 118 float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward. 119 float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations). 120 float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s 121 59 60 Vector3 resetposition; 122 61 }; 123 62
Note: See TracChangeset
for help on using the changeset viewer.