Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11516 for code/branches


Ignore:
Timestamp:
Oct 30, 2017, 4:04:29 PM (7 years ago)
Author:
vyang
Message:

Files hinzugefuegt, versucht Aehnlichkeiten mit anderen minigames (dodgerace, invader) zu finden. Testlevel noch zu bearbeiten. Gametype Asteroids crashed immer noch

Location:
code/branches/Asteroid_HS17
Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc

    r11506 r11516  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Florian Zinggeler
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file Invader.cc
     31    @brief Implementation of the Invader class.
     32*/
     33
    134#include "Asteroids.h"
     35#include "Highscore.h"
     36#include "core/CoreIncludes.h"
     37#include "core/EventIncludes.h"
     38#include "core/command/Executor.h"
     39#include "core/config/ConfigValueIncludes.h"
     40
     41#include "gamestates/GSLevel.h"
     42#include "chat/ChatManager.h"
     43
     44// ! HACK
     45#include "infos/PlayerInfo.h"
     46
     47#include "AsteroidsCenterPoint.h"
     48#include "AsteroidsShip.h"
     49
     50#include "core/command/ConsoleCommand.h"
     51#include "worldentities/ExplosionPart.h"
    252
    353namespace orxonox
    454{
    5         RegisterUnloadableClass(Asteroids);
     55    RegisterUnloadableClass(Asteroids);
    656
    7         Asteroids::Asteroids(Context* context) : Deathmatch(context)
    8         {
    9                 level = 1;
    10                 this->numberOfBots = 0;
    11         }
     57    Asteroids::Asteroids(Context* context) : Deathmatch(context)
     58    {
     59        RegisterObject(Asteroids);
     60        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
     61        this->center_ = nullptr;
     62        bEndGame = false;
     63        lives = 3;
     64        point = 0;
    1265
    13         void Asteroids::spawnAsteroid();
     66    }
    1467
    15         void Asteroids::setCenterpoint(InvaderCenterPoint* center)
     68
     69    AsteroidsShip* Asteroids::getPlayer()
     70    {
     71        if (player == nullptr)
     72        {
     73            for (Asteroids* ship : ObjectList<AsteroidsShip>())
     74                player = ship;
     75        }
     76        return player;
     77    }
     78
     79
     80    void Asteroids::setCenterpoint(AsteroidsCenterPoint* center)
    1681    {
    1782        this->center_ = center;
    1883    }
    1984
    20     void Asteroids::start();
    21     void Asteroids::end();
    22    
     85    void Asteroids::costLife()
     86    {
     87        lives = 0;
     88    };
     89
     90    void Asteroids::start()
     91    {
     92        // Set variable to temporarily force the player to spawn.
     93        this->bForceSpawn_ = true;
     94
     95        if (this->center_ == nullptr)  // abandon mission!
     96        {
     97            orxout(internal_error) << "Invader: No Centerpoint specified." << endl;
     98            GSLevel::startMainMenu();
     99            return;
     100        }
     101        // Call start for the parent class.
     102        Deathmatch::start();
     103    }
     104
     105    void Asteroids::addPoints(int numPoints)
     106    {
     107        if (!bEndGame)
     108        {
     109            point += numPoints;
     110        }
     111    }
     112
     113    void Asteroids::end()
     114    {
     115        // DON'T CALL THIS!
     116        //      Deathmatch::end();
     117        // It will misteriously crash the game!
     118        // Instead startMainMenu, this won't crash.
     119        GSLevel::startMainMenu();
     120    }
    23121}
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h

    r11506 r11516  
    3333*/
    3434
    35 #ifndef _Invader_H__
    36 #define _Invader_H__
     35#ifndef _Asteroids_H__
     36#define _Asteroids_H__
    3737
    38 #include "invader/InvaderPrereqs.h"
    39 
     38#include "asteroids/AsteroidsPrereqs.h"
    4039#include "gametypes/Deathmatch.h"
    4140#include "tools/Timer.h"
     
    4443{
    4544
    46     class _InvaderExport Invader : public Deathmatch
     45    class _AsteroidsExport Asteroids : public Deathmatch
    4746    {
    4847        public:
    49             Invader(Context* context);
     48            Asteroids(Context* context);
    5049
    5150            virtual void start() override;
    5251            virtual void end() override;
     52            virtual void tick(float dt) override;
    5353            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    5454
    55             void spawnEnemy();
    56 
    57             void setCenterpoint(InvaderCenterPoint* center);
     55            void setCenterpoint(AsteroidsCenterPoint* center);
    5856
    5957            int getLives(){return this->lives;}
    60             int getLevel(){return this->level;}
    6158            int getPoints(){return this->point;}
    62             int getMultiplier(){return this->multiplier;}
     59           
     60            void costLife();
     61            void addPoints(int numPoints);
    6362
    64             void costLife();
    65             void levelUp();
    66             void addPoints(int numPoints);
    67             // checks if multiplier should be reset.
    68             void comboControll();
    6963            int lives;
    70             int multiplier;
    7164            bool bEndGame;
    72             bool bShowLevel;
     65           
    7366        private:
    7467            void toggleShowLevel(){bShowLevel = !bShowLevel;}
    75             InvaderShip* getPlayer();
    76             WeakPtr<InvaderCenterPoint> center_;
    77             WeakPtr<InvaderShip> player;
     68            AsteroidsShip* getPlayer();
     69            WeakPtr<AsteroidsCenterPoint> center_;
     70            WeakPtr<AsteroidsShip> player;
     71            WeakPtr<Camera> camera;
    7872
    7973            Timer enemySpawnTimer;
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc

    r11506 r11516  
    33#include "core/CoreIncludes.h"
    44#include "core/XMLPort.h"
    5 #include "Invader.h"
    6 #include "InvaderEnemy.h"
     5#include "Asteroids.h"
    76#include "graphics/Camera.h"
     7#include "asteroids/AsteroidStone"
    88#include "weapons/projectiles/Projectile.h"
     9
    910
    1011namespace orxonox
     
    1617    {
    1718        RegisterObject(AsteroidsShip);
     19        /*radius = 20;
     20        x = getPosition().x;
     21        y = getPosition().y;
     22        dx = 3.0f;
     23        dy = 3.0f;
     24        angle= 0.0f;*/
    1825
    19         float x = getPosition().x;
    20         float y = getPosition().y;
    21         float velocityx = 0.0f;
    22         float velocityy = 0.0f;
    23         this->bBoost_ = false;
     26        speed = 830;
     27        isFireing = false;
     28        damping = 10;
     29
     30        lastTimeFront = 0;
     31        lastTimeLeft = 0;
     32        lastTime = 0;
     33
    2434    }
     35
    2536    //Destructor
    2637    AsteroidsShip::~AsteroidsShip()
     
    3546    void AsteroidsShip::tick(float dt)
    3647    {
    37         //Movement computation
    38         Vector3 speed = Vector3 (100, 100, 0);
    39         Vector3 position = this->getPosition();
    40         position += (speed * dt);
    41         this->setPosition(position);
     48        /*Movement computation
     49        Vector3 pos = getPosition();
     50
     51        dx *= damping;
     52        dy *= damping;
     53
     54        float speed = sqrt(dx*dx+ dy*dy);
     55        if(speed > maxspeed)
     56        {
     57            dx *= maxspeed/speed;
     58            dy *= mayspeed/speed;
     59        }
     60
     61        x += dx;
     62        y += dy;
     63
     64        if(x>W) x=0;
     65        if(x<0) x=W;
     66        if(y>H) y=0;
     67        if(y<0) y=H;
     68        setPosition(x,y,0);
     69
    4270        //roll? muss sich das Raumschiff drehen?
     71        setOrientation(angle, x, y, 0);
    4372
    4473        //Schiessen wenn geschossen wurde
     
    4776            ControllableEntity::fire(0);
    4877       
    49         //Leben verloren
     78        //Leben verloren */
     79        Vector3 pos = getPosition();
     80
     81        //Movement calculation
     82        lastTimeFront += dt * damping;
     83        lastTimeLeft += dt * damping;
     84        lastTime += dt;
     85
     86        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
     87        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
     88
     89        //Execute movement
     90        if (this->hasLocalController())
     91        {
     92            float dist_y = velocity.y * dt;
     93            //float dist_x = velocity.x * dt;
     94            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
     95                posforeward += dist_y;
     96            else
     97            {
     98                velocity.y = 0;
     99                // restart if game ended
     100/*
     101                if (getGame())
     102                    if (getGame()->bEndGame)
     103                    {
     104                        getGame()->start();
     105                        return;
     106                    }*/
     107            }
     108
     109            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
     110        }
     111
     112
     113        // Camera
     114        Camera* camera = this->getCamera();
     115        if (camera != nullptr)
     116        {
     117            // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
     118            camera->setOrientation(Vector3::UNIT_Z, Degree(0));
     119        }
     120
     121
     122
     123        // bring back on track!
     124        if(pos.y != 0)
     125        {
     126            pos.y = 0;
     127        }
     128
     129        setPosition(pos);
     130        setOrientation(Vector3::UNIT_Y, Degree(270));
     131
     132        SUPER(AsteroidsShip, tick, dt);
    50133    }
    51134   
    52     void
     135    Asteroids* AsteroidsShip::getGame()
     136    {
     137        if (game == nullptr)
     138        {
     139            for (Asteroids* asteroids : ObjectList<Asteroids>())
     140                game = asteroids;
     141        }
     142        return game;
     143    }
    53144
     145    void InvaderShip::death()
     146    {
     147        getGame()->costLife();
     148        SpaceShip::death();
     149    }
    54150
    55151
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h

    r11506 r11516  
    3333*/
    3434
    35 #ifndef _DodgeRace_H__
    36 #define _DodgeRace_H__
    37 
    38 #include "dodgerace/DodgeRacePrereqs.h"
    39 
    40 #include "DodgeRaceCenterPoint.h" // Necessary for WeakPointer??
    41 //#include "DodgeRaceShip.h"        DO NOT include in Header. Will cause forward declaration issues
    42 
    43 //#include "DodgeRaceHUDinfo.h"
     35#ifndef _Asteroids_H__
     36#define _Asteroids_H__
    4437
    4538
    46 #include "core/EventIncludes.h"
    47 #include "core/command/Executor.h"
    48 #include "core/config/ConfigValueIncludes.h"
    49 
    50 #include "gamestates/GSLevel.h"
    51 #include "chat/ChatManager.h"
    52 #include <vector>
    53 
    54 // ! HACK
    55 #include "infos/PlayerInfo.h"
    56 
    57 #include "core/command/ConsoleCommand.h"
    58 
     39#include "asteroids/AsteroidsPrereqs.h"
    5940#include "gametypes/Deathmatch.h"
    60 #include "tools/Timer.h"
     41#include "worldentities/pawns/SpaceShip.h"
     42#include "weapons/projectiles/Projectile.h"
     43#include <math.h>
    6144
    6245namespace orxonox
    6346{
    6447
    65     class _DodgeRaceExport DodgeRace : public Deathmatch
     48    class _AsteroidsExport Asteroids : public SpaceShip
    6649    {
    6750       public:
    68             DodgeRace(Context* context);
    69 
    70             virtual void start() override;
    71             virtual void end() override;
     51            Asteroids(Context* context);
    7252
    7353            virtual void tick(float dt) override;
    7454
    75             virtual void playerPreSpawn(PlayerInfo* player) override;
     55            // overwrite for 2d movement
     56            virtual void moveFrontBack(const Vector2& value) override;
     57            virtual void moveRightLeft(const Vector2& value) override;
    7658
    77             void levelUp();
     59            // Starts or stops fireing
     60            virtual void boost(bool bBoost) override;
    7861
    79             int getLives(){return this->lives;}
    80             int getLevel(){return this->level;}
    81             int getPoints(){return this->point;}
    82             int getMultiplier(){return this->multiplier;}
    8362
    8463            void setCenterpoint(DodgeRaceCenterPoint* center)
     
    8665            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    8766
    88             // checks if multiplier should be reset.
    89             void comboControll();
    90             void costLife();
    91 
    9267            bool bEndGame;
    9368            bool bShowLevel;
    9469            int lives;
    95             int multiplier;
    96             float counter;
    97             int pattern;
    98             float currentPosition;
    99             float lastPosition;
     70            float angle, radius;
     71            float speed, damping, posforeward;
     72            bool isFireing;
     73
     74            //Nachschauen wie gross das Spielfeld ist!
     75            float H = 1000;
     76            float W = 1000;
     77
     78        protected:
     79            virtual void death() override;
    10080
    10181       private:
    102             Timer endGameTimer;
    103 
    104             DodgeRaceShip* getPlayer();
    105             WeakPtr<DodgeRaceShip> player;
    106             std::vector<DodgeRaceCube*> cubeList;
    107             void toggleShowLevel(){bShowLevel = !bShowLevel;}
    108             void addPoints(int numPoints);
    109 
    110             WeakPtr<DodgeRaceCenterPoint> center_;
    111             int level;
    112             int point;
    113             bool b_combo;
    114 
    115             Timer enemySpawnTimer;
    116             Timer comboTimer;
    117             Timer showLevelTimer;
    118 
    119 
    120          /*
    121 
    122             //void spawnEnemy();
    123 
    124 
    125 
    126 
    127 
    128 
    129 
    130 
    131 
    132 
    133 
    134 
    135         private:
    136 
    137 
    138 
    139 
    140             //Context* context;
    141             */
     82            Asteroids* getGame();
     83            WeakPtr<Asteroids> game;
     84            WeakPtr<WorldEntity> lastEntity;
     85            Camera* camera;
     86            float lastTimeFront, lastTimeLeft, lastTime;
     87            struct Velocity
     88            {
     89                float x;
     90                float y;
     91            } velocity, desiredVelocity;
     92           
    14293    };
    14394}
    14495
    145 #endif /* _DodgeRace_H__ */
     96#endif /* _Asteroids_H__ */
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc

    r11506 r11516  
    3232*/
    3333
    34 #include "InvaderEnemy.h"
    35 
     34#include "AsteroidsStone.h"
    3635#include "core/CoreIncludes.h"
    37 #include "Invader.h"
    38 #include "InvaderShip.h"
     36#include "Asteroids.h"
     37#include "AsteroidsShip.h"
     38#include <cmath>
     39#include "util/Math.h"
    3940
    4041namespace orxonox
    4142{
    42     RegisterClass(InvaderEnemy);
     43    RegisterClass(AsteroidsStone);
    4344
    44     InvaderEnemy::InvaderEnemy(Context* context) : Pawn(context)
     45    AsteroidsStone::AsteroidsStone(Context* context) : MovableEntity(context)
    4546    {
    46         RegisterObject(InvaderEnemy);
    47         enableCollisionCallback();
    48         lifetime = 0;
     47        RegisterObject(AsteroidsStone);
     48
     49        maxspeed = 50.0f;
     50        //Random Spawn? pos= random?
     51        this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0);
     52                if(r){
     53                        this.r = r*0.5;
     54                }else{
     55                        this.r = rnd(15, 50);
     56                }
     57
     58                //random Geschwindigkeit und Richtung
     59                velocity.x = rnd(0, maxspeed);
     60                velocity.y = rnd(0, maxspeed);
     61    }
     62//Bis hier geschrieben
     63    void AsteroidsStone::tick(float dt)
     64    {
     65        Vector3 pos = this->getPosition();
     66        pos.x += velocity.x*dt;
     67        pos.y += velocity.y*dt;
     68        setPosition(pos);
     69        SUPER(AsteroidsStone, tick, dt);
    4970    }
    5071
    51     void InvaderEnemy::tick(float dt)
    52     {
    53         lifetime += dt;
    54         // die after 5 seconds.
    55         if (lifetime > 5000)
    56             removeHealth(2000);
    57 
    58         if (player != nullptr)
    59         {
    60             float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * (player->getPosition().z - getPosition().z);
    61             setVelocity(Vector3(1000.f - level * 100 , 0, newZ));
    62         }
    63         SUPER(InvaderEnemy, tick, dt);
    64     }
    65 
    66     inline bool InvaderEnemy::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
     72    inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    6773    {
    6874        if(orxonox_cast<InvaderShip*>(otherObject))
     
    7177    }
    7278
    73     Invader* InvaderEnemy::getGame()
    74     {
    75         if (game == nullptr)
    76         {
    77             for (Invader* invader : ObjectList<Invader>())
    78                 game = invader;
    79         }
    80         return game;
    81     }
    8279
    83     void InvaderEnemy::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    84     {
    85         Pawn::damage(damage, healthdamage, shielddamage, originator, cs);
    86         if (getGame() && orxonox_cast<InvaderShip*>(originator) != nullptr && getHealth() <= 0)
    87             getGame()->addPoints(42);
    88     }
    8980}
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h

    r11506 r11516  
    3232*/
    3333
    34 #ifndef _InvaderEnemy_H__
    35 #define _InvaderEnemy_H__
     34#ifndef _AsteroidsStone_H__
     35#define _AsteroidsStone_H__
    3636
    37 #include "invader/InvaderPrereqs.h"
     37#include "asteroids/AsteroidsPrereqs.h"
    3838
    39 #include "worldentities/pawns/Pawn.h"
     39#include "worldentities/MovableEntity.h"
    4040
    4141namespace orxonox
    4242{
    43     class _InvaderExport InvaderEnemy : public Pawn
     43    class _AsteroidsExport AsteroidsStone : public MovableEntity
    4444    {
    4545        public:
    46             InvaderEnemy(Context* context);
     46            AsteroidsStone(Context* context);
     47            virtual void tick(float dt) override;
    4748
    48             virtual void tick(float dt) override;
    49             virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
    50             virtual void damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) override;
    51             virtual void setInvaderPlayer(InvaderShip* player){this->player = player;}
    52 
     49            float r;
    5350            int level;
    5451        protected:
    55             Invader* getGame();
    56             WeakPtr<Invader> game;
    57             WeakPtr<InvaderShip> player;
    58             Camera* camera;
    59             bool isFireing;
    60             float speed, damping;
    61             float lastTimeFront, lastTimeLeft;
    62             float lifetime;
    63             struct Velocity
    64             {
    65                 float x;
    66                 float y;
    67             } velocity, desiredVelocity;
     52            float fieldWidth_;
     53            float fieldHeight_;
     54            Vector2 velocity;
     55            float maxspeed;
     56
     57
    6858
    6959    };
  • code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt

    r11506 r11516  
    1 SET_SOURCE_FILES(Invader_SRC_FILES
    2 BUILD_UNIT InvaderBuildUnit.cc
    3   Invader.cc
    4   InvaderCenterPoint.cc
     1SET_SOURCE_FILES(ASTEROIDS_SRC_FILES
     2BUILD_UNIT AsteroidsBuildUnit.cc
     3  Asteroids.cc
     4  AsteroidsCenterPoint.cc
    55  InvaderShip.cc
    6   InvaderEnemy.cc
    7   InvaderEnemyShooter.cc
    8   InvaderWeapon.cc
    9   InvaderWeaponEnemy.cc
    10   InvaderHUDinfo.cc
     6  AsteroidsStone.cc
     7  AsteroidsWeapon.cc
    118END_BUILD_UNIT
    129)
    1310
    14 ORXONOX_ADD_LIBRARY(invader
     11ORXONOX_ADD_LIBRARY(asteroids
    1512  PLUGIN
    1613  FIND_HEADER_FILES
     
    1916    overlays
    2017    weapons
    21   SOURCE_FILES ${Invader_SRC_FILES}
     18  SOURCE_FILES ${ASTEROIDS_SRC_FILES}
    2219)
Note: See TracChangeset for help on using the changeset viewer.