Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10040


Ignore:
Timestamp:
Apr 17, 2014, 4:29:25 PM (11 years ago)
Author:
fvultier
Message:

Bewegung mit WASD und Absprung von einer Platform in der Mitte funktioniert.

Location:
code/branches/pickupsFS14/src/modules/jump
Files:
6 edited

Legend:

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

    r10017 r10040  
    1 SET_SOURCE_FILES(Jump_SRC_FILES
     1SET_SOURCE_FILES(JUMP_SRC_FILES
    22BUILD_UNIT JumpBuildUnit.cc
    33  Jump.cc
    4   JumpCenterPoint.cc
    5   JumpShip.cc
    64  JumpPlatform.cc
     5  JumpPlatformHMove.cc
     6  JumpPlatformVMove.cc
     7  JumpFigure.cc
     8  JumpCenterpoint.cc
     9  JumpScore.cc
    710END_BUILD_UNIT
    811)
     
    1417    orxonox
    1518    overlays
    16     weapons
    17   SOURCE_FILES ${Jump_SRC_FILES}
     19  SOURCE_FILES ${JUMP_SRC_FILES}
    1820)
  • code/branches/pickupsFS14/src/modules/jump/Jump.cc

    r10032 r10040  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    3333
    3434#include "Jump.h"
     35
    3536#include "core/CoreIncludes.h"
    3637#include "core/EventIncludes.h"
     
    4142#include "chat/ChatManager.h"
    4243
    43 // ! HACK
     44#include "JumpCenterpoint.h"
     45#include "JumpPlatform.h"
     46#include "JumpFigure.h"
     47
    4448#include "infos/PlayerInfo.h"
    45 
    46 #include "JumpCenterPoint.h"
    47 #include "JumpShip.h"
    48 /*
    49 #include "JumpEnemy.h"
    50 #include "JumpEnemyShooter.h"*/
    51 
    52 #include "core/command/ConsoleCommand.h"
    53 #include "worldentities/BigExplosion.h"
    5449
    5550namespace orxonox
    5651{
     52    // Events to allow to react to scoring of a player, in the level-file.
     53    CreateEventName(JumpCenterpoint, right);
     54    CreateEventName(JumpCenterpoint, left);
     55
    5756    RegisterUnloadableClass(Jump);
    5857
     58    /**
     59    @brief
     60        Constructor. Registers and initializes the object.
     61    */
    5962    Jump::Jump(Context* context) : Deathmatch(context)
    6063    {
    6164        RegisterObject(Jump);
    62         platformList.clear();
    63         yScreenPosition = 0;
    64         screenShiftSinceLastUpdate = 0;
    65 
    66         //this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    67         //this->center_ = 0;
     65
     66        this->center_ = 0;
     67        this->ball_ = 0;
     68        this->figure_ = 0;
     69        this->camera = 0;
     70
    6871        //this->setHUDTemplate("JumpHUD");
    6972
    70 
    71     }
    72 
    73 
    74     /*void Jump::levelUp()
    75     {
    76         level++;
    77         if (getPlayer() != NULL)
    78         {
    79             for (int i = 0; i < 7; i++)
     73        // Pre-set the timer, but don't start it yet.
     74        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this)));
     75        this->starttimer_.stopTimer();
     76
     77
     78        this->scoreLimit_ = 10;
     79        this->setConfigValues();
     80    }
     81
     82    /**
     83    @brief
     84        Destructor. Cleans up, if initialized.
     85    */
     86    Jump::~Jump()
     87    {
     88        if (this->isInitialized())
     89        {
     90            this->cleanup();
     91        }
     92    }
     93
     94    void Jump::tick(float dt)
     95    {
     96        SUPER(Jump, tick, dt);
     97
     98        if (figure_ != NULL)
     99        {
     100                Vector3 figurePosition = figure_->getPosition();
     101
     102                if (figurePosition.z > totalScreenShift)
     103                {
     104                        totalScreenShift = figurePosition.z;
     105                }
     106
     107                if (this->camera != NULL)
     108                        {
     109                                Vector3 cameraPosition = Vector3(0,totalScreenShift,0);
     110                                camera->setPosition(cameraPosition);
     111                        }
     112                        else
     113                        {
     114                                orxout() << "no camera found" << endl;
     115                                //this->camera = this->figure_->getCamera();
     116                        }
     117        }
     118
     119
     120
     121
     122
     123    }
     124
     125
     126    void Jump::setConfigValues()
     127    {
     128        SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
     129    }
     130
     131    /**
     132    @brief
     133        Cleans up the Gametype by destroying the ball and the bats.
     134    */
     135    void Jump::cleanup()
     136    {
     137        if (this->ball_ != NULL) // Destroy the ball, if present.
     138        {
     139            this->ball_->destroy();
     140            this->ball_ = 0;
     141        }
     142
     143        // Destroy both bats, if present.
     144                if (this->figure_ != NULL)
     145                {
     146                        this->figure_->destroy();
     147                        this->figure_ = 0;
     148                }
     149                this->camera = 0;
     150    }
     151
     152    /**
     153    @brief
     154        Starts the Jump minigame.
     155    */
     156    void Jump::start()
     157    {
     158        if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place.
     159        {
     160            if (this->ball_ == NULL) // If there is no ball, create a new ball.
    80161            {
    81                 WeakPtr<BigExplosion> chunk = new BigExplosion(this->center_->getContext());
    82                 chunk->setPosition(Vector3(600, 0, 100.f * i - 300));
    83                 chunk->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
    84                 chunk->setScale(20);
     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());
    85165            }
    86         }
    87         addPoints(multiplier * 42);
    88         multiplier *= 2;
    89         toggleShowLevel();
    90         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Jump::toggleShowLevel, this)));
    91     }*/
    92 
    93     WeakPtr<JumpShip> Jump::getPlayer()
    94     {
    95         if (player == NULL)
    96         {
    97                 for (ObjectList<JumpShip>::iterator it = ObjectList<JumpShip>::begin(); it != ObjectList<JumpShip>::end(); ++it)
    98                 {
    99                 player = *it;
    100                 }
    101         }
    102         return player;
    103     }
    104 
    105     void Jump::tick(float dt)
    106     {
    107 
    108 
    109         if (getPlayer() != NULL)
    110         {
    111             Vector3 shipPosition = getPlayer()->getPosition();
    112 
    113                 // Bildschirmposition kann nur nach oben verschoben werden
    114                 if (shipPosition.y > yScreenPosition)
    115                 {
    116                         screenShiftSinceLastUpdate += shipPosition.y - yScreenPosition;
    117 
    118                         yScreenPosition = shipPosition.y;
    119                 }
    120 
    121                 // Kameraposition nachfuehren
    122                 if (camera == NULL)
    123                 {
    124                         camera = getPlayer()->getCamera();
    125                 }
    126             if (camera != NULL)
    127             {
    128                 camera->setPosition(Vector3(-shipPosition.x, yScreenPosition-shipPosition.y, 100));
    129                 //camera->setOrientation(Vector3::UNIT_Z, Degree(180));
    130             }
    131 
    132             if (screenShiftSinceLastUpdate > 200.0)
    133             {
    134                 screenShiftSinceLastUpdate -= 200.0;
    135                 orxout() << "new section added" << endl;
    136                 addPlatform(shipPosition.x, shipPosition.y + 300.0);
    137             }
    138 
    139         }
    140 
    141         SUPER(Jump, tick, dt);
    142     }
    143 
    144 
    145     /*void Jump::spawnEnemy()
    146     {
    147         if (getPlayer() == NULL)
    148             return;
    149 
    150         for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
    151         {
    152             WeakPtr<JumpEnemy> newPawn;
    153             if (rand() % 42/(1 + level*level) == 0)
    154             {
    155                 newPawn = new JumpEnemyShooter(this->center_->getContext());
    156                 newPawn->addTemplate("enemyjumpshooter");
    157             }
    158             else
    159             {
    160                 newPawn = new JumpEnemy(this->center_->getContext());
    161                 newPawn->addTemplate("enemyjump");
    162             }
    163             newPawn->setPlayer(player);
    164             newPawn->level = level;
    165             // spawn enemy at random points in front of player.
    166             newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
    167         }
    168     }*/
    169 
    170     /*void Jump::costLife()
    171     {
    172         lives--;
    173         multiplier = 1;
    174         // end the game in 30 seconds.
    175         if (lives <= 0)
    176             enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Jump::end, this)));
    177     };*/
    178 
    179     /*void Jump::comboControll()
    180     {
    181         if (b_combo)
    182             multiplier++;
    183         // if no combo was performed before, reset multiplier
    184         else
    185             multiplier = 1;
    186         b_combo = false;
    187     }*/
    188 
    189 
    190     void Jump::start()
    191     {
    192         // Call start for the parent class.
    193         Deathmatch::start();
    194 
    195         /*
    196         // Set variable to temporarily force the player to spawn.
    197         this->bForceSpawn_ = true;
    198 
    199         if (this->center_ == NULL)  // abandon mission!
     166
     167            // 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_);
     169            this->ball_->setPosition(0, 0, 0);
     170            this->ball_->setFieldDimension(this->center_->getFieldDimension());
     171
     172            // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
     173                        if (this->figure_ == NULL)
     174                        {
     175                                this->figure_ = new JumpFigure(this->center_->getContext());
     176                                this->figure_->addTemplate(this->center_->getBattemplate());
     177                        }
     178
     179            // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to.
     180            this->center_->attach(this->figure_);
     181            this->figure_->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
     182            this->figure_->yaw(Degree(-90));
     183            this->figure_->setSpeed(this->center_->getBatSpeed());
     184            this->figure_->setFieldDimension(this->center_->getFieldDimension());
     185            this->figure_->setLength(this->center_->getBatLength());
     186
     187            // Set the bats for the ball.
     188            this->ball_->setFigure(this->figure_);
     189        }
     190        else // If no centerpoint was specified, an error is thrown and the level is exited.
    200191        {
    201192            orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
     
    203194            return;
    204195        }
     196
     197        // Start the timer. After it has expired the ball is started.
     198        this->starttimer_.startTimer();
     199
     200        // Set variable to temporarily force the player to spawn.
     201        bool temp = this->bForceSpawn_;
     202        this->bForceSpawn_ = true;
     203
     204        // Call start for the parent class.
     205        Deathmatch::start();
     206
     207        // Reset the variable.
     208        this->bForceSpawn_ = temp;
     209
     210        if (this->figure_ != NULL)
     211        {
     212                this->camera = this->figure_->getCamera();
     213        }
     214
     215        totalScreenShift = 0.0;
     216    }
     217
     218    /**
     219    @brief
     220        Ends the Jump minigame.
     221    */
     222    void Jump::end()
     223    {
     224        this->cleanup();
     225
     226        // Call end for the parent class.
     227        Deathmatch::end();
     228    }
     229
     230    /**
     231    @brief
     232        Spawns players, and fills the rest up with bots.
     233    */
     234    void Jump::spawnPlayersIfRequested()
     235    {
     236
     237        // first spawn human players to assign always the left bat to the player in singleplayer
     238        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     239            if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
     240                this->spawnPlayer(it->first);
     241        // now spawn bots
     242        /*
     243        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     244            if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
     245                this->spawnPlayer(it->first);
    205246        */
    206 
    207         //addPlatform(0,0);
    208 
    209     }
    210 
    211 
    212     /*void Jump::addPoints(int numPoints)
    213     {
    214         if (!bEndGame)
    215         {
    216             point += numPoints * multiplier;
    217             b_combo = true;
    218         }
    219     }*/
    220 
    221     /*void Jump::end()
    222     {
    223         // DON'T CALL THIS!
    224         //      Deathmatch::end();
    225         // It will misteriously crash the game!
    226         // Instead startMainMenu, this won't crash.
    227         GSLevel::startMainMenu();
    228     }*/
    229 
    230     void Jump::addPlatform(float xPosition, float yPosition)
    231     {
    232                 JumpPlatform* newPlatform = new JumpPlatform(center_->getContext());
    233                 newPlatform->setPosition(Vector3(xPosition, yPosition, 0));
    234                 platformList.push_front(newPlatform);
     247    }
     248
     249    /**
     250    @brief
     251        Spawns the input player.
     252    @param player
     253        The player to be spawned.
     254    */
     255    void Jump::spawnPlayer(PlayerInfo* player)
     256    {
     257        assert(player);
     258
     259        // If the first (left) bat has no player.
     260        if (this->figure_->getPlayer() == NULL)
     261        {
     262            player->startControl(this->figure_);
     263            this->players_[player].state_ = PlayerState::Alive;
     264        }
     265        // If both bats are taken.
     266        else
     267        {
     268            return;
     269        }
     270
     271    }
     272
     273    /**
     274    @brief
     275        Is called when the player scored.
     276    */
     277    void Jump::playerScored(PlayerInfo* player, int score)
     278    {
     279        /*
     280        Deathmatch::playerScored(player, score);
     281        if (this->center_ != NULL) // If there is a centerpoint.
     282        {
     283            // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks.
     284            if (player == this->getRightPlayer())
     285                this->center_->fireEvent(FireEventName(JumpCenterpoint, right));
     286            else if (player == this->getLeftPlayer())
     287                this->center_->fireEvent(FireEventName(JumpCenterpoint, left));
     288
     289            // Also announce, that the player has scored.
     290            if (player != NULL)
     291                this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
     292        }
     293
     294        // If there is a ball present, reset its position, velocity and acceleration.
     295        if (this->ball_ != NULL)
     296        {
     297            this->ball_->setPosition(Vector3::ZERO);
     298            this->ball_->setVelocity(Vector3::ZERO);
     299            this->ball_->setAcceleration(Vector3::ZERO);
     300            this->ball_->setSpeed(0);
     301        }
     302
     303        // If there are bats reset them to the middle position.
     304        if (this->figure_[0] != NULL && this->figure_[1] != NULL)
     305        {
     306            this->figure_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
     307            this->figure_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
     308        }
     309
     310        // If a player gets enough points, he won the game -> end of game
     311        PlayerInfo* winningPlayer = NULL;
     312        if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_)
     313            winningPlayer = this->getLeftPlayer();
     314        else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_)
     315            winningPlayer = getLeftPlayerthis->getRightPlayer();
     316
     317        if (winningPlayer)
     318        {
     319             ChatManager::message(winningPlayer->getName() + " has won!");
     320             this->end();
     321        }
     322
     323        // Restart the timer to start the ball.
     324        this->starttimer_.startTimer();
     325
     326        */
     327    }
     328
     329    /**
     330    @brief
     331        Starts the ball with some default speed.
     332    */
     333    void Jump::startBall()
     334    {
     335
     336    }
     337
     338    /**
     339    @brief
     340        Get the left player.
     341    @return
     342        Returns a pointer to the player playing on the left. If there is no left player, NULL is returned.
     343    */
     344    PlayerInfo* Jump::getPlayer() const
     345    {
     346        if (this->figure_ != NULL)
     347        {
     348            return this->figure_->getPlayer();
     349        }
     350        else
     351        {
     352            return 0;
     353        }
    235354    }
    236355
  • code/branches/pickupsFS14/src/modules/jump/Jump.h

    r10032 r10040  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    2929/**
    3030    @file Jump.h
    31     @brief Gametype.
     31    @brief Declaration of the Jump class.
    3232    @ingroup Jump
    3333*/
     
    3737
    3838#include "jump/JumpPrereqs.h"
     39
     40#include "tools/Timer.h"
     41#include "graphics/Camera.h"
     42
    3943#include "gametypes/Deathmatch.h"
    40 #include "JumpCenterPoint.h"
    41 #include "tools/Timer.h"
    42 #include "JumpPlatform.h"
    43 #include <list>
    44 
     44#include "JumpCenterpoint.h"
    4545
    4646namespace orxonox
    4747{
    4848
     49    /**
     50    @brief
     51        Implements a Jump minigame (<a href="http://en.wikipedia.org/wiki/Jump">Wikipedia::Jump</a>).
     52        It connects the different entities present in a game of Jump.
     53
     54        - The @ref orxonox::JumpCenterpoint "JumpCenterpoint" is the playing field for the Jump minigame, it allows for configuration of the minigame, e.g. by setting the size of the playing field, or the length of the @ref orxonox::JumpFigure "JumpFigures". The playing field is always in the x,y-plane, the x-axis being the horizontal and the z-axis being the vertical axis.<br />
     55        The Jump class redistributes the important parameters defined in @ref orxonox::JumpCenterpoint "JumpCenterpoint" to the other entities, that need to know them, e.g. the @ref orxonox::JumpPlatform "JumpPlatform" and the @ref orxonox::JumpFigure "JumpFigures".<br />
     56        The @ref orxonox::JumpCenterpoint "JumpCenterpoint" needs to exist in a level with the @ref orxonox::Gametype "Gametype" <em>Jump</em>.
     57        - The @ref orxonox::JumpPlatform "JumpPlatform" is the ball both players play with. The @ref orxonox::JumpPlatform "JumpPlatform" both implements the movement of the ball, as well as the influence of the boundaries and consequently, also the bouncing (off the upper and lower delimiters, and as off the @ref orxonox::JumpFigure "JumpFigures") of the ball and the effects of the failure of a player to catch the ball (i.e. the scoring of the other player).
     58        - The two @ref orxonox::JumpFigure "JumpFigures" are the entities through which the players can actively participate in the game, by controlling them. The @ref orxonox::JumpFigure "JumpFigure" class manages the movement (and restrictions thereof) and the influence of the players on the bats.
     59
     60    @author
     61        Fabian 'x3n' Landau
     62
     63    @ingroup Jump
     64    */
    4965    class _JumpExport Jump : public Deathmatch
    5066    {
    5167        public:
    52             Jump(Context* context);
    53             virtual void start();
    54             //virtual void end();
    55             //virtual void addBots(unsigned int amount){} //<! overwrite function in order to bypass the addbots command
     68            Jump(Context* context); //!< Constructor. Registers and initializes the object.
     69            virtual ~Jump(); //!< Destructor. Cleans up, if initialized.
    5670
    5771            virtual void tick(float dt);
    5872
    59             //void spawnEnemy();
     73            virtual void start(); //!< Starts the Jump minigame.
     74            virtual void end(); ///!< Ends the Jump minigame.
    6075
    61             void setCenterpoint(JumpCenterPoint* center){ this->center_ = center; }
     76            virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player.
    6277
    63             virtual void addPlatform(float x, float y);
     78            virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
    6479
    65            /*int getLives(){return this->lives;}
    66             int getLevel(){return this->level;}
    67             int getPoints(){return this->point;}
    68             int getMultiplier(){return this->multiplier;}*/
     80            /**
     81            @brief Set the JumpCenterpoint (the playing field).
     82            @param center A pointer to the JumpCenterpoint to be set.
     83            */
     84            void setCenterpoint(JumpCenterpoint* center)
     85                { this->center_ = center; }
     86            void setConfigValues(); //!< Makes scoreLimit configurable.
    6987
    70             /*void costLife();
    71             void levelUp();
    72             void addPoints(int numPoints);
    73             // checks if multiplier should be reset.
    74             void comboControll();*/
    75             //int lives;
    76             //int multiplier;
    77             //bool bEndGame;
    78             //bool bShowLevel;
    79         private:
    80             //void toggleShowLevel(){bShowLevel = !bShowLevel;}
    81             WeakPtr<JumpShip> getPlayer();
    82             WeakPtr<JumpCenterPoint> center_;
    83             WeakPtr<JumpShip> player;
     88            PlayerInfo* getPlayer() const; //!< Get the left player.
     89
     90        protected:
     91            virtual void spawnPlayersIfRequested(); //!< Spawns players, and fills the rest up with bots.
     92
     93            void startBall(); //!< Starts the ball with some default speed.
     94            void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats.
     95
     96            WeakPtr<JumpCenterpoint> center_; //!< The playing field.
     97            WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
     98            WeakPtr<JumpFigure> figure_; //!< The two bats.
    8499            WeakPtr<Camera> camera;
     100            Timer starttimer_; //!< A timer to delay the start of the game.
     101            int scoreLimit_; //!< If a player scored that much points, the game is ended.
    85102
    86             /*Timer enemySpawnTimer;
    87             Timer comboTimer;
    88             Timer showLevelTimer;
    89             //Context* context; <-- War schon auskommentiert!!!
    90             int level;
    91             int point;
    92             bool b_combo;*/
    93             std::list<JumpPlatform*> platformList;
    94             float yScreenPosition;
    95             float screenShiftSinceLastUpdate;
     103            float totalScreenShift;
    96104    };
    97105}
  • code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc

    r10032 r10040  
    2121 *
    2222 *   Author:
    23  *      Benjamin de Capitani
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    2727 */
    2828
     29/**
     30    @file JumpPlatform.cc
     31    @brief Implementation of the JumpPlatform class.
     32*/
     33
    2934#include "JumpPlatform.h"
    3035
    3136#include "core/CoreIncludes.h"
    3237#include "core/GameMode.h"
    33 #include "core/command/Executor.h"
    34 #include "tools/ParticleInterface.h"
    35 #include "Scene.h"
    36 #include "graphics/ParticleSpawner.h"
    37 #include "graphics/Model.h"
    38 #include "worldentities/MovableEntity.h"
    39 #include "chat/ChatManager.h"
    40 #include "OrxonoxPrereqs.h"
     38
     39#include "gametypes/Gametype.h"
     40
     41#include "JumpFigure.h"
     42
     43#include "sound/WorldSound.h"
     44#include "core/XMLPort.h"
    4145
    4246namespace orxonox
     
    4448    RegisterClass(JumpPlatform);
    4549
    46     JumpPlatform::JumpPlatform(Context* context) : MobileEntity(context)
     50    const float JumpPlatform::MAX_REL_Z_VELOCITY = 1.5;
     51
     52    /**
     53    @brief
     54        Constructor. Registers and initializes the object.
     55    */
     56    JumpPlatform::JumpPlatform(Context* context) : MovableEntity(context)
    4757    {
    4858        RegisterObject(JumpPlatform);
    4959
    50 
    51         model = new Model(getContext());
    52         model->setSyncMode(0);
    53         model->setMeshSource("Platform01.mesh");
    54 
    55         attach(model);
    56         setScale(5);
    57         setPosition(Vector3(0,0,0));
    58         setVelocity(Vector3(0,0,0));
    59 
    60     }
    61 
     60        this->figure_ = 0;
     61        this->bDeleteBats_ = false;
     62        this->batID_ = new unsigned int[1];
     63        this->batID_[0] = OBJECTID_UNKNOWN;
     64        this->relMercyOffset_ = 0.05f;
     65
     66        this->registerVariables();
     67
     68        //initialize sound
     69        if (GameMode::isMaster())
     70                 {
     71                         this->defScoreSound_ = new WorldSound(this->getContext());
     72                         this->defScoreSound_->setVolume(1.0f);
     73                         this->defBatSound_ = new WorldSound(this->getContext());
     74                         this->defBatSound_->setVolume(0.4f);
     75                         this->defBoundarySound_ = new WorldSound(this->getContext());
     76                         this->defBoundarySound_->setVolume(0.5f);
     77                 }
     78                 else
     79                 {
     80                         this->defScoreSound_ = 0;
     81                         this->defBatSound_ = 0;
     82                         this->defBoundarySound_ = 0;
     83                 }
     84
     85        this->setPosition(Vector3(0,0,0));
     86        this->setVelocity(Vector3(0,0,0));
     87        this->setAcceleration(Vector3(0,0,0));
     88    }
     89
     90    /**
     91    @brief
     92        Destructor.
     93    */
     94    JumpPlatform::~JumpPlatform()
     95    {
     96        if (this->isInitialized())
     97        {
     98            if (this->bDeleteBats_)
     99                delete this->figure_;
     100
     101            delete[] this->batID_;
     102        }
     103    }
     104
     105    //xml port for loading sounds
     106    void JumpPlatform::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     107    {
     108        SUPER(JumpPlatform, XMLPort, xmlelement, mode);
     109        XMLPortParam(JumpPlatform, "defScoreSound",  setDefScoreSound,  getDefScoreSound,  xmlelement, mode);
     110        XMLPortParam(JumpPlatform, "defBatSound",  setDefBatSound,  getDefBatSound,  xmlelement, mode);
     111        XMLPortParam(JumpPlatform, "defBoundarySound",  setDefBoundarySound,  getDefBoundarySound,  xmlelement, mode);
     112    }
     113
     114    /**
     115    @brief
     116        Register variables to synchronize over the network.
     117    */
     118    void JumpPlatform::registerVariables()
     119    {
     120        registerVariable( this->fieldWidth_ );
     121        registerVariable( this->fieldHeight_ );
     122        registerVariable( this->relMercyOffset_ );
     123        registerVariable( this->batID_[0] );
     124        //registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<JumpPlatform>( this, &JumpPlatform::applyBats) );
     125    }
     126
     127    /**
     128    @brief
     129        Is called every tick.
     130        Handles the movement of the ball and its interaction with the boundaries and bats.
     131    @param dt
     132        The time since the last tick.
     133    */
    62134    void JumpPlatform::tick(float dt)
    63135    {
    64         //setAngularVelocity(getAngularVelocity() + Vector3(0.05,0,0));
    65         /*Vector3 movement(0,0,0);
    66         Vector3 shipPosition = getPosition();*/
    67 
    68 
    69 
    70136        SUPER(JumpPlatform, tick, dt);
    71     }
    72 
    73 
     137
     138        Vector3 platformPosition = this->getPosition();
     139        Vector3 platformVelocity = this->getVelocity();
     140
     141        if (figure_ != NULL)
     142        {
     143            Vector3 figurePosition = figure_->getPosition();
     144            Vector3 figureVelocity = figure_->getVelocity();
     145
     146            if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-10 && figurePosition.x < platformPosition.x+10 && figurePosition.z > platformPosition.z-4 && figurePosition.z < platformPosition.z+4)
     147            {
     148                figure_->JumpFromPlatform(200.0f);
     149            }
     150        }
     151
     152
     153
     154        /*
     155        // 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).
     156        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     157        {
     158            defBoundarySound_->play(); //play boundary sound
     159            // Its velocity in z-direction is inverted (i.e. it bounces off).
     160            velocity.z = -velocity.z;
     161            // And its position is set as to not overstep the boundary it has just crossed.
     162            if (position.z > this->fieldHeight_ / 2)
     163                position.z = this->fieldHeight_ / 2;
     164            if (position.z < -this->fieldHeight_ / 2)
     165                position.z = -this->fieldHeight_ / 2;
     166
     167            this->fireEvent();
     168        }
     169
     170        // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry).
     171        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     172        {
     173            float distance = 0;
     174
     175            if (this->bat_ != NULL) // If there are bats.
     176            {
     177                // If the right boundary has been crossed.
     178                if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)
     179                {
     180                    // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
     181                    distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     182                    if (fabs(distance) <= 1) // If the bat is there to parry.
     183                    {
     184                        defBatSound_->play(); //play bat sound
     185                        // Set the ball to be exactly at the boundary.
     186                        position.x = this->fieldWidth_ / 2;
     187                        // Invert its velocity in x-direction (i.e. it bounces off).
     188                        velocity.x = -velocity.x;
     189                        // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
     190                        velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
     191                        acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
     192
     193                        this->fireEvent();
     194                    }
     195                    // If the left player scores.
     196                    else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     197                    {
     198                        defScoreSound_->play();//play score sound
     199                        if (this->getGametype() && this->bat_[0])
     200                        {
     201                            this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     202                            return;
     203                        }
     204                    }
     205                }
     206                // If the left boundary has been crossed.
     207                else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)
     208                {
     209                    // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
     210                    distance = (position.z - this->figure_->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     211                    if (fabs(distance) <= 1) // If the bat is there to parry.
     212                    {
     213                        defBatSound_->play(); //play bat sound
     214                        // Set the ball to be exactly at the boundary.
     215                        position.x = -this->fieldWidth_ / 2;
     216                        // Invert its velocity in x-direction (i.e. it bounces off).
     217                        velocity.x = -velocity.x;
     218                        // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
     219                        velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
     220                        acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;
     221
     222                        this->fireEvent();
     223                    }
     224                    // If the right player scores.
     225                    else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     226                    {
     227                        defScoreSound_->play();//play score sound
     228                        if (this->getGametype() && this->bat_[1])
     229                        {
     230                            this->getGametype()->playerScored(this->bat_[1]->getPlayer());
     231                            return;
     232                        }
     233                    }
     234                }
     235            }
     236        }
     237        */
     238    }
     239
     240    /**
     241    @brief
     242        Set the bats for the ball.
     243    @param bats
     244        An array (of size 2) of weak pointers, to be set as the new bats.
     245    */
     246    void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure)
     247    {
     248        if (this->bDeleteBats_) // If there are already some bats, delete them.
     249        {
     250            delete this->figure_;
     251            this->bDeleteBats_ = false;
     252        }
     253
     254        this->figure_ = newFigure;
     255        // Also store their object IDs, for synchronization.
     256        this->batID_[0] = this->figure_->getObjectID();
     257    }
     258
     259    /**
     260    @brief
     261        Get the bats over the network.
     262    */
     263    void JumpPlatform::applyBats()
     264    {
     265        // Make space for the bats, if they don't exist, yet.
     266        if (this->figure_ == NULL)
     267        {
     268            this->figure_ = *(new WeakPtr<JumpFigure>);
     269            this->bDeleteBats_ = true;
     270        }
     271
     272        if (this->batID_[0] != OBJECTID_UNKNOWN)
     273        {
     274                // WAR IM PONG NICHT AUSKOMMENTIERT!!!
     275            //this->figure_ = orxonox_cast<JumpFigure>(Synchronisable::getSynchronisable(this->batID_[0]));
     276        }
     277    }
     278
     279    void JumpPlatform::setDefScoreSound(const std::string &jumpSound)
     280    {
     281        if( defScoreSound_ )
     282            defScoreSound_->setSource(jumpSound);
     283        else
     284            assert(0); // This should never happen, because soundpointer is only available on master
     285    }
     286
     287    const std::string& JumpPlatform::getDefScoreSound()
     288    {
     289        if( defScoreSound_ )
     290            return defScoreSound_->getSource();
     291        else
     292            assert(0);
     293        return BLANKSTRING;
     294    }
     295
     296    void JumpPlatform::setDefBatSound(const std::string &jumpSound)
     297    {
     298        if( defBatSound_ )
     299            defBatSound_->setSource(jumpSound);
     300        else
     301            assert(0); // This should never happen, because soundpointer is only available on master
     302    }
     303
     304    const std::string& JumpPlatform::getDefBatSound()
     305    {
     306        if( defBatSound_ )
     307            return defBatSound_->getSource();
     308        else
     309            assert(0);
     310        return BLANKSTRING;
     311    }
     312
     313    void JumpPlatform::setDefBoundarySound(const std::string &jumpSound)
     314    {
     315        if( defBoundarySound_ )
     316            defBoundarySound_->setSource(jumpSound);
     317        else
     318            assert(0); // This should never happen, because soundpointer is only available on master
     319    }
     320
     321    const std::string& JumpPlatform::getDefBoundarySound()
     322    {
     323        if( defBoundarySound_ )
     324            return defBoundarySound_->getSource();
     325        else
     326            assert(0);
     327        return BLANKSTRING;
     328    }
    74329}
  • code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h

    r10032 r10040  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    3030    @file JumpPlatform.h
    3131    @brief Declaration of the JumpPlatform class.
     32    @ingroup Jump
    3233*/
    3334
     
    3738#include "jump/JumpPrereqs.h"
    3839
    39 #include "worldentities/MobileEntity.h"
     40#include "util/Math.h"
     41
     42#include "worldentities/MovableEntity.h"
     43
    4044
    4145namespace orxonox
    4246{
    43     class _JumpExport JumpPlatform : public MobileEntity
     47
     48    /**
     49    @brief
     50        This class manages the ball for @ref orxonox::Jump "Jump".
     51
     52        It is responsible for both the movement of the ball in the x,z-plane as well as its interaction with the boundaries of the playing field (defined by the @ref orxonox::JumpCenterpoint "JumpCenterpoint") and the @ref orxonox::JumpFigure "JumpFigures". Or more precisely, it makes the ball bounce off then upper and lower delimiters of the playing field, it makes the ball bounce off the bats and also detects when a player scores and takes appropriate measures.
     53
     54    @author
     55        Fabian 'x3n' Landau
     56
     57    @ingroup Jump
     58    */
     59    class _JumpExport JumpPlatform : public MovableEntity
    4460    {
    4561        public:
    4662            JumpPlatform(Context* context);
     63            virtual ~JumpPlatform();
     64
    4765            virtual void tick(float dt);
    4866
    49         private:
    50             Model* model;
     67            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     68
     69            /**
     70            @brief Set the dimensions of the playing field.
     71            @param width The width of the playing field.
     72            @param height The height of the playing field.
     73            */
     74            void setFieldDimension(float width, float height)
     75                { this->fieldWidth_ = width; this->fieldHeight_ = height; }
     76            /**
     77            @brief Get the dimensions of the playing field.
     78            @param dimension A vector with the width as the first and height as the second component.
     79            */
     80            void setFieldDimension(const Vector2& dimension)
     81                { this->setFieldDimension(dimension.x, dimension.y); }
     82            /**
     83            @brief Get the dimensions of the playing field.
     84            @return Returns a vector with the width as the first and height as the second component.
     85            */
     86            Vector2 getFieldDimension() const
     87                { return Vector2(this->fieldWidth_, this->fieldHeight_); }
     88
     89
     90            void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball.
     91            void applyBats(); //!< Get the bats over the network.
     92
     93            static const float MAX_REL_Z_VELOCITY;
     94
     95            void setDefScoreSound(const std::string& engineSound);
     96            const std::string& getDefScoreSound();
     97            void setDefBatSound(const std::string& engineSound);
     98            const std::string& getDefBatSound();
     99            void setDefBoundarySound(const std::string& engineSound);
     100            const std::string& getDefBoundarySound();
     101
     102        protected:
     103            void registerVariables();
     104
     105            float fieldWidth_; //!< The width of the playing field.
     106            float fieldHeight_; //!< The height of the playing field.
     107            WeakPtr<JumpFigure> figure_; //!< An array with the two bats.
     108            bool bDeleteBats_; //!< Bool, to keep track, of whether this->bat_ exists or not.
     109            unsigned int* batID_; //!< The object IDs of the bats, to be able to synchronize them over the network.
     110            float relMercyOffset_; //!< Offset, that makes the player not loose, when, in all fairness, he would have.
     111            WorldSound* defScoreSound_;
     112            WorldSound* defBatSound_;
     113            WorldSound* defBoundarySound_;
    51114    };
    52115}
  • code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h

    r10032 r10040  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
     23 *      Reto Grieder
    2424 *   Co-authors:
    2525 *      ...
     
    3030@file
    3131@brief
    32     Shared library macros, enums, constants and forward declarations for the Invader module
     32    Shared library macros, enums, constants and forward declarations for the jump module
    3333*/
    3434
     
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(INVADER_STATIC_BUILD)
    46 #  ifdef INVADER_SHARED_BUILD
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(PONG_STATIC_BUILD)
     46#  ifdef PONG_SHARED_BUILD
    4747#    define _JumpExport __declspec(dllexport)
    4848#  else
     
    6969{
    7070    class Jump;
    71     class JumpCenterPoint;
    72     class JumpShip;
    7371    class JumpPlatform;
    74     class JumpEnemy;
    75     class JumpEnemyShooter;
    76     class JumpWeapon;
    77     class JumpWeaponEnemy;
    78     class JumpHUDinfo;
     72    class JumpPlatformHMove;
     73    class JumpFigure;
     74    class JumpCenterpoint;
     75    class JumpScore;
    7976}
    8077
Note: See TracChangeset for help on using the changeset viewer.