Changeset 11555 for code/branches/Asteroid_HS17/src/modules
- Timestamp:
- Nov 13, 2017, 4:05:34 PM (7 years ago)
- Location:
- code/branches/Asteroid_HS17/src/modules/asteroids
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
r11541 r11555 60 60 this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 61 61 this->center_ = nullptr; 62 this->lives = 3; 62 63 bEndGame = false; 63 64 lives = 3; … … 65 66 66 67 // Pre-set the timer, but don't start it yet. 67 this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));68 //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this))); 68 69 } 69 70 … … 79 80 } 80 81 81 /** 82 @brief 83 Destructor. Cleans up, if initialized. 84 */ 85 Asteroids::~Asteroids() 82 void Asteroids::spawnStone(int newsize) 86 83 { 87 if (this->isInitialized()) 88 this->cleanup(); 89 } 84 //no player -> should end game? 85 if(getPlayer() == nullptr) return; 86 //invalid size 87 if(newsize > 3 || newsize < 1) return; 88 AsteroidsStone* newStone; 89 newStone = new AsteroidsStone(this->center_->getContext()); 90 newStone.size = newsize; 91 if(newsize == 1) newStone->addTemplate("asteroidsstone1"); 92 else if(newsize == 2) newStone->addTemplate("asteroidsstone2"); 93 else newStone->addTemplate("asteroidsstone3"); 94 newStone->setAsteroidsPlayer(player); 90 95 91 /**92 @brief93 Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids.94 */95 void Asteroids::cleanup()96 {97 if (this->stones_ != nullptr) // Destroy the ball, if present.98 {99 this->stones_->destroy();100 this->stones_ = nullptr;101 }102 103 // Destroy AsteroidsShip104 105 if (this->player != nullptr)106 {107 this->player->destroy();108 this->player = nullptr;109 }110 96 } 111 97 -
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
r11528 r11555 67 67 68 68 private: 69 void toggleShowLevel(){bShowLevel = !bShowLevel;}70 void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.71 69 AsteroidsShip* getPlayer(); 72 70 WeakPtr<AsteroidsCenterPoint> center_; … … 75 73 WeakPtr<AsteroidsStones> stones_; 76 74 77 Timer enemySpawnTimer; 75 78 76 //Context* context; 79 int l evel;77 int lives; 80 78 int point; 81 bool b_combo;82 79 83 80 Timer starttimer_; //!< A timer to delay the start of the game. 81 Timer enemySpawnTimer; 84 82 }; 85 83 } -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
r11541 r11555 19 19 RegisterObject(AsteroidsShip); 20 20 21 angle= 0.0f; 22 23 21 direction= 0.0f; 24 22 25 23 isFireing = false; … … 30 28 lastTime = 0; 31 29 32 height = this->getGame()->center_->getFieldHeight(); 33 width = this->getGame()->center_->getFieldWidth(); 34 35 force.x =0; 36 force.y =0; 37 38 velocity.x = 0; 39 velocity.y = 0; 40 30 height = 600; 31 width = 1000; 41 32 } 42 43 //Destructor44 AsteroidsShip::~AsteroidsShip()45 {46 if (this->isInitialized())47 this->cleanup();48 }49 50 33 51 34 … … 53 36 void AsteroidsShip::tick(float dt) 54 37 { 38 orxout() << "ich ticke!"<< endl; 39 SUPER(AsteroidsShip, tick, dt); 40 55 41 //Movement computation beachte Beschleunigung? 56 42 Vector3 pos = getPosition(); 43 Vector3 vel = getVelocity(); 57 44 58 float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y); 45 float speed = sqrt(vel.x*vel.x+ vel.z*velo.z); 46 47 48 //Daempfung falls das spaceship zu schnell wird 59 49 if(speed > maxspeed) 60 50 { 61 vel ocity.x *= maxspeed/speed;62 vel ocity.y*= mayspeed/speed;51 vel.x *= maxspeed/speed; 52 vel.z *= mayspeed/speed; 63 53 } 64 54 65 pos.x += velocity.x*dt; 66 pos.y += velocity.y*dt; 55 if(moveUpPressed_) 56 { 57 //Gas geben 58 vel.x += 1; 59 vel.z += 1; 60 61 }else if(moveDownPressed_){ 62 //Bremsen 63 vel.x += 1; 64 vel.z += 1; 65 }else if(moveLeftPressed_){ 66 //rotate left 67 }else if (moveRightPressed_){ 68 //rotateright 69 } 70 71 setVelocity(vel); 72 73 pos.x += vel.x*dt; 74 pos.z += vel.z*dt; 67 75 68 76 69 //haelt ship innerhalb des Kamerafensters 70 if(x>width) x=0; 71 if(x<0) x=width; 72 if(y>height) y=0; 73 if(y<0) y=height); 77 78 //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0) 79 if(pos.x > width/2) pos.x = -width/2; 80 if(pos.x < -width/2) pos.x = width/2; 81 if(pos.z > height/2) pos.z = -height/2; 82 if(pos.z < -height/2) pos.z = height/2; 74 83 75 84 76 85 //Schiessen wenn geschossen wurde 77 86 // shoot! 78 /* 87 79 88 if (isFireing) 80 89 ControllableEntity::fire(0); 81 */ 82 83 //Execute movement 84 if (this->hasLocalController()) 85 { 86 force.x += 1; 87 force.y += 1; 88 89 } 90 91 92 93 //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren 94 Camera* camera = this->getCamera(); 95 if (camera != nullptr) 96 { 97 camera->setPosition(Vector3(0,cameradistance, 0)); 98 camera->setOrientation(Vector3::UNIT_Z, Degree(90)); 99 } 100 101 90 102 91 103 92 // bring back on track! … … 107 96 } 108 97 109 velocity.x *= damping; 110 velocity.y *= damping; 98 //Reibung? 99 vel.x *= damping; 100 vel.y *= damping; 101 111 102 112 103 setPosition(pos); 113 setOrientation(Vector3::UNIT_Y, Degree( 270));104 setOrientation(Vector3::UNIT_Y, Degree(direction)); 114 105 115 SUPER(AsteroidsShip, tick, dt); 106 // Reset key variables 107 moveUpPressed_ = false; 108 moveDownPressed_ = false; 109 moveLeftPressed_ = false; 110 moveDownPressed_ = false; 111 116 112 117 113 } … … 119 115 void AsteroidsShip::moveFrontBack(const Vector2& value) 120 116 { 121 velocity.x += 1; 122 } 117 if (value.x > 0) 118 { 119 moveUpPressed_ = true; 120 moveDownPressed_ = false 121 if(moveUpPressed_) 122 { 123 orxout() << "up" << endl; 124 } 125 } 126 else 127 { 128 moveUpPressed_ = false; 129 moveDownPressed_ = true; 130 if(moveDownPressed_) 131 { 132 orxout() << "down" << endl; 133 } 134 } 135 } 123 136 124 void AsteroidsShip::move UpDown(const Vector2& value)137 void AsteroidsShip::moveRightLeft(const Vector2& value) 125 138 { 126 velocity.y +=1; 139 if (value.x > 0) 140 { 141 moveLeftPressed_ = false; 142 moveRightPressed_ = true; 143 } 144 if(moveRightPressed_) 145 { 146 orxout() << "right" << endl; 147 } 127 148 149 else 150 { 151 moveLeftPressed_ = true; 152 moveRightPressed_ = false; 153 if(moveLeftPressed_) 154 { 155 orxout() << "left" << endl; 156 } 157 } 128 158 } 129 void AsteroidsShip::moveFrontLeftRight(const Vector2& value) 130 { 131 132 } 159 133 160 134 161 Asteroids* AsteroidsShip::getGame() -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
r11541 r11555 53 53 virtual void tick(float dt) override; 54 54 55 // 55 //overwrite for 2d movement 56 56 virtual void moveFrontBack(const Vector2& value) override; 57 57 virtual void moveRightLeft(const Vector2& value) override; 58 virtual void moveUpDown(const Vector2& value) override;59 58 60 59 // Starts or stops fireing 61 virtual void boost(bool bBoost) override;60 //virtual void boost(bool bBoost) override; 62 61 63 62 … … 69 68 70 69 bool bEndGame; 71 bool bShowLevel;72 70 int lives; 73 float angle, radius;74 float damping , posforeward;71 float direction; 72 float damping; 75 73 bool isFireing; 76 float dx, dy;77 74 const float maxspeed = 500; 78 const float cameradistance = 100; 75 79 76 80 77 //Nachschauen wie gross das Spielfeld ist! … … 91 88 WeakPtr<Asteroids> game; 92 89 WeakPtr<WorldEntity> lastEntity; 93 Camera* camera;94 90 float lastTimeFront, lastTimeLeft, lastTime; 95 struct Vector 96 { 97 float x; 98 float y; 99 }force, velocity 91 92 //Controller 93 bool moveUpPressed_, moveDownPressed_, moveRightPressed_, moveLeftPressed_; 100 94 101 95 }; -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
r11541 r11555 28 28 29 29 /** 30 @file InvaderEnemy.h31 @brief Declaration of the InvaderEnemy class.30 @file AsteroidsEnemy.h 31 @brief Declaration of the AsteroidsEnemy class. 32 32 */ 33 33 … … 36 36 #include "Asteroids.h" 37 37 #include "AsteroidsShip.h" 38 #include <cstdlib> 38 39 #include <cmath> 39 40 #include "util/Math.h" 40 41 42 const float delta = 3; 41 43 42 44 namespace orxonox … … 48 50 RegisterObject(AsteroidsStone); 49 51 52 direction = 0; 53 //Spielfeld x als Horizontale und z als Vertikale 54 fieldWidth_ = this->getGame()->center_->getFieldWidth; 55 fieldHeigth_ = this->getGame()->center_->getFieldHeight; 56 57 58 //Random size 1, 2, 3 ->muss noch realisiert werden. Templates erstellen 59 this.size = 1; 50 60 maxspeed = 50.0f; 51 61 //Random Spawn? pos= random? -> spawn durch timer in der Asteroids Klasse 52 this->setPosition(rnd( 0, fieldWidth_), rnd(0, fieldHeigth_), 0);62 this->setPosition(rnd(fieldWidth_), 0, rnd(fieldHeigth)); 53 63 54 //random Geschwindigkeit und Richtung 55 velocity.x = rnd(0, maxspeed); 56 velocity.y = rnd(0, maxspeed); 57 this->context = context; 64 //random Geschwindigkeit und Richtung 65 velocity.x = rnd(maxspeed); 66 velocity.y = rnd(maxspeed); 67 } 68 69 inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 70 { 71 if(orxonox_cast<AsteroidsShip*>(otherObject)) 72 removeHealth(2000); 73 return false; 58 74 } 59 75 … … 64 80 }else if(this->size == 2){ 65 81 Pawn::death(); 66 67 82 //Wie mache ich das ? Eigentlich in der game Klasse? sonst zeigt der Pointer auf einen falschen Bereich 68 69 83 for(int i = 0; i<2; i++) 70 84 { 71 85 AsteroidsStone* newStone; 72 newStone = new AsteroidsStone(this-> context);86 newStone = new AsteroidsStone(this->getGame()->center_->getContext()); 73 87 newStone->addTemplate("asteroidsstone"); 74 newStone->setAsteroidsPlayer( player);88 newStone->setAsteroidsPlayer(this->getGame()->player); 75 89 } 76 90 77 91 } 92 } 93 94 95 Asteroids* AsteroidsStone::getGame() 96 { 97 if (game == nullptr) 98 { 99 for (Asteroids* Asteroids : ObjectList<Asteroids>()) 100 game = asteroids; 101 } 102 return game; 78 103 } 79 104 … … 82 107 void AsteroidsStone::tick(float dt) 83 108 { 84 Vector3 pos = this->getPosition(); 85 pos.x += velocity.x*dt; 86 pos.z += velocity.y*dt; 109 Vector3 pos = getPosition(); 87 110 111 112 113 114 //bounce on the borders 115 if(pos.x-delta <= 0 || pos.x+delta >= fieldWidth_) 116 direction = -direction; 117 118 119 120 //zurück bringen 88 121 if(pos.y != 0){ 89 122 pos.y=0; 90 123 } 124 125 //spin 126 127 setOrientation() 91 128 setPosition(pos); 129 92 130 SUPER(AsteroidsStone, tick, dt); 93 131 } … … 95 133 inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 96 134 { 97 if(orxonox_cast< InvaderShip*>(otherObject))135 if(orxonox_cast<AsteroidsShip*>(otherObject)) 98 136 removeHealth(2000); 99 137 return false; -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
r11541 r11555 50 50 //Es gibt 3 Groessen von Meteroiden gross, mittel, klein, gross ->2 mittleren, mittel -> 2 kleinen, kleine-> verschwinden 51 51 int size; 52 int level; 52 53 53 virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;} 54 virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override; 55 54 56 55 57 56 58 protected: 59 60 Asteroids* getGame(); 61 WeakPtr<Asteroids> game; 57 62 58 63 virtual void death() override; … … 60 65 61 66 //herausfinden->ueber Kamera Einstellung wie bei Pong? 62 float fieldWidth_ =500;63 float fieldHeight_ =700;67 float fieldWidth_; 68 float fieldHeight_; 64 69 Vector2 velocity; 65 70 float maxspeed; 71 float direction; 66 72 67 private:68 Context* context;69 73 }; 70 74 }
Note: See TracChangeset
for help on using the changeset viewer.