Changeset 11608 for code/branches/Asteroid_HS17/src/modules/asteroids2D
- Timestamp:
- Nov 27, 2017, 5:00:59 PM (7 years ago)
- Location:
- code/branches/Asteroid_HS17/src/modules/asteroids2D
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc
r11593 r11608 35 35 #include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header! 36 36 #include "core/CoreIncludes.h" 37 37 #include "Highscore.h" 38 38 39 39 namespace orxonox … … 44 44 { 45 45 RegisterObject(Asteroids2D); 46 this->bEndGame = false;47 46 47 bEndGame = false; 48 lives = 1; 49 level = 1; 50 point = 0; 51 bShowLevel = false; 52 multiplier = 1; 53 b_combo = false; 54 counter = 5000; 55 pattern = 1; 56 lastPosition = 0; 57 // spawn enemy every 3.5 seconds 58 //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2D::spawnEnemy, this))); 59 this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 60 this->center_ = nullptr; 61 this->setHUDTemplate("Asteroids2DHUD"); 62 } 63 64 void Asteroids2D::levelUp() 65 { 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(&Asteroids2D::toggleShowLevel, this))); 48 85 } 49 86 50 87 void Asteroids2D::tick(float dt) 51 88 { 52 89 53 90 SUPER(Asteroids2D, tick, dt); 54 91 } … … 66 103 } 67 104 105 void Asteroids2D::costLife() 106 { 107 //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this))); 108 lives = 0; 109 }; 110 68 111 void Asteroids2D::start() 69 112 { 70 113 orxout() << "start" << endl; 71 114 72 115 // Set variable to temporarily force the player to spawn. 73 116 this->bForceSpawn_ = false; … … 83 126 } 84 127 128 void Asteroids2D::playerPreSpawn(PlayerInfo* player) 129 { 130 if(lives <= 0) 131 { 132 this->end(); 133 } 134 } 135 136 void Asteroids2D::addPoints(int numPoints) 137 { 138 if (!bEndGame) 139 { 140 point += numPoints * multiplier; 141 b_combo = true; 142 } 143 } 144 85 145 void Asteroids2D::end() 86 146 { … … 89 149 // It will misteriously crash the game! 90 150 // Instead startMainMenu, this won't crash. 91 orxout() << "Asteroids2D Game has ended" << endl; 151 if (Highscore::exists()){ 152 int score = this->getPoints(); 153 if(score > Highscore::getInstance().getHighestScoreOfGame("Dodge Race")) 154 Highscore::getInstance().storeHighscore("Dodge Race",score); 155 156 } 92 157 GSLevel::startMainMenu(); 93 158 } -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h
r11593 r11608 50 50 #include "gamestates/GSLevel.h" 51 51 #include "chat/ChatManager.h" 52 52 #include <vector> 53 53 54 54 // ! HACK … … 58 58 59 59 #include "gametypes/Deathmatch.h" 60 #include "tools/Timer.h" 60 61 61 62 namespace orxonox … … 69 70 virtual void start() override; 70 71 virtual void end() override; 72 71 73 virtual void tick(float dt) override; 74 75 virtual void playerPreSpawn(PlayerInfo* player) override; 76 77 void levelUp(); 78 79 int getLives(){return this->lives;} 80 int getLevel(){return this->level;} 81 int getPoints(){return this->point;} 82 int getMultiplier(){return this->multiplier;} 72 83 73 84 void setCenterpoint(Asteroids2DCenterPoint* center) 74 85 { this->center_ = center; } 86 virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command 75 87 76 virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command 88 // checks if multiplier should be reset. 89 void costLife(); 90 77 91 bool bEndGame; 92 bool bShowLevel; 93 int lives; 94 int multiplier; 95 float counter; 96 int pattern; 97 float currentPosition; 98 float lastPosition; 78 99 79 100 private: 80 101 Timer endGameTimer; 81 102 82 103 Asteroids2DShip* getPlayer(); 83 104 WeakPtr<Asteroids2DShip> player; 105 std::vector<Asteroids2DCube*> cubeList; 106 void toggleShowLevel(){bShowLevel = !bShowLevel;} 107 void addPoints(int numPoints); 108 84 109 WeakPtr<Asteroids2DCenterPoint> center_; 110 int level; 111 int point; 112 bool b_combo; 113 114 Timer enemySpawnTimer; 115 Timer comboTimer; 116 Timer showLevelTimer; 85 117 86 118 -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DCenterPoint.cc
r11593 r11608 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 37 38 38 39 #include "Asteroids2D.h" … … 47 48 48 49 this->checkGametype(); 50 this->width_ = 200; 51 this->height_ = 120; 49 52 } 53 /** 54 @brief 55 Method to create a Asteroids2DCenterpoint through XML. 56 */ 57 void Asteroids2DCenterPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 { 59 SUPER(Asteroids2DCenterPoint, XMLPort, xmlelement, mode); 50 60 61 XMLPortParam(Asteroids2DCenterPoint, "dimension", setFieldDimension, getFieldDimension, xmlelement, mode); 62 } 51 63 void Asteroids2DCenterPoint::checkGametype() 52 64 { -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DCenterPoint.h
r11593 r11608 49 49 public: 50 50 Asteroids2DCenterPoint(Context* context); //checks whether the gametype is actually Asteroids2D. 51 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method to create a PongCenterpoint through XML. 52 /** 53 @brief Set the dimensions of the playing field. 54 @param dimension A vector with the width of the playing field as first component and the height as second. 55 */ 56 void setFieldDimension(const Vector2& dimension) 57 { this->width_ = dimension.x; this->height_ = dimension.y; } 58 /** 59 @brief Get the dimensions of the playing field. 60 @return Returns a vector with the width of the playing field as first component and the height as second. 61 */ 62 Vector2 getFieldDimension() const 63 { return Vector2(this->width_, this->height_); } 51 64 52 65 private: 53 66 void checkGametype(); 67 float width_, height_; 54 68 55 69 }; -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc
r11593 r11608 25 25 */ 26 26 27 #include " DodgeRaceHUDinfo.h"27 #include "Asteroids2DHUDinfo.h" 28 28 29 29 #include "core/CoreIncludes.h" 30 30 #include "core/XMLPort.h" 31 31 #include "util/Convert.h" 32 //#include " DodgeRace.h"32 //#include "Asteroids2D.h" 33 33 34 34 namespace orxonox 35 35 { 36 RegisterClass( DodgeRaceHUDinfo);36 RegisterClass(Asteroids2DHUDinfo); 37 37 38 DodgeRaceHUDinfo::DodgeRaceHUDinfo(Context* context) : OverlayText(context)38 Asteroids2DHUDinfo::Asteroids2DHUDinfo(Context* context) : OverlayText(context) 39 39 { 40 RegisterObject( DodgeRaceHUDinfo);40 RegisterObject(Asteroids2DHUDinfo); 41 41 42 this-> DodgeRaceGame = nullptr;42 this->Asteroids2DGame = nullptr; 43 43 this->bShowPoints_ = true; 44 44 } 45 45 46 void DodgeRaceHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)46 void Asteroids2DHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) 47 47 { 48 SUPER( DodgeRaceHUDinfo, XMLPort, xmlelement, mode);48 SUPER(Asteroids2DHUDinfo, XMLPort, xmlelement, mode); 49 49 50 XMLPortParam( DodgeRaceHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false);50 XMLPortParam(Asteroids2DHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false); 51 51 } 52 52 53 void DodgeRaceHUDinfo::tick(float dt)53 void Asteroids2DHUDinfo::tick(float dt) 54 54 { 55 SUPER( DodgeRaceHUDinfo, tick, dt);55 SUPER(Asteroids2DHUDinfo, tick, dt); 56 56 57 57 58 58 if(this->bShowPoints_) 59 59 { 60 const std::string& points = multi_cast<std::string>(this-> DodgeRaceGame->getPoints());61 if (this-> DodgeRaceGame->lives <= 0)60 const std::string& points = multi_cast<std::string>(this->Asteroids2DGame->getPoints()); 61 if (this->Asteroids2DGame->lives <= 0) 62 62 { 63 63 setTextSize(0.2); … … 76 76 } 77 77 78 void DodgeRaceHUDinfo::changedOwner()78 void Asteroids2DHUDinfo::changedOwner() 79 79 { 80 SUPER( DodgeRaceHUDinfo, changedOwner);80 SUPER(Asteroids2DHUDinfo, changedOwner); 81 81 82 82 if (this->getOwner() && this->getOwner()->getGametype()) 83 83 { 84 this-> DodgeRaceGame = orxonox_cast<DodgeRace*>(this->getOwner()->getGametype());84 this->Asteroids2DGame = orxonox_cast<Asteroids2D*>(this->getOwner()->getGametype()); 85 85 } 86 86 else 87 87 { 88 this-> DodgeRaceGame = nullptr;88 this->Asteroids2DGame = nullptr; 89 89 } 90 90 } -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc
r11593 r11608 55 55 void Asteroids2DShip::tick(float dt) 56 56 { 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 // bring back on track!91 if(pos.y != 0)92 {93 pos.y = 0;94 }95 96 setPosition(pos);97 setOrientation(Vector3::UNIT_Y, Degree(270));98 99 57 SUPER(Asteroids2DShip, tick, dt); 100 58 } 101 59 102 void Asteroids2DShip::moveFrontBack(const Vector2& value) 60 void Asteroids2DShip::updateLevel() 61 { 62 lastTime = 0; 63 if (getGame()) 64 getGame()->levelUp(); 65 } 66 67 /* void Asteroids2DShip::moveFrontBack(const Vector2& value) 103 68 { 104 69 //lastTimeFront = 0; 105 70 //desiredVelocity.y = value.y * speed * 42; 106 71 orxout() << "FrontBack" << endl; 72 SUPER(Asteroids2DShip, moveFrontBack, value); 107 73 } 108 74 109 75 void Asteroids2DShip::moveRightLeft(const Vector2& value) 110 76 { 111 lastTimeLeft = 0; 112 desiredVelocity.x = value.x * speed; 77 //lastTimeLeft = 0; 78 //desiredVelocity.x = value.x * speed; 79 orxout() << "RightLeft" << endl; 80 SUPER(Asteroids2DShip, moveFrontBack, value); 113 81 } 82 */ 114 83 void Asteroids2DShip::boost(bool bBoost) 115 84 { … … 139 108 void Asteroids2DShip::death() 140 109 { 141 //getGame()->costLife();110 getGame()->costLife(); 142 111 SpaceShip::death(); 143 112 } -
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h
r11593 r11608 55 55 56 56 // overwrite for 2d movement 57 virtual void moveFrontBack(const Vector2& value) override;58 virtual void moveRightLeft(const Vector2& value) override;57 //virtual void moveFrontBack(const Vector2& value) override; 58 //virtual void moveRightLeft(const Vector2& value) override; 59 59 60 60 // Starts or stops fireing … … 62 62 63 63 //no rotation! 64 virtual void rotateYaw(const Vector2& value) override{}; 64 65 virtual void rotatePitch(const Vector2& value) override{}; 65 66 66 67 //return to main menu if game has ended. 67 68 virtual void rotateRoll(const Vector2& value) override{if (getGame()) if (getGame()->bEndGame) getGame()->end();}; 69 70 virtual void updateLevel(); 68 71 69 72 virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override; -
code/branches/Asteroid_HS17/src/modules/asteroids2D/CMakeLists.txt
r11593 r11608 1 SET_SOURCE_FILES( Asteroids2D_SRC_FILES1 SET_SOURCE_FILES(MINIGAMESTEST_SRC_FILES 2 2 Asteroids2D.cc 3 3 Asteroids2DCenterPoint.cc 4 4 Asteroids2DShip.cc 5 Asteroids2DCube.cc 6 Asteroids2DHUDinfo.cc 5 7 ) 6 8 … … 11 13 orxonox 12 14 overlays 13 SOURCE_FILES ${ ASTEROIDS2D_SRC_FILES}15 SOURCE_FILES ${MINIGAMESTEST_SRC_FILES} 14 16 )
Note: See TracChangeset
for help on using the changeset viewer.