[Orxonox-commit 5378] r10041 - in code/branches/pickupsFS14/src: modules/jump orxonox/worldentities

fvultier at orxonox.net fvultier at orxonox.net
Tue Apr 22 17:32:38 CEST 2014


Author: fvultier
Date: 2014-04-22 17:32:37 +0200 (Tue, 22 Apr 2014)
New Revision: 10041

Modified:
   code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt
   code/branches/pickupsFS14/src/modules/jump/Jump.cc
   code/branches/pickupsFS14/src/modules/jump/Jump.h
   code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc
   code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h
   code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h
   code/branches/pickupsFS14/src/orxonox/worldentities/WorldEntity.h
Log:
Level wird zufaellig generiert, HUD funktionier(Punkte werden angezeigt), Diverse bugs behoben, Figur springt von allen Platformen korrekt ab.

Modified: code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt	2014-04-22 15:32:37 UTC (rev 10041)
@@ -2,6 +2,7 @@
 BUILD_UNIT JumpBuildUnit.cc
   Jump.cc
   JumpPlatform.cc
+  JumpPlatformStatic.cc
   JumpPlatformHMove.cc
   JumpPlatformVMove.cc
   JumpFigure.cc

Modified: code/branches/pickupsFS14/src/modules/jump/Jump.cc
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/Jump.cc	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/Jump.cc	2014-04-22 15:32:37 UTC (rev 10041)
@@ -43,6 +43,9 @@
 
 #include "JumpCenterpoint.h"
 #include "JumpPlatform.h"
+#include "JumpPlatformStatic.h"
+#include "JumpPlatformHMove.h"
+#include "JumpPlatformVMove.h"
 #include "JumpFigure.h"
 
 #include "infos/PlayerInfo.h"
@@ -64,12 +67,13 @@
         RegisterObject(Jump);
 
         this->center_ = 0;
-        this->ball_ = 0;
         this->figure_ = 0;
         this->camera = 0;
 
-        //this->setHUDTemplate("JumpHUD");
+        platformList.clear();
 
+        this->setHUDTemplate("JumpHUD");
+
         // Pre-set the timer, but don't start it yet.
         this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this)));
         this->starttimer_.stopTimer();
@@ -98,28 +102,58 @@
     	if (figure_ != NULL)
     	{
     		Vector3 figurePosition = figure_->getPosition();
+    		Vector3 figureVelocity = figure_->getVelocity();
 
     		if (figurePosition.z > totalScreenShift)
     		{
+    			screenShiftSinceLastUpdate += figurePosition.z - totalScreenShift;
     			totalScreenShift = figurePosition.z;
+
+                // Falls noetig neue Platformen im neuen Bereich einfuegen
+                if (screenShiftSinceLastUpdate > sectionLength)
+                {
+                	screenShiftSinceLastUpdate -= sectionLength;
+                    addSection();
+                }
     		}
 
+    		// Spiel verloren wegen Ansturz?
+    		if (figurePosition.z < totalScreenShift - center_->getFieldDimension().y && figureVelocity.z < 0)
+    		{
+    			end();
+    		}
+
+
     		if (this->camera != NULL)
 			{
-				Vector3 cameraPosition = Vector3(0,totalScreenShift,0);
+				Vector3 cameraPosition = Vector3(0, totalScreenShift, 0);
 				camera->setPosition(cameraPosition);
 			}
 			else
 			{
-				orxout() << "no camera found" << endl;
+				orxout() << "No camera found." << endl;
 				//this->camera = this->figure_->getCamera();
 			}
     	}
+    	else
+    	{
+    		//orxout() << "No figure found." << endl;
+    	}
 
-
-
-
-
+		// Platformen, die zu weit unten sind entfernen
+		Vector3 platformPosition;
+		for (std::list<JumpPlatform*>::iterator it = platformList.begin(); it != platformList.end(); it++)
+		{
+			// IDEE: Statt durch alle platformen in der Liste, wie im Tutorial durch alle objekte im Spiel iterieren --> eigene liste unnoetig
+			platformPosition = (**it).getPosition();
+			if (platformPosition.z < totalScreenShift - center_->getFieldDimension().y)
+			{
+				// Entferne Platform
+				orxout() << "position = " << (**it).getPosition().y << endl;
+				center_->detach(*it);
+				it = platformList.erase(it);
+			}
+		}
     }
 
 
