[Orxonox-commit 6907] r11528 - in code/branches/Asteroid_HS17: data/levels src/modules/asteroids

vyang at orxonox.net vyang at orxonox.net
Sat Nov 4 17:05:00 CET 2017


Author: vyang
Date: 2017-11-04 17:04:59 +0100 (Sat, 04 Nov 2017)
New Revision: 11528

Modified:
   code/branches/Asteroid_HS17/data/levels/Asteroids.oxw
   code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
   code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.cc
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
   code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
   code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt
Log:
Spawn Funktion fuer die Asteroiden veraendert

Modified: code/branches/Asteroid_HS17/data/levels/Asteroids.oxw
===================================================================
--- code/branches/Asteroid_HS17/data/levels/Asteroids.oxw	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/data/levels/Asteroids.oxw	2017-11-04 16:04:59 UTC (rev 11528)
@@ -1,10 +1,11 @@
- <LevelInfo
+<LevelInfo
  name = "Asteroids"
- description = "Try to prevent asteroids from colliding into your spaceshuttle. Be prepared to dodge all asteroids or destroy them;"
+ description = "Try to prevent asteroids from colliding into your spaceshuttle. Be prepared to dodge all asteroids or destroy them."
  tags = "asteroids, minigame"
  screenshot = "emptylevel.png"
 />
 
+
 <?lua
   include("stats.oxo")
   include("templates/lodInformation.oxt")
@@ -13,63 +14,62 @@
 <?lua
   include("templates/spaceshipAssff2.oxt")
   include("templates/spaceshipPirate.oxt")
-  include("templates/spaceshipDodgeRace.oxt")
+  include("templates/spaceshipInvader.oxt")
   include("templates/enemyInvader.oxt")
-  include("templates/DodgeRacePattern.oxt")
-  include("overlays/DodgeRaceHUD.oxo")
+  include("overlays/InvaderHUD.oxo")
 ?>
 
-
-
 <Level
-    plugin = asteroids
-    gametype = Asteroids
-    >
-
-
+  plugins = invader
+  gametype = Invader
+>
   <templates>
     <Template link=lodtemplate_default />
   </templates>
   <?lua include("includes/notifications.oxi") ?>
 
+    <!-- ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox" -->
   <Scene
-    ambientlight = "1.0, 1.0, 1.0"
-    skybox       = "Orxonox/skyBoxClouds"
-    negativeWorldRange = "-100000, -100000, -100000"
-    positiveWorldRange = " 100000,  100000,  100000"
+    ambientlight = "0.8, 0.7, 0.4"
+    skybox     = "Orxonox/skyBoxBasic"
   >
 
-  <WorldAmbientSound
-    source="Earth.ogg"
-    looping="true"
-    playOnLoad="true"
-  />
-
     <!-- <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> -->
-    <Light type=directional position="-100, 10000, -700" lookat="0.2, -1, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
-    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=AsteroidsShip pawndesign=spaceshipdodgerace />
+    <Light type=directional position="1100, 11000, -7000" lookat="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=InvaderShip pawndesign=spaceshipinvader />
 
     <DistanceTrigger name="start" position="-200,0,0" target="Pawn" distance=10 stayActive="true" delay=0 />
 
 
-    <DodgeRaceCenterPoint name=invadercenter />
-  
-  <StaticEntity position="0,-50,0" direction="0,0,0"   scale="1" collisionType=static mass=1 friction=0.01 >
+    <InvaderCenterPoint name=invadercenter />
+    
+    <?lua
+      for i = 1, 300, 1 do
+        j = math.random()
+    ?>
+
+    <MovableEntity
+      position = "<?lua print(math.random()* 40000 + 1000) ?>,-1000,<?lua print(math.random() * 4000 - 2000) ?>"
+      collisionType = dynamic
+      linearDamping = 0.8
+      angularDamping = 0
+      scale = "<?lua print(j * 150)?>"
+      collisiondamage = 0
+      enablecollisiondamage = true
+    >
       <attached>
-        <Model position="0,0,0" mesh="plane.mesh" scale3D="100000,0,100000" />
+        <Model mass="<?lua print(j * 1000) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" />
       </attached>
-
       <collisionShapes>
-        <BoxCollisionShape position="0,0,0" halfExtents="1,1,1" />
+        <SphereCollisionShape radius="<?lua print(j * 350) ?>" />
       </collisionShapes>
+    </MovableEntity>
 
-  </StaticEntity>
+    <?lua
+      end
+    ?>
     
-    
-    
-    
-    
-    
   </Scene>
 </Level>
 

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc	2017-11-04 16:04:59 UTC (rev 11528)
@@ -63,9 +63,78 @@
         lives = 3;
         point = 0;
 
