Changeset 11516 for code/branches
- Timestamp:
- Oct 30, 2017, 4:04:29 PM (7 years ago)
- Location:
- code/branches/Asteroid_HS17
- Files:
-
- 5 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
r11506 r11516 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Florian Zinggeler 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file Invader.cc 31 @brief Implementation of the Invader class. 32 */ 33 1 34 #include "Asteroids.h" 35 #include "Highscore.h" 36 #include "core/CoreIncludes.h" 37 #include "core/EventIncludes.h" 38 #include "core/command/Executor.h" 39 #include "core/config/ConfigValueIncludes.h" 40 41 #include "gamestates/GSLevel.h" 42 #include "chat/ChatManager.h" 43 44 // ! HACK 45 #include "infos/PlayerInfo.h" 46 47 #include "AsteroidsCenterPoint.h" 48 #include "AsteroidsShip.h" 49 50 #include "core/command/ConsoleCommand.h" 51 #include "worldentities/ExplosionPart.h" 2 52 3 53 namespace orxonox 4 54 { 5 55 RegisterUnloadableClass(Asteroids); 6 56 7 Asteroids::Asteroids(Context* context) : Deathmatch(context) 8 { 9 level = 1; 10 this->numberOfBots = 0; 11 } 57 Asteroids::Asteroids(Context* context) : Deathmatch(context) 58 { 59 RegisterObject(Asteroids); 60 this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 61 this->center_ = nullptr; 62 bEndGame = false; 63 lives = 3; 64 point = 0; 12 65 13 void Asteroids::spawnAsteroid(); 66 } 14 67 15 void Asteroids::setCenterpoint(InvaderCenterPoint* center) 68 69 AsteroidsShip* Asteroids::getPlayer() 70 { 71 if (player == nullptr) 72 { 73 for (Asteroids* ship : ObjectList<AsteroidsShip>()) 74 player = ship; 75 } 76 return player; 77 } 78 79 80 void Asteroids::setCenterpoint(AsteroidsCenterPoint* center) 16 81 { 17 82 this->center_ = center; 18 83 } 19 84 20 void Asteroids::start(); 21 void Asteroids::end(); 22 85 void Asteroids::costLife() 86 { 87 lives = 0; 88 }; 89 90 void Asteroids::start() 91 { 92 // Set variable to temporarily force the player to spawn. 93 this->bForceSpawn_ = true; 94 95 if (this->center_ == nullptr) // abandon mission! 96 { 97 orxout(internal_error) << "Invader: No Centerpoint specified." << endl; 98 GSLevel::startMainMenu(); 99 return; 100 } 101 // Call start for the parent class. 102 Deathmatch::start(); 103 } 104 105 void Asteroids::addPoints(int numPoints) 106 { 107 if (!bEndGame) 108 { 109 point += numPoints; 110 } 111 } 112 113 void Asteroids::end() 114 { 115 // DON'T CALL THIS! 116 // Deathmatch::end(); 117 // It will misteriously crash the game! 118 // Instead startMainMenu, this won't crash. 119 GSLevel::startMainMenu(); 120 } 23 121 } -
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
r11506 r11516 33 33 */ 34 34 35 #ifndef _ Invader_H__36 #define _ Invader_H__35 #ifndef _Asteroids_H__ 36 #define _Asteroids_H__ 37 37 38 #include "invader/InvaderPrereqs.h" 39 38 #include "asteroids/AsteroidsPrereqs.h" 40 39 #include "gametypes/Deathmatch.h" 41 40 #include "tools/Timer.h" … … 44 43 { 45 44 46 class _ InvaderExport Invader: public Deathmatch45 class _AsteroidsExport Asteroids : public Deathmatch 47 46 { 48 47 public: 49 Invader(Context* context);48 Asteroids(Context* context); 50 49 51 50 virtual void start() override; 52 51 virtual void end() override; 52 virtual void tick(float dt) override; 53 53 virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command 54 54 55 void spawnEnemy(); 56 57 void setCenterpoint(InvaderCenterPoint* center); 55 void setCenterpoint(AsteroidsCenterPoint* center); 58 56 59 57 int getLives(){return this->lives;} 60 int getLevel(){return this->level;}61 58 int getPoints(){return this->point;} 62 int getMultiplier(){return this->multiplier;} 59 60 void costLife(); 61 void addPoints(int numPoints); 63 62 64 void costLife();65 void levelUp();66 void addPoints(int numPoints);67 // checks if multiplier should be reset.68 void comboControll();69 63 int lives; 70 int multiplier;71 64 bool bEndGame; 72 bool bShowLevel;65 73 66 private: 74 67 void toggleShowLevel(){bShowLevel = !bShowLevel;} 75 InvaderShip* getPlayer(); 76 WeakPtr<InvaderCenterPoint> center_; 77 WeakPtr<InvaderShip> player; 68 AsteroidsShip* getPlayer(); 69 WeakPtr<AsteroidsCenterPoint> center_; 70 WeakPtr<AsteroidsShip> player; 71 WeakPtr<Camera> camera; 78 72 79 73 Timer enemySpawnTimer; -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
r11506 r11516 3 3 #include "core/CoreIncludes.h" 4 4 #include "core/XMLPort.h" 5 #include "Invader.h" 6 #include "InvaderEnemy.h" 5 #include "Asteroids.h" 7 6 #include "graphics/Camera.h" 7 #include "asteroids/AsteroidStone" 8 8 #include "weapons/projectiles/Projectile.h" 9 9 10 10 11 namespace orxonox … … 16 17 { 17 18 RegisterObject(AsteroidsShip); 19 /*radius = 20; 20 x = getPosition().x; 21 y = getPosition().y; 22 dx = 3.0f; 23 dy = 3.0f; 24 angle= 0.0f;*/ 18 25 19 float x = getPosition().x; 20 float y = getPosition().y; 21 float velocityx = 0.0f; 22 float velocityy = 0.0f; 23 this->bBoost_ = false; 26 speed = 830; 27 isFireing = false; 28 damping = 10; 29 30 lastTimeFront = 0; 31 lastTimeLeft = 0; 32 lastTime = 0; 33 24 34 } 35 25 36 //Destructor 26 37 AsteroidsShip::~AsteroidsShip() … … 35 46 void AsteroidsShip::tick(float dt) 36 47 { 37 //Movement computation 38 Vector3 speed = Vector3 (100, 100, 0); 39 Vector3 position = this->getPosition(); 40 position += (speed * dt); 41 this->setPosition(position); 48 /*Movement computation 49 Vector3 pos = getPosition(); 50 51 dx *= damping; 52 dy *= damping; 53 54 float speed = sqrt(dx*dx+ dy*dy); 55 if(speed > maxspeed) 56 { 57 dx *= maxspeed/speed; 58 dy *= mayspeed/speed; 59 } 60 61 x += dx; 62 y += dy; 63 64 if(x>W) x=0; 65 if(x<0) x=W; 66 if(y>H) y=0; 67 if(y<0) y=H; 68 setPosition(x,y,0); 69 42 70 //roll? muss sich das Raumschiff drehen? 71 setOrientation(angle, x, y, 0); 43 72 44 73 //Schiessen wenn geschossen wurde … … 47 76 ControllableEntity::fire(0); 48 77 49 //Leben verloren 78 //Leben verloren */ 79 Vector3 pos = getPosition(); 80 81 //Movement calculation 82 lastTimeFront += dt * damping; 83 lastTimeLeft += dt * damping; 84 lastTime += dt; 85 86 velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); 87 velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); 88 89 //Execute movement 90 if (this->hasLocalController()) 91 { 92 float dist_y = velocity.y * dt; 93 //float dist_x = velocity.x * dt; 94 if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) 95 posforeward += dist_y; 96 else 97 { 98 velocity.y = 0; 99 // restart if game ended 100 /* 101 if (getGame()) 102 if (getGame()->bEndGame) 103 { 104 getGame()->start(); 105 return; 106 }*/ 107 } 108 109 pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; 110 } 111 112 113 // Camera 114 Camera* camera = this->getCamera(); 115 if (camera != nullptr) 116 { 117 // camera->setPosition(Vector3(-pos.z, -posforeward, 0)); 118 camera->setOrientation(Vector3::UNIT_Z, Degree(0)); 119 } 120 121 122 123 // bring back on track! 124 if(pos.y != 0) 125 { 126 pos.y = 0; 127 } 128 129 setPosition(pos); 130 setOrientation(Vector3::UNIT_Y, Degree(270)); 131 132 SUPER(AsteroidsShip, tick, dt); 50 133 } 51 134 52 void 135 Asteroids* AsteroidsShip::getGame() 136 { 137 if (game == nullptr) 138 { 139 for (Asteroids* asteroids : ObjectList<Asteroids>()) 140 game = asteroids; 141 } 142 return game; 143 } 53 144 145 void InvaderShip::death() 146 { 147 getGame()->costLife(); 148 SpaceShip::death(); 149 } 54 150 55 151 -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
r11506 r11516 33 33 */ 34 34 35 #ifndef _DodgeRace_H__ 36 #define _DodgeRace_H__ 37 38 #include "dodgerace/DodgeRacePrereqs.h" 39 40 #include "DodgeRaceCenterPoint.h" // Necessary for WeakPointer?? 41 //#include "DodgeRaceShip.h" DO NOT include in Header. Will cause forward declaration issues 42 43 //#include "DodgeRaceHUDinfo.h" 35 #ifndef _Asteroids_H__ 36 #define _Asteroids_H__ 44 37 45 38 46 #include "core/EventIncludes.h" 47 #include "core/command/Executor.h" 48 #include "core/config/ConfigValueIncludes.h" 49 50 #include "gamestates/GSLevel.h" 51 #include "chat/ChatManager.h" 52 #include <vector> 53 54 // ! HACK 55 #include "infos/PlayerInfo.h" 56 57 #include "core/command/ConsoleCommand.h" 58 39 #include "asteroids/AsteroidsPrereqs.h" 59 40 #include "gametypes/Deathmatch.h" 60 #include "tools/Timer.h" 41 #include "worldentities/pawns/SpaceShip.h" 42 #include "weapons/projectiles/Projectile.h" 43 #include <math.h> 61 44 62 45 namespace orxonox 63 46 { 64 47 65 class _ DodgeRaceExport DodgeRace : public Deathmatch48 class _AsteroidsExport Asteroids : public SpaceShip 66 49 { 67 50 public: 68 DodgeRace(Context* context); 69 70 virtual void start() override; 71 virtual void end() override; 51 Asteroids(Context* context); 72 52 73 53 virtual void tick(float dt) override; 74 54 75 virtual void playerPreSpawn(PlayerInfo* player) override; 55 // overwrite for 2d movement 56 virtual void moveFrontBack(const Vector2& value) override; 57 virtual void moveRightLeft(const Vector2& value) override; 76 58 77 void levelUp(); 59 // Starts or stops fireing 60 virtual void boost(bool bBoost) override; 78 61 79 int getLives(){return this->lives;}80 int getLevel(){return this->level;}81 int getPoints(){return this->point;}82 int getMultiplier(){return this->multiplier;}83 62 84 63 void setCenterpoint(DodgeRaceCenterPoint* center) … … 86 65 virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command 87 66 88 // checks if multiplier should be reset.89 void comboControll();90 void costLife();91 92 67 bool bEndGame; 93 68 bool bShowLevel; 94 69 int lives; 95 int multiplier; 96 float counter; 97 int pattern; 98 float currentPosition; 99 float lastPosition; 70 float angle, radius; 71 float speed, damping, posforeward; 72 bool isFireing; 73 74 //Nachschauen wie gross das Spielfeld ist! 75 float H = 1000; 76 float W = 1000; 77 78 protected: 79 virtual void death() override; 100 80 101 81 private: 102 Timer endGameTimer; 103 104 DodgeRaceShip* getPlayer(); 105 WeakPtr<DodgeRaceShip> player; 106 std::vector<DodgeRaceCube*> cubeList; 107 void toggleShowLevel(){bShowLevel = !bShowLevel;} 108 void addPoints(int numPoints); 109 110 WeakPtr<DodgeRaceCenterPoint> center_; 111 int level; 112 int point; 113 bool b_combo; 114 115 Timer enemySpawnTimer; 116 Timer comboTimer; 117 Timer showLevelTimer; 118 119 120 /* 121 122 //void spawnEnemy(); 123 124 125 126 127 128 129 130 131 132 133 134 135 private: 136 137 138 139 140 //Context* context; 141 */ 82 Asteroids* getGame(); 83 WeakPtr<Asteroids> game; 84 WeakPtr<WorldEntity> lastEntity; 85 Camera* camera; 86 float lastTimeFront, lastTimeLeft, lastTime; 87 struct Velocity 88 { 89 float x; 90 float y; 91 } velocity, desiredVelocity; 92 142 93 }; 143 94 } 144 95 145 #endif /* _ DodgeRace_H__ */96 #endif /* _Asteroids_H__ */ -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
r11506 r11516 32 32 */ 33 33 34 #include "InvaderEnemy.h" 35 34 #include "AsteroidsStone.h" 36 35 #include "core/CoreIncludes.h" 37 #include "Invader.h" 38 #include "InvaderShip.h" 36 #include "Asteroids.h" 37 #include "AsteroidsShip.h" 38 #include <cmath> 39 #include "util/Math.h" 39 40 40 41 namespace orxonox 41 42 { 42 RegisterClass( InvaderEnemy);43 RegisterClass(AsteroidsStone); 43 44 44 InvaderEnemy::InvaderEnemy(Context* context) : Pawn(context)45 AsteroidsStone::AsteroidsStone(Context* context) : MovableEntity(context) 45 46 { 46 RegisterObject(InvaderEnemy); 47 enableCollisionCallback(); 48 lifetime = 0; 47 RegisterObject(AsteroidsStone); 48 49 maxspeed = 50.0f; 50 //Random Spawn? pos= random? 51 this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0); 52 if(r){ 53 this.r = r*0.5; 54 }else{ 55 this.r = rnd(15, 50); 56 } 57 58 //random Geschwindigkeit und Richtung 59 velocity.x = rnd(0, maxspeed); 60 velocity.y = rnd(0, maxspeed); 61 } 62 //Bis hier geschrieben 63 void AsteroidsStone::tick(float dt) 64 { 65 Vector3 pos = this->getPosition(); 66 pos.x += velocity.x*dt; 67 pos.y += velocity.y*dt; 68 setPosition(pos); 69 SUPER(AsteroidsStone, tick, dt); 49 70 } 50 71 51 void InvaderEnemy::tick(float dt) 52 { 53 lifetime += dt; 54 // die after 5 seconds. 55 if (lifetime > 5000) 56 removeHealth(2000); 57 58 if (player != nullptr) 59 { 60 float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * (player->getPosition().z - getPosition().z); 61 setVelocity(Vector3(1000.f - level * 100 , 0, newZ)); 62 } 63 SUPER(InvaderEnemy, tick, dt); 64 } 65 66 inline bool InvaderEnemy::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 72 inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 67 73 { 68 74 if(orxonox_cast<InvaderShip*>(otherObject)) … … 71 77 } 72 78 73 Invader* InvaderEnemy::getGame()74 {75 if (game == nullptr)76 {77 for (Invader* invader : ObjectList<Invader>())78 game = invader;79 }80 return game;81 }82 79 83 void InvaderEnemy::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)84 {85 Pawn::damage(damage, healthdamage, shielddamage, originator, cs);86 if (getGame() && orxonox_cast<InvaderShip*>(originator) != nullptr && getHealth() <= 0)87 getGame()->addPoints(42);88 }89 80 } -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
r11506 r11516 32 32 */ 33 33 34 #ifndef _ InvaderEnemy_H__35 #define _ InvaderEnemy_H__34 #ifndef _AsteroidsStone_H__ 35 #define _AsteroidsStone_H__ 36 36 37 #include " invader/InvaderPrereqs.h"37 #include "asteroids/AsteroidsPrereqs.h" 38 38 39 #include "worldentities/ pawns/Pawn.h"39 #include "worldentities/MovableEntity.h" 40 40 41 41 namespace orxonox 42 42 { 43 class _ InvaderExport InvaderEnemy : public Pawn43 class _AsteroidsExport AsteroidsStone : public MovableEntity 44 44 { 45 45 public: 46 InvaderEnemy(Context* context); 46 AsteroidsStone(Context* context); 47 virtual void tick(float dt) override; 47 48 48 virtual void tick(float dt) override; 49 virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override; 50 virtual void damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) override; 51 virtual void setInvaderPlayer(InvaderShip* player){this->player = player;} 52 49 float r; 53 50 int level; 54 51 protected: 55 Invader* getGame(); 56 WeakPtr<Invader> game; 57 WeakPtr<InvaderShip> player; 58 Camera* camera; 59 bool isFireing; 60 float speed, damping; 61 float lastTimeFront, lastTimeLeft; 62 float lifetime; 63 struct Velocity 64 { 65 float x; 66 float y; 67 } velocity, desiredVelocity; 52 float fieldWidth_; 53 float fieldHeight_; 54 Vector2 velocity; 55 float maxspeed; 56 57 68 58 69 59 }; -
code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt
r11506 r11516 1 SET_SOURCE_FILES( Invader_SRC_FILES2 BUILD_UNIT InvaderBuildUnit.cc3 Invader.cc4 InvaderCenterPoint.cc1 SET_SOURCE_FILES(ASTEROIDS_SRC_FILES 2 BUILD_UNIT AsteroidsBuildUnit.cc 3 Asteroids.cc 4 AsteroidsCenterPoint.cc 5 5 InvaderShip.cc 6 InvaderEnemy.cc 7 InvaderEnemyShooter.cc 8 InvaderWeapon.cc 9 InvaderWeaponEnemy.cc 10 InvaderHUDinfo.cc 6 AsteroidsStone.cc 7 AsteroidsWeapon.cc 11 8 END_BUILD_UNIT 12 9 ) 13 10 14 ORXONOX_ADD_LIBRARY( invader11 ORXONOX_ADD_LIBRARY(asteroids 15 12 PLUGIN 16 13 FIND_HEADER_FILES … … 19 16 overlays 20 17 weapons 21 SOURCE_FILES ${ Invader_SRC_FILES}18 SOURCE_FILES ${ASTEROIDS_SRC_FILES} 22 19 )
Note: See TracChangeset
for help on using the changeset viewer.