Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2017, 5:00:59 PM (8 years ago)
Author:
vyang
Message:

Asteroids2D erfolgreich als Minigame eingebunden, Dimensionen des Spielfeldes werden im CenterPoint gesetzt.

Location:
code/branches/Asteroid_HS17/src/modules/minigametest
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Asteroid_HS17/src/modules/minigametest/MiniGameTest.cc

    r11593 r11608  
    3434#include "MiniGameTest.h"
    3535#include "MiniGameTestShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
    36 #include "MiniGameTestCube.h"
    3736#include "core/CoreIncludes.h"
    3837#include "Highscore.h"
     
    5857        // spawn enemy every 3.5 seconds
    5958        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&MiniGameTest::spawnEnemy, this)));
    60         comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&MiniGameTest::comboControll, this)));
    6159        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    6260        this->center_ = nullptr;
    63 
    6461        this->setHUDTemplate("MiniGameTestHUD");
    6562    }
     
    9087    void MiniGameTest::tick(float dt)
    9188    {
    92         if (getPlayer() != nullptr)
    93         {
    94             currentPosition = getPlayer()->getWorldPosition().x;
    95             counter = counter + (currentPosition - lastPosition);
    96             lastPosition = currentPosition;
    97             point = (int) currentPosition;
    98             getPlayer()->speed = 830.0f - (point / 1000);
    99 
    100             for(unsigned int i=0; i < cubeList.size();i++)
    101             {
    102                 if(cubeList.at(i)->getPosition().x < currentPosition-3000)
    103                 {
    104                     cubeList.at(i)->destroy();
    105                     cubeList.erase(cubeList.begin()+i);
    106                 }
    107             }
    108 
    109             if(counter >= 3000)
    110             {
    111                 counter = 0;
    112                 for(int i = 0; i<6; i++)
    113                 {
    114                     MiniGameTestCube* cube = new MiniGameTestCube(this->center_->getContext());
    115                     cubeList.push_back(cube);
    116                     switch(pattern)
    117                     {
    118                     case 1: cube->addTemplate("MiniGameTestCube01");
    119                     break;
    120                     case 2: cube->addTemplate("MiniGameTestCube02");
    121                     break;
    122 
    123                     }
    124 
    125                     cube->setPosition(getPlayer()->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
    126                     //stEntity->setScale3D(50,50,50);
    127                 }
    128 
    129 
    130                 pattern %= 2;
    131                 pattern ++;
    132 
    133             }
    134 
    135         }
     89       
    13690        SUPER(MiniGameTest, tick, dt);
    13791    }
     
    155109    };
    156110
    157     void MiniGameTest::comboControll()
    158     {
    159         if (b_combo)
    160             multiplier++;
    161         // if no combo was performed before, reset multiplier
    162         else
    163             multiplier = 1;
    164         b_combo = false;
    165     }
    166 
    167111    void MiniGameTest::start()
    168112    {
    169113        orxout() << "start" << endl;
    170         for(unsigned int i=0; i< cubeList.size();i++)
    171         {
    172             cubeList.at(i)->destroy();
    173             cubeList.erase(cubeList.begin()+i);
    174114
    175         }
    176         cubeList.clear();
    177115        // Set variable to temporarily force the player to spawn.
    178116        this->bForceSpawn_ = false;
     
    194132            this->end();
    195133        }
    196 
    197         // Reset all the cubes
    198         /*
    199         orxout() << "prespawn" << endl;
    200         for(int i=0; i< cubeList.size();i++)
    201         {
    202             cubeList.at(i)->destroy();
    203             cubeList.erase(cubeList.begin()+i);
    204         }
    205         cubeList.clear();
    206         lives = 1;
    207         point = 0;
    208         lastPosition = 0;
    209         */
    210134    }
    211135
  • code/branches/Asteroid_HS17/src/modules/minigametest/MiniGameTest.h

    r11593 r11608  
    8787
    8888            // checks if multiplier should be reset.
    89             void comboControll();
    9089            void costLife();
    9190
  • code/branches/Asteroid_HS17/src/modules/minigametest/MiniGameTestShip.cc

    r11593 r11608  
    5555    void MiniGameTestShip::tick(float dt)
    5656    {
    57         Vector3 pos = getPosition();
    58 
    59         //Movement calculation
    60         lastTimeFront += dt * damping;
    61         lastTimeLeft += dt * damping;
    62         lastTime += dt;
    63 
    64         velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
    65         velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
    66 
    67         //Execute movement
    68         if (this->hasLocalController())
    69         {
    70             float dist_y = velocity.y * dt;
    71             //float dist_x = velocity.x * dt;
    72             if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
    73                 posforeward += dist_y;
    74             else
    75             {
    76                 velocity.y = 0;
    77                 // restart if game ended
    78 /*
    79                 if (getGame())
    80                     if (getGame()->bEndGame)
    81                     {
    82                         getGame()->start();
    83                         return;
    84                     }*/
    85             }
    86 
    87             pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
    88         }
    89 
    90 
    91         // Camera
    92         Camera* camera = this->getCamera();
    93         if (camera != nullptr)
    94         {
    95             // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
    96             camera->setOrientation(Vector3::UNIT_Z, Degree(0));
    97         }
    98 
    99 
    100 
    101         // bring back on track!
    102         if(pos.y != 0)
    103         {
    104             pos.y = 0;
    105         }
    106 
    107         setPosition(pos);
    108         setOrientation(Vector3::UNIT_Y, Degree(270));
    109 
    110         // Level up!
    111         if (pos.x > 42000)
    112         {
    113             updateLevel();
    114             setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
    115         }
    116 
    11757        SUPER(MiniGameTestShip, tick, dt);
    11858    }
     
    12565    }
    12666
    127     void MiniGameTestShip::moveFrontBack(const Vector2& value)
     67/*    void MiniGameTestShip::moveFrontBack(const Vector2& value)
    12868    {
    12969        //lastTimeFront = 0;
    13070        //desiredVelocity.y = value.y * speed * 42;
    131 
     71        orxout() << "FrontBack" << endl;
     72        SUPER(MiniGameTestShip, moveFrontBack, value);
    13273    }
    13374
    13475    void MiniGameTestShip::moveRightLeft(const Vector2& value)
    13576    {
    136         lastTimeLeft = 0;
    137         desiredVelocity.x = value.x * speed;
     77        //lastTimeLeft = 0;
     78        //desiredVelocity.x = value.x * speed;
     79        orxout() << "RightLeft" << endl;
     80        SUPER(MiniGameTestShip, moveFrontBack, value);       
    13881    }
     82 */
    13983    void MiniGameTestShip::boost(bool bBoost)
    14084    {
  • code/branches/Asteroid_HS17/src/modules/minigametest/MiniGameTestShip.h

    r11593 r11608  
    5555
    5656            // overwrite for 2d movement
    57             virtual void moveFrontBack(const Vector2& value) override;
    58             virtual void moveRightLeft(const Vector2& value) override;
     57            //virtual void moveFrontBack(const Vector2& value) override;
     58            //virtual void moveRightLeft(const Vector2& value) override;
    5959
    6060            // Starts or stops fireing
     
    8282            WeakPtr<MiniGameTest> game;
    8383            WeakPtr<WorldEntity> lastEntity;
    84             Camera* camera;
    8584            float lastTimeFront, lastTimeLeft, lastTime;
    8685            struct Velocity
Note: See TracChangeset for help on using the changeset viewer.