@@ -134,11 +168,11 @@
     */
     void Jump::cleanup()
     {
-        if (this->ball_ != NULL) // Destroy the ball, if present.
+        /*if (this->ball_ != NULL) // Destroy the ball, if present.
         {
             this->ball_->destroy();
             this->ball_ = 0;
-        }
+        }*/
 
         // Destroy both bats, if present.
 		if (this->figure_ != NULL)
@@ -157,18 +191,17 @@
     {
         if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place.
         {
-            if (this->ball_ == NULL) // If there is no ball, create a new ball.
-            {
-                this->ball_ = new JumpPlatform(this->center_->getContext());
-                // Apply the template for the ball specified by the centerpoint.
-                this->ball_->addTemplate(this->center_->getBalltemplate());
-            }
 
+
             // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
-            this->center_->attach(this->ball_);
+            /*this->center_->attach(this->ball_);
             this->ball_->setPosition(0, 0, 0);
             this->ball_->setFieldDimension(this->center_->getFieldDimension());
 
+            // Set the bats for the ball.
+            this->ball_->setFigure(this->figure_);
+            */
+
             // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
 			if (this->figure_ == NULL)
 			{
@@ -184,8 +217,7 @@
             this->figure_->setFieldDimension(this->center_->getFieldDimension());
             this->figure_->setLength(this->center_->getBatLength());
 
-            // Set the bats for the ball.
-            this->ball_->setFigure(this->figure_);
+
         }
         else // If no centerpoint was specified, an error is thrown and the level is exited.
         {
@@ -213,6 +245,13 @@
         }
 
         totalScreenShift = 0.0;
+        screenShiftSinceLastUpdate = 0.0;
+        sectionNumber = 0;
+        sectionLength = 100.0;
+
+        addStartSection();
+        addSection();
+        addSection();
     }
 
     /**
@@ -353,4 +392,86 @@
         }
     }
 
+    void Jump::addPlatform(JumpPlatform* newPlatform, float xPosition, float zPosition)
+    {
+    	if (newPlatform != NULL)
+		{
+    		newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition));
+    		newPlatform->setFieldDimension(center_->getFieldDimension());
+    		newPlatform->setFigure(this->figure_);
+    		center_->attach(newPlatform);
+    		platformList.push_front(newPlatform);
+		}
+    }
+
+    void Jump::addStartSection()
+    {
+		JumpPlatform* newPlatform;
+
+		for (float xPosition = -center_->getFieldDimension().x; xPosition <= center_->getFieldDimension().x; xPosition += 12.0)
+		{
+			newPlatform = new JumpPlatformStatic(center_->getContext());
+			addPlatform(newPlatform, xPosition, -0.05*sectionLength);
+		}
+    }
+
+    void Jump::addSection()
+    {
+        float fieldWidth = center_->getFieldDimension().x;
+        float fieldHeight = center_->getFieldDimension().y;
+
+        float sectionBegin = sectionNumber * sectionLength;
+        float sectionEnd = (1.0 + sectionNumber) * sectionLength;
+
+        JumpPlatformStatic* newPlatformStatic;
+        JumpPlatformHMove* newPlatformHMove;
+        JumpPlatformVMove* newPlatformVMove;
+
+		switch (rand()%3)
+		{
+		case 0:
+			for (int i = 0; i < 10; ++i)
+			{
+				newPlatformStatic = new JumpPlatformStatic(center_->getContext());
+				addPlatform(newPlatformStatic, randomXPosition(), sectionBegin + i*sectionLength/10);
+			}
+			break;
+		case 1:
+			for (int i = 0; i < 10; ++i)
+			{
+				newPlatformHMove = new JumpPlatformHMove(center_->getContext());
+				newPlatformHMove->setProperties(-fieldWidth, fieldWidth, 30.0);
+				addPlatform(newPlatformHMove, randomXPosition(), sectionBegin + i*sectionLength/10);
+			}
+
+			break;
+		case 2:
+			for (int i = 0; i < 10; ++i)
+			{
+				newPlatformVMove = new JumpPlatformVMove(center_->getContext());
+				newPlatformVMove->setProperties(sectionBegin, sectionEnd, 20.0);
+				addPlatform(newPlatformVMove, -fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd));
+			}
+			break;
+		}
+		orxout() << "new section added with number "<< sectionNumber << endl;
+
+		++ sectionNumber;
+    }
+
+    float Jump::randomXPosition()
+    {
+    	return (float)(rand()%(2*(int)center_->getFieldDimension().x)) - center_->getFieldDimension().x;
+    }
+
+    float Jump::randomYPosition(float lowerBoundary, float upperBoundary)
+    {
+    	return (float)(rand()%(int)(upperBoundary - lowerBoundary)) + lowerBoundary;
+    }
+
+    int Jump::getScore(PlayerInfo* player) const
+    {
+        return sectionNumber - 2;
+    }
+
 }

Modified: code/branches/pickupsFS14/src/modules/jump/Jump.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/Jump.h	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/Jump.h	2014-04-22 15:32:37 UTC (rev 10041)
@@ -43,6 +43,8 @@
 #include "gametypes/Deathmatch.h"
 #include "JumpCenterpoint.h"
 
+#include <list>
+
 namespace orxonox
 {
 
@@ -77,6 +79,14 @@
 
             virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
 
+            virtual void addPlatform(JumpPlatform* newPlatform, float xPosition, float zPosition);
+            virtual void addStartSection();
+            virtual void addSection();
+            virtual float randomXPosition();
+            virtual float randomYPosition(float lowerBoundary, float upperBoundary);
+
+            int getScore(PlayerInfo* player) const;
+
             /**
             @brief Set the JumpCenterpoint (the playing field).
             @param center A pointer to the JumpCenterpoint to be set.
@@ -94,13 +104,17 @@
             void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats.
 
             WeakPtr<JumpCenterpoint> center_; //!< The playing field.
-            WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
+            //WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
             WeakPtr<JumpFigure> figure_; //!< The two bats.
             WeakPtr<Camera> camera;
             Timer starttimer_; //!< A timer to delay the start of the game.
             int scoreLimit_; //!< If a player scored that much points, the game is ended.
 
             float totalScreenShift;
+            float screenShiftSinceLastUpdate;
+            float sectionLength;
+            int sectionNumber;
+            std::list<JumpPlatform*> platformList;
     };
 }
 

Modified: code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc	2014-04-22 15:32:37 UTC (rev 10041)
@@ -35,7 +35,7 @@
 
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
-
+#include "graphics/Model.h"
 #include "gametypes/Gametype.h"
 
 #include "JumpFigure.h"
@@ -85,6 +85,8 @@
         this->setPosition(Vector3(0,0,0));
         this->setVelocity(Vector3(0,0,0));
         this->setAcceleration(Vector3(0,0,0));
+
+        model = NULL;
     }
 
     /**
@@ -93,13 +95,13 @@
     */
     JumpPlatform::~JumpPlatform()
     {
-        if (this->isInitialized())
+        /*if (this->isInitialized())
         {
             if (this->bDeleteBats_)
                 delete this->figure_;
 
             delete[] this->batID_;
-        }
+        }*/
     }
 
     //xml port for loading sounds
@@ -136,7 +138,6 @@
         SUPER(JumpPlatform, tick, dt);
 
         Vector3 platformPosition = this->getPosition();
-        Vector3 platformVelocity = this->getVelocity();
 
         if (figure_ != NULL)
         {
@@ -151,6 +152,8 @@
 
 
 
+
+
         /*
         // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
         if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)

Modified: code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h	2014-04-22 15:32:37 UTC (rev 10041)
@@ -110,6 +110,7 @@
             float relMercyOffset_; //!< Offset, that makes the player not loose, when, in all fairness, he would have.
             WorldSound* defScoreSound_;
             WorldSound* defBatSound_;
+            Model* model;
             WorldSound* defBoundarySound_;
     };
 }

Modified: code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h	2014-04-22 15:32:37 UTC (rev 10041)
@@ -69,7 +69,9 @@
 {
     class Jump;
     class JumpPlatform;
+    class JumpPlatformStatic;
     class JumpPlatformHMove;
+    class JumpPlatformVMove;
     class JumpFigure;
     class JumpCenterpoint;
     class JumpScore;

Modified: code/branches/pickupsFS14/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/pickupsFS14/src/orxonox/worldentities/WorldEntity.h	2014-04-17 14:29:25 UTC (rev 10040)
+++ code/branches/pickupsFS14/src/orxonox/worldentities/WorldEntity.h	2014-04-22 15:32:37 UTC (rev 10041)
@@ -163,8 +163,8 @@
             inline void scale3D(float x, float y, float z)
                 { this->scale3D(Vector3(x, y, z)); }
             inline void scale(float scale)
+
                 { this->scale3D(scale, scale, scale); }
-
             virtual void changedScale() {}
 
             void attach(WorldEntity* object);




More information about the Orxonox-commit mailing list