Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 11, 2018, 4:49:56 PM (7 years ago)
Author:
landauf
Message:

fixed crash when setting highscore

Location:
code/branches/Presentation_HS17_merge/src/modules
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2D.cc

    r11727 r11729  
    5959#include "Highscore.h"
    6060#include "gamestates/GSLevel.h"
     61#include "infos/PlayerInfo.h"
    6162
    6263namespace orxonox
     
    124125        if(this->firstTick_)
    125126        {
    126             getPlayer();
    127127            for(int i = 0; i < 5; ++i)
    128128            {
     
    141141        //stones are created with a size -> second constructor in Asteroids2DStone class
    142142        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
    143         newStone->setAsteroids2DPlayer(player);
    144143
    145144        //look at templates in data/levels/templates/asteroidsAsteroids2D.oxt
     
    163162    Asteroids2DShip* Asteroids2D::getPlayer()
    164163    {
    165         if (player == nullptr)
    166         {
    167             for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
    168             {
    169                 player = ship;
    170             }
    171         }
    172         return player;
     164        for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
     165        {
     166            return ship;
     167        }
     168        return nullptr;
    173169    }
    174170
     
    201197    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
    202198    {
     199        this->playerInfo_ = player;
    203200        if(lives <= 0)
    204201        {
     
    226223        {
    227224            int score = this->getPoints();
    228             Highscore::getInstance().storeScore("Asteroids2D", score, this->getPlayer()->getPlayer());
     225            Highscore::getInstance().storeScore("Asteroids2D", score, this->playerInfo_);
    229226        }
    230227        GSLevel::startMainMenu();
  • code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2D.h

    r11727 r11729  
    9494
    9595
    96             WeakPtr<Asteroids2DShip> player;
     96            WeakPtr<PlayerInfo> playerInfo_;
    9797            void toggleShowLevel(){bShowLevel = !bShowLevel;}
    9898
  • code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.h

    r11666 r11729  
    5353            Vector3 randomPosition (float maxwidth, float maxheight);
    5454            Vector3 randomVelocity(float maxspeed);
    55             void setAsteroids2DPlayer(Asteroids2DShip* player){this->player = player;};
    5655            virtual int getSize(){ return this->size;}
    5756            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
     
    6261          Asteroids2D* getGame();
    6362          WeakPtr<Asteroids2D> game;
    64           WeakPtr<Asteroids2DShip> player;         
    6563                int size;                               // three sizes, 3-> two 2s, 2-> two 1s, 1-> die
    6664                float width, height;    //field
  • code/branches/Presentation_HS17_merge/src/modules/dodgerace/DodgeRace.cc

    r11716 r11729  
    3737#include "core/CoreIncludes.h"
    3838#include "Highscore.h"
     39#include "infos/PlayerInfo.h"
    3940
    4041namespace orxonox
     
    9091    void DodgeRace::tick(float dt)
    9192    {
    92         if (getPlayer() != nullptr)
    93         {
    94             currentPosition = getPlayer()->getWorldPosition().x;
     93        DodgeRaceShip* player = this->getPlayer();
     94        if (player != nullptr)
     95        {
     96            currentPosition = player->getWorldPosition().x;
    9597            counter = counter + (currentPosition - lastPosition);
    9698            lastPosition = currentPosition;
    9799            point = (int) currentPosition;
    98             getPlayer()->speed = 830.0f - (point / 1000);
     100            player->speed = 830.0f - (point / 1000);
    99101
    100102            for(unsigned int i=0; i < cubeList.size();i++)
     
    123125                    }
    124126
    125                     cube->setPosition(getPlayer()->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
     127                    cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
    126128                    //stEntity->setScale3D(50,50,50);
    127129                }
     
    139141    DodgeRaceShip* DodgeRace::getPlayer()
    140142    {
    141         if (player == nullptr)
    142         {
    143             for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())
    144             {
    145                 player = ship;
    146             }
    147         }
    148         return player;
     143        for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())
     144        {
     145            return ship;
     146        }
     147        return nullptr;
    149148    }
    150149
     
    190189    void DodgeRace::playerPreSpawn(PlayerInfo* player)
    191190    {
     191        this->playerInfo_ = player;
    192192        if(lives <= 0)
    193193        {
     
    228228        {
    229229            int score = this->getPoints();
    230             Highscore::getInstance().storeScore("Dodge Race", score, this->getPlayer()->getPlayer());
     230            Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_);
    231231        }
    232232        GSLevel::startMainMenu();
  • code/branches/Presentation_HS17_merge/src/modules/dodgerace/DodgeRace.h

    r11071 r11729  
    103103
    104104            DodgeRaceShip* getPlayer();
    105             WeakPtr<DodgeRaceShip> player;
     105            WeakPtr<PlayerInfo> playerInfo_;
    106106            std::vector<DodgeRaceCube*> cubeList;
    107107            void toggleShowLevel(){bShowLevel = !bShowLevel;}
Note: See TracChangeset for help on using the changeset viewer.