+        // Pre-set the timer, but don't start it yet.
+        this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
     }
 
+    //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird
+    Asteroids::spawnStone(){
+        if(getPlayer() == nullptr){
+            return;
+        }
 
+        AsteroidsStone* newStone;
+        newStone = new AsteroidsStone(this->center_->getContext());
+        newStone->addTemplate("asteroidsstone");
+        newStone->setAsteroidsPlayer(player);
+    }
+
+        void Invader::spawnEnemy()
+    {
+        if (getPlayer() == nullptr)
+            return;
+
+        for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
+        {
+            InvaderEnemy* newPawn;
+            if (rand() % 42/(1 + level*level) == 0)
+            {
+                newPawn = new InvaderEnemyShooter(this->center_->getContext());
+                newPawn->addTemplate("enemyinvadershooter");
+            }
+            else
+            {
+                newPawn = new InvaderEnemy(this->center_->getContext());
+                newPawn->addTemplate("enemyinvader");
+            }
+            newPawn->setInvaderPlayer(player);
+            newPawn->level = level;
+            // spawn enemy at random points in front of player.
+            newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
+        }
+    }
+
+    /**
+    @brief
+        Destructor. Cleans up, if initialized.
+    */
+    Asteroids::~Asteroids()
+    {
+        if (this->isInitialized())
+            this->cleanup();
+    }
+
+    /**
+    @brief
+        Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids.
+    */
+    void Asteroids::cleanup()
+    {
+        if (this->stones_ != nullptr) // Destroy the ball, if present.
+        {
+            this->stones_->destroy();
+            this->stones_ = nullptr;
+        }
+
+        // Destroy AsteroidsShip
+
+        if (this->player != nullptr)
+        {
+            this->player->destroy();
+            this->player = nullptr;
+        }
+    }
+
     AsteroidsShip* Asteroids::getPlayer()
     {
         if (player == nullptr)
@@ -86,20 +155,24 @@
     {
         lives = 0;
     };
-
     void Asteroids::start()
     {
-        // Set variable to temporarily force the player to spawn.
-        this->bForceSpawn_ = true;
-
-        if (this->center_ == nullptr)  // abandon mission!
+        if (this->center_ == nullptr) // There needs to be a AsteroidsCenterpoint, i.e. the area the game takes place. If no centerpoint was specified, an error is thrown and the level is exited.
         {
-            orxout(internal_error) << "Invader: No Centerpoint specified." << endl;
+            orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl;
             GSLevel::startMainMenu();
             return;
         }
+
+        // Set variable to temporarily force the player to spawn.
+        bool temp = this->bForceSpawn_;
+        this->bForceSpawn_ = true;
+
         // Call start for the parent class.
         Deathmatch::start();
+
+        // Reset the variable.
+        this->bForceSpawn_ = temp;
     }
 
     void Asteroids::addPoints(int numPoints)

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h	2017-11-04 16:04:59 UTC (rev 11528)
@@ -60,23 +60,27 @@
             void costLife();
             void addPoints(int numPoints);
 
+            void spawnStone();
+
             int lives;
             bool bEndGame;
             
         private:
             void toggleShowLevel(){bShowLevel = !bShowLevel;}
+            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
             AsteroidsShip* getPlayer();
             WeakPtr<AsteroidsCenterPoint> center_;
             WeakPtr<AsteroidsShip> player;
             WeakPtr<Camera> camera;
+            WeakPtr<AsteroidsStones> stones_;
 
             Timer enemySpawnTimer;
-            Timer comboTimer;
-            Timer showLevelTimer;
             //Context* context;
             int level;
             int point;
             bool b_combo;
+
+            Timer starttimer_; //!< A timer to delay the start of the game.
     };
 }
 

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.cc	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.cc	2017-11-04 16:04:59 UTC (rev 11528)
@@ -45,6 +45,11 @@
     {
         RegisterObject(AsteroidsCenterPoint);
 
+
+        //Werte ausprobieren und testen!
+        this->width_ = 500;
+        this->height_= 300;
+
         this->checkGametype();
     }
 

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h	2017-11-04 16:04:59 UTC (rev 11528)
@@ -46,8 +46,24 @@
         public:
             AsteroidsCenterPoint(Context* context); //checks whether the gametype is actually Invader.
 
+                        /**
+            @brief Set the dimensions of the playing field.
+            @param dimension A vector with the width of the playing field as first component and the height as second.
+            */
+            void setFieldDimension(const Vector2& dimension)
+                { this->width_ = dimension.x; this->height_ = dimension.y; }
+            /**
+            @brief Get the dimensions of the playing field.
+            @return Returns a vector with the width of the playing field as first component and the height as second.
+            */
+            Vector2 getFieldDimension() const
+                { return Vector2(this->width_, this->height_); }
+
         private:
             void checkGametype();
