Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10041


Ignore:
Timestamp:
Apr 22, 2014, 5:32:37 PM (10 years ago)
Author:
fvultier
Message:

Level wird zufaellig generiert, HUD funktionier(Punkte werden angezeigt), Diverse bugs behoben, Figur springt von allen Platformen korrekt ab.

Location:
code/branches/pickupsFS14/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt

    r10040 r10041  
    33  Jump.cc
    44  JumpPlatform.cc
     5  JumpPlatformStatic.cc
    56  JumpPlatformHMove.cc
    67  JumpPlatformVMove.cc
  • code/branches/pickupsFS14/src/modules/jump/Jump.cc

    r10040 r10041  
    4444#include "JumpCenterpoint.h"
    4545#include "JumpPlatform.h"
     46#include "JumpPlatformStatic.h"
     47#include "JumpPlatformHMove.h"
     48#include "JumpPlatformVMove.h"
    4649#include "JumpFigure.h"
    4750
     
    6568
    6669        this->center_ = 0;
    67         this->ball_ = 0;
    6870        this->figure_ = 0;
    6971        this->camera = 0;
    7072
    71         //this->setHUDTemplate("JumpHUD");
     73        platformList.clear();
     74
     75        this->setHUDTemplate("JumpHUD");
    7276
    7377        // Pre-set the timer, but don't start it yet.
     
    99103        {
    100104                Vector3 figurePosition = figure_->getPosition();
     105                Vector3 figureVelocity = figure_->getVelocity();
    101106
    102107                if (figurePosition.z > totalScreenShift)
    103108                {
     109                        screenShiftSinceLastUpdate += figurePosition.z - totalScreenShift;
    104110                        totalScreenShift = figurePosition.z;
     111
     112                // Falls noetig neue Platformen im neuen Bereich einfuegen
     113                if (screenShiftSinceLastUpdate > sectionLength)
     114                {
     115                        screenShiftSinceLastUpdate -= sectionLength;
     116                    addSection();
     117                }
    105118                }
    106119
     120                // Spiel verloren wegen Ansturz?
     121                if (figurePosition.z < totalScreenShift - center_->getFieldDimension().y && figureVelocity.z < 0)
     122                {
     123                        end();
     124                }
     125
     126
    107127                if (this->camera != NULL)
    108128                        {
    109                                 Vector3 cameraPosition = Vector3(0,totalScreenShift,0);
     129                                Vector3 cameraPosition = Vector3(0, totalScreenShift, 0);
    110130                                camera->setPosition(cameraPosition);
    111131                        }
    112132                        else
    113133                        {
    114                                 orxout() << "no camera found" << endl;
     134                                orxout() << "No camera found." << endl;
    115135                                //this->camera = this->figure_->getCamera();
    116136                        }
    117137        }
    118 
    119 
    120 
    121 
    122 
     138        else
     139        {
     140                //orxout() << "No figure found." << endl;
     141        }
     142
     143                // Platformen, die zu weit unten sind entfernen
     144                Vector3 platformPosition;
     145                for (std::list<JumpPlatform*>::iterator it = platformList.begin(); it != platformList.end(); it++)
     146                {
     147                        // IDEE: Statt durch alle platformen in der Liste, wie im Tutorial durch alle objekte im Spiel iterieren --> eigene liste unnoetig
     148                        platformPosition = (**it).getPosition();
     149                        if (platformPosition.z < totalScreenShift - center_->getFieldDimension().y)
     150                        {
     151                                // Entferne Platform
     152                                orxout() << "position = " << (**it).getPosition().y << endl;
     153                                center_->detach(*it);
     154                                it = platformList.erase(it);
     155                        }
     156                }
    123157    }
    124158
     
    135169    void Jump::cleanup()
    136170    {
    137         if (this->ball_ != NULL) // Destroy the ball, if present.
     171        /*if (this->ball_ != NULL) // Destroy the ball, if present.
    138172        {
    139173            this->ball_->destroy();
    140174            this->ball_ = 0;
    141         }
     175        }*/
    142176
    143177        // Destroy both bats, if present.
     
    158192        if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place.
    159193        {
    160             if (this->ball_ == NULL) // If there is no ball, create a new ball.
    161             {
    162                 this->ball_ = new JumpPlatform(this->center_->getContext());
    163                 // Apply the template for the ball specified by the centerpoint.
    164                 this->ball_->addTemplate(this->center_->getBalltemplate());
    165             }
     194
    166195
    167196            // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
    168             this->center_->attach(this->ball_);
     197            /*this->center_->attach(this->ball_);
    169198            this->ball_->setPosition(0, 0, 0);
    170199            this->ball_->setFieldDimension(this->center_->getFieldDimension());
     200
     201            // Set the bats for the ball.
     202            this->ball_->setFigure(this->figure_);
     203            */
    171204
    172205            // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
     
    185218            this->figure_->setLength(this->center_->getBatLength());
    186219
    187             // Set the bats for the ball.
    188             this->ball_->setFigure(this->figure_);
     220
    189221        }
    190222        else // If no centerpoint was specified, an error is thrown and the level is exited.
     
    214246
    215247        totalScreenShift = 0.0;
     248        screenShiftSinceLastUpdate = 0.0;
     249        sectionNumber = 0;
     250        sectionLength = 100.0;
     251
     252        addStartSection();
     253        addSection();
     254        addSection();
    216255    }
    217256
     
    354393    }
    355394
     395    void Jump::addPlatform(JumpPlatform* newPlatform, float xPosition, float zPosition)
     396    {
     397        if (newPlatform != NULL)
     398                {
     399                newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition));
     400                newPlatform->setFieldDimension(center_->getFieldDimension());
     401                newPlatform->setFigure(this->figure_);
     402                center_->attach(newPlatform);
     403                platformList.push_front(newPlatform);
     404                }
     405    }
     406
     407    void Jump::addStartSection()
     408    {
     409                JumpPlatform* newPlatform;
     410
     411                for (float xPosition = -center_->getFieldDimension().x; xPosition <= center_->getFieldDimension().x; xPosition += 12.0)
     412                {
     413                        newPlatform = new JumpPlatformStatic(center_->getContext());
     414                        addPlatform(newPlatform, xPosition, -0.05*sectionLength);
     415                }
     416    }
     417
     418    void Jump::addSection()
     419    {
     420        float fieldWidth = center_->getFieldDimension().x;
     421        float fieldHeight = center_->getFieldDimension().y;
     422
     423        float sectionBegin = sectionNumber * sectionLength;
     424        float sectionEnd = (1.0 + sectionNumber) * sectionLength;
     425
     426        JumpPlatformStatic* newPlatformStatic;
     427        JumpPlatformHMove* newPlatformHMove;
     428        JumpPlatformVMove* newPlatformVMove;
     429
     430                switch (rand()%3)
     431                {
     432                case 0:
     433                        for (int i = 0; i < 10; ++i)
     434                        {
     435                                newPlatformStatic = new JumpPlatformStatic(center_->getContext());
     436                                addPlatform(newPlatformStatic, randomXPosition(), sectionBegin + i*sectionLength/10);
     437                        }
     438                        break;
     439                case 1:
     440                        for (int i = 0; i < 10; ++i)
     441                        {
     442                                newPlatformHMove = new JumpPlatformHMove(center_->getContext());
     443                                newPlatformHMove->setProperties(-fieldWidth, fieldWidth, 30.0);
     444                                addPlatform(newPlatformHMove, randomXPosition(), sectionBegin + i*sectionLength/10);
     445                        }
     446
     447                        break;
     448                case 2:
     449                        for (int i = 0; i < 10; ++i)
     450                        {
     451                                newPlatformVMove = new JumpPlatformVMove(center_->getContext());
     452                                newPlatformVMove->setProperties(sectionBegin, sectionEnd, 20.0);
     453                                addPlatform(newPlatformVMove, -fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd));
     454                        }
     455                        break;
     456                }
     457                orxout() << "new section added with number "<< sectionNumber << endl;
     458
     459                ++ sectionNumber;
     460    }
     461
     462    float Jump::randomXPosition()
     463    {
     464        return (float)(rand()%(2*(int)center_->getFieldDimension().x)) - center_->getFieldDimension().x;
     465    }
     466
     467    float Jump::randomYPosition(float lowerBoundary, float upperBoundary)
     468    {
     469        return (float)(rand()%(int)(upperBoundary - lowerBoundary)) + lowerBoundary;
     470    }
     471
     472    int Jump::getScore(PlayerInfo* player) const
     473    {
     474        return sectionNumber - 2;
     475    }
     476
    356477}
  • code/branches/pickupsFS14/src/modules/jump/Jump.h

    r10040 r10041  
    4444#include "JumpCenterpoint.h"
    4545
     46#include <list>
     47
    4648namespace orxonox
    4749{
     
    7880            virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
    7981
     82            virtual void addPlatform(JumpPlatform* newPlatform, float xPosition, float zPosition);
     83            virtual void addStartSection();
     84            virtual void addSection();
     85            virtual float randomXPosition();
     86            virtual float randomYPosition(float lowerBoundary, float upperBoundary);
     87
     88            int getScore(PlayerInfo* player) const;
     89
    8090            /**
    8191            @brief Set the JumpCenterpoint (the playing field).
     
    95105
    96106            WeakPtr<JumpCenterpoint> center_; //!< The playing field.
    97             WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
     107            //WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
    98108            WeakPtr<JumpFigure> figure_; //!< The two bats.
    99109            WeakPtr<Camera> camera;
     
    102112
    103113            float totalScreenShift;
     114            float screenShiftSinceLastUpdate;
     115            float sectionLength;
     116            int sectionNumber;
     117            std::list<JumpPlatform*> platformList;
    104118    };
    105119}
  • code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc

    r10040 r10041  
    3636#include "core/CoreIncludes.h"
    3737#include "core/GameMode.h"
    38 
     38#include "graphics/Model.h"
    3939#include "gametypes/Gametype.h"
    4040
     
    8686        this->setVelocity(Vector3(0,0,0));
    8787        this->setAcceleration(Vector3(0,0,0));
     88
     89        model = NULL;
    8890    }
    8991
     
    9496    JumpPlatform::~JumpPlatform()
    9597    {
    96         if (this->isInitialized())
     98        /*if (this->isInitialized())
    9799        {
    98100            if (this->bDeleteBats_)
     
    100102
    101103            delete[] this->batID_;
    102         }
     104        }*/
    103105    }
    104106
     
    137139
    138140        Vector3 platformPosition = this->getPosition();
    139         Vector3 platformVelocity = this->getVelocity();
    140141
    141142        if (figure_ != NULL)
     
    149150            }
    150151        }
     152
     153
    151154
    152155
  • code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h

    r10040 r10041  
    111111            WorldSound* defScoreSound_;
    112112            WorldSound* defBatSound_;
     113            Model* model;
    113114            WorldSound* defBoundarySound_;
    114115    };
  • code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h

    r10040 r10041  
    7070    class Jump;
    7171    class JumpPlatform;
     72    class JumpPlatformStatic;
    7273    class JumpPlatformHMove;
     74    class JumpPlatformVMove;
    7375    class JumpFigure;
    7476    class JumpCenterpoint;
  • code/branches/pickupsFS14/src/orxonox/worldentities/WorldEntity.h

    r9667 r10041  
    164164                { this->scale3D(Vector3(x, y, z)); }
    165165            inline void scale(float scale)
     166
    166167                { this->scale3D(scale, scale, scale); }
    167 
    168168            virtual void changedScale() {}
    169169
Note: See TracChangeset for help on using the changeset viewer.