Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11529


Ignore:
Timestamp:
Nov 6, 2017, 12:52:38 PM (6 years ago)
Author:
pascscha
Message:

Asteroid Clusters

Location:
code/branches/FlappyOrx_HS17
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FlappyOrx_HS17/data/levels/FlappyOrx.oxw

    r11521 r11529  
    4848    <FlappyOrxCenterPoint name=flappyorxcenter />
    4949   
     50
     51
     52    <?lua
     53      for i = 1, 6, 1 do
     54        for j = 3, 12,3 do
     55    ?>
     56
     57    <Template name=Asteroid<?lua print(j) ?>_<?lua print(i) ?>>
     58      <MovableEntity
     59        collisionType = dynamic
     60        linearDamping = 0.8
     61        angularDamping = 0
     62        scale = "<?lua print(j) ?>"
     63        collisiondamage = 10000
     64        enablecollisiondamage = true
     65      >
     66     
     67        <attached>
     68          <Model mass="1000" mesh="ast<?lua print(i) ?>.mesh" />
     69        </attached>
     70        <collisionShapes>
     71          <SphereCollisionShape radius="<?lua print(j) ?>" />
     72        </collisionShapes>
     73      </MovableEntity>
     74    </Template>
     75
     76    <?lua
     77        end
     78      end
     79    ?>
     80
     81    <!--
    5082     <?lua
    5183      for i = 1, 30, 1 do
     
    92124      end
    93125    ?>
     126  -->
     127   
     128   
    94129  </Scene>
    95130</Level>
    96 
  • code/branches/FlappyOrx_HS17/data/levels/templates/spaceshipFlappyOrx.oxt

    r11514 r11529  
    4343    speed = 100
    4444    UpwardThrust = 200
    45     gravity = 18
     45    gravity = 500
    4646  >
    4747    <engines>
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/CMakeLists.txt

    r11503 r11529  
    77  FlappyOrxWeaponEnemy.cc
    88  FlappyOrxHUDinfo.cc
     9  FlappyOrxAsteroid.cc
    910END_BUILD_UNIT
    1011)
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc

    r11521 r11529  
    4747#include "FlappyOrxCenterPoint.h"
    4848#include "FlappyOrxShip.h"
     49#include "FlappyOrxAsteroid.h"
    4950
    5051#include "core/command/ConsoleCommand.h"
     
    6768        multiplier = 1;
    6869        b_combo = false;
    69        
     70        this->spawnDistance=300;
     71        this->tubeOffsetX=500;
    7072        this->setHUDTemplate("FlappyOrxHUD");
    7173    }
    7274
     75    void FlappyOrx::updatePlayerPos(int x){
     76        if(this->tubes.size()==0||x-this->tubes.back()-tubeOffsetX>spawnDistance){
     77            spawnTube();
     78            this->tubes.push(x+tubeOffsetX);
     79        }
     80        if(this->tubes.size()!=0&&x>this->tubes.front()){
     81            this->tubes.pop();
     82            levelUp();
     83        }
     84    }
     85
    7386    void FlappyOrx::levelUp()
    7487    {
    7588        level++;
    76         if (getPlayer() != nullptr)
    77         {
    78             for (int i = 0; i < 7; i++)
    79             {
    80 
    81                 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
    82                 chunk5->setPosition(this->center_->getPosition());
    83                 chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
    84                 chunk5->setScale(10);
    85                 chunk5->setEffect1("Orxonox/explosion2b");
    86                 chunk5->setEffect2("Orxonox/smoke6");
    87                 chunk5->setMinSpeed(0);
    88                 chunk5->setMaxSpeed(0);
    89                 chunk5->Explode();
    90 
    91             }
    92         }
    93         addPoints(multiplier * 42);
    94         multiplier *= 2;
    95         toggleShowLevel();
    96         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
     89        //toggleShowLevel();
     90        //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
    9791    }
    9892
     
    108102    }
    109103
    110 
     104    void FlappyOrx::spawnTube()
     105    {
     106        int space = 90;
     107        int height = (float(rand())/RAND_MAX-0.5)*(280-space);
     108           
     109        if (getPlayer() == nullptr)
     110            return;
     111
     112        Vector3 pos = player->getPosition();
     113
     114        asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);
     115        asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8);   
     116    }
     117
     118    void FlappyOrx::asteroidField(int x, int y, float slope){
     119        int r = 20;
     120        int noadd = 0;
     121
     122        ClearAsteroids();
     123        Circle newAsteroid = Circle();
     124        while(r>0){
     125            if(slope>0)
     126                newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;
     127            else
     128                newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;
     129           
     130            newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope;
     131            newAsteroid.r=r;
     132           
     133            int i = addIfPossible(newAsteroid);
     134            if(i==0)
     135                noadd++;
     136            else if(i==2)
     137                r=0;
     138            if(noadd>=5){
     139                noadd=0;
     140                r-=5;
     141            }
     142        }
     143    }
     144
     145    void FlappyOrx::createAsteroid(Circle &c){
     146        orxout() << "created Asteroid at x="<<c.x<<" y="<<c.y << std::endl;
     147        MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
     148        if(c.r<=5)
     149            newAsteroid->addTemplate(Asteroid5[rand()%6]);
     150        else if(c.r<=10)
     151            newAsteroid->addTemplate(Asteroid10[rand()%6]);
     152        else if(c.r<=15)
     153            newAsteroid->addTemplate(Asteroid15[rand()%6]);
     154        else
     155            newAsteroid->addTemplate(Asteroid20[rand()%6]);
     156       
     157        newAsteroid->setPosition(Vector3(c.x, 0, c.y));
     158        newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360));
     159        newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
     160
     161    }
    111162
    112163    void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center)
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h

    r11503 r11529  
    4141#include "tools/Timer.h"
    4242
     43
    4344namespace orxonox
    4445{
     46
     47    struct Circle{
     48        int r;
     49        int x;
     50        int y;
     51        Circle(int new_r, int new_x, int new_y){
     52            r=new_r;
     53            x=new_x;
     54            y=new_y;
     55        }
     56        Circle(){
     57            r=0;
     58            x=0;
     59            y=0;
     60        }
     61    };
    4562
    4663    class _FlappyOrxExport FlappyOrx : public Deathmatch
     
    5370            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    5471
    55             void spawnEnemy();
    56 
     72            void updatePlayerPos(int x);
     73            void createAsteroid(Circle &c);
     74            void asteroidField(int x, int y, float slope);
     75            void spawnTube();
     76           
    5777            void setCenterpoint(FlappyOrxCenterPoint* center);
    5878
     
    7191            bool bEndGame;
    7292            bool bShowLevel;
     93            std::queue<int> tubes;
     94            int spawnDistance;
     95            int tubeOffsetX;
    7396        private:
    7497            void toggleShowLevel(){bShowLevel = !bShowLevel;}
     98
     99            const static int nAst = 7;
     100            Circle Asteroids[nAst];
     101
     102            void ClearAsteroids(){
     103                for(int i = 0; i<this->nAst; i++){
     104                    Asteroids[i].r=0;
     105                }
     106            }
     107
     108           
     109            bool Collision(Circle &c1, Circle &c2){
     110                if(c1.r==0 || c2.r==0)
     111                    return false;
     112                int x = c1.x - c2.x;
     113                int y = c1.y - c2.y;
     114                int r = c1.r + c2.r;
     115
     116                return x*x+y*y<r*r*1.5;
     117            }
     118
     119            int addIfPossible(Circle c){
     120                int i;
     121                for(i=0; i<this->nAst && this->Asteroids[i].r!=0;i++){
     122                    if(Collision(c,this->Asteroids[i])){
     123                        return 0;
     124                    }
     125                }
     126                if(i==nAst)
     127                    return 2;
     128                this->Asteroids[i].x=c.x;
     129                this->Asteroids[i].y=c.y;
     130                this->Asteroids[i].r=c.r;
     131                createAsteroid(c);
     132                return 1;
     133            }
     134           
     135           
     136
    75137            FlappyOrxShip* getPlayer();
    76138            WeakPtr<FlappyOrxCenterPoint> center_;
     
    84146            int point;
    85147            bool b_combo;
     148            std::string Asteroid5[6] = {"Asteroid3_1","Asteroid3_2","Asteroid3_3","Asteroid3_4","Asteroid3_5","Asteroid3_6"};
     149            std::string Asteroid10[6] = {"Asteroid6_1","Asteroid6_2","Asteroid6_3","Asteroid6_4","Asteroid6_5","Asteroid6_6"};
     150            std::string Asteroid15[6] = {"Asteroid9_1","Asteroid9_2","Asteroid9_3","Asteroid9_4","Asteroid9_5","Asteroid9_6"};
     151            std::string Asteroid20[6] = {"Asteroid12_1","Asteroid12_2","Asteroid12_3","Asteroid12_4","Asteroid12_5","Asteroid12_6"};
     152
     153
     154
    86155    };
    87156}
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc

    r11521 r11529  
    7373            }
    7474            Vector3 pos = getPosition();
    75             velocity.y += gravity;
     75
     76            getGame()->updatePlayerPos(pos.x);
     77           
     78
     79            velocity.y += gravity*dt;
    7680            if(isFlapping){
    7781                isFlapping = false;
    78                 velocity.y = -UpwardThrust;
     82                if(pos.z > -150)
     83                    velocity.y = -UpwardThrust;
    7984            }
    8085
    8186            pos += Vector3(speed + velocity.x, 0, velocity.y) * dt;
    8287           
    83             if(pos.z < -150 || pos.z > 150){
     88            if(pos.z > 150){
    8489                pos.z=0;
    8590                velocity.y = 0;
     
    9499                }
    95100           
     101           
    96102            // Camera
    97103            Camera* camera = this->getCamera();
     
    102108            }
    103109
     110           
    104111            setPosition(pos);
    105112            setOrientation(Vector3::UNIT_Y, Degree(270));
Note: See TracChangeset for help on using the changeset viewer.