+            //Spielfeld liegt in x-z Ebene, x ist LeftRight(Horizontale), z ist UpDown (Vertikale)
+            float width_;
+            float height_;
 
     };
 }

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc	2017-11-04 16:04:59 UTC (rev 11528)
@@ -4,8 +4,9 @@
 #include "core/XMLPort.h"
 #include "Asteroids.h"
 #include "graphics/Camera.h"
-#include "asteroids/AsteroidStone"
+#include "asteroids/AsteroidStone.h"
 #include "weapons/projectiles/Projectile.h"
+#include "asteroids/AsteroidsCenterpoint.h"
 
 
 namespace orxonox
@@ -107,10 +108,12 @@
             }
 
             pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
+
         }
 
 
-        // Camera
+
+        //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
         Camera* camera = this->getCamera();
         if (camera != nullptr)
         {
@@ -131,7 +134,22 @@
 
         SUPER(AsteroidsShip, tick, dt);
     }
-    
+
+    void AsteroidsShip::moveFrontBack(const Vector2& value)
+    {
+
+
+    } 
+
+    void AsteroidsShip::moveFrontBack(const Vector2& value)
+    {
+
+    }
+    void AsteroidsShip::moveFrontBack(const Vector2& value)
+    {
+
+    }
+
     Asteroids* AsteroidsShip::getGame()
     {
         if (game == nullptr)
@@ -142,7 +160,7 @@
         return game;
     }
 
-    void InvaderShip::death()
+    void AsteroidsShip::death()
     {
         getGame()->costLife();
         SpaceShip::death();

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h	2017-11-04 16:04:59 UTC (rev 11528)
@@ -55,13 +55,16 @@
             // overwrite for 2d movement
             virtual void moveFrontBack(const Vector2& value) override;
             virtual void moveRightLeft(const Vector2& value) override;
+            virtual void moveUpDown(const Vector2& value) override;
 
             // Starts or stops fireing
             virtual void boost(bool bBoost) override;
 
 
-            void setCenterpoint(DodgeRaceCenterPoint* center)
+            void setCenterpoint(AsteroidsCenterPoint* center)
                        { this->center_ = center; }
+
+
             virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
 
             bool bEndGame;

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc	2017-11-04 16:04:59 UTC (rev 11528)
@@ -41,11 +41,13 @@
 namespace orxonox
 {
     RegisterClass(AsteroidsStone);
-
-    AsteroidsStone::AsteroidsStone(Context* context) : MovableEntity(context)
+    //pawn kann sterben -> nach dem Tot sollen aber 2 Asteroiden spawnen
+    AsteroidsStone::AsteroidsStone(Context* context) : Pawn(context)
     {
         RegisterObject(AsteroidsStone);
 
+
+
         maxspeed = 50.0f;
         //Random Spawn? pos= random?
         this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0);

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h	2017-11-04 16:04:59 UTC (rev 11528)
@@ -27,8 +27,8 @@
  */
 
 /**
-    @file InvaderEnemy.h
-    @brief Declaration of the InvaderEnemy class.
+    @file AsteroidsStone.h
+    @brief Declaration of the AsteroidsStone class.
 */
 
 #ifndef _AsteroidsStone_H__
@@ -36,27 +36,29 @@
 
 #include "asteroids/AsteroidsPrereqs.h"
 
-#include "worldentities/MovableEntity.h"
+#include "worldentities/Pawn.h"
 
 namespace orxonox
 {
-    class _AsteroidsExport AsteroidsStone : public MovableEntity
+    class _AsteroidsExport AsteroidsStone : public Pawn
     {
         public:
             AsteroidsStone(Context* context);
             virtual void tick(float dt) override;
 
+            //Radius of the asteroid
             float r;
             int level;
+            virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;}
+
         protected:
-            float fieldWidth_;
-            float fieldHeight_;
+
+            //herausfinden->ueber Kamera Einstellung wie bei Pong?
+            float fieldWidth_=500;
+            float fieldHeight_=700;
             Vector2 velocity;
             float maxspeed;
-
-
-
     };
 }
 
-#endif /* _InvaderEnemy_H__ */
+#endif /* _AsteroidsStone_H__ */

Modified: code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt	2017-10-30 15:36:26 UTC (rev 11527)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt	2017-11-04 16:04:59 UTC (rev 11528)
@@ -2,7 +2,7 @@
 BUILD_UNIT AsteroidsBuildUnit.cc
   Asteroids.cc
   AsteroidsCenterPoint.cc
-  InvaderShip.cc
+  AsteroidsShip.cc
   AsteroidsStone.cc
   AsteroidsWeapon.cc
 END_BUILD_UNIT



More information about the Orxonox-commit mailing list