Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11555


Ignore:
Timestamp:
Nov 13, 2017, 4:05:34 PM (6 years ago)
Author:
vyang
Message:

Level file: korrekte Kameraposition, Raumschiff bewegt sich nicht, schiesst aber → wird AsteroidsShip ueberhaupt geladen? AsteroidsShip: neue Steuerung (vgl Jump, Rotation muss noch angepasst werden)

Location:
code/branches/Asteroid_HS17
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Asteroid_HS17/data/levels/Asteroids.oxw

    r11541 r11555  
    77
    88
     9<!--wird immer gebraucht-->
    910<?lua
    1011  include("stats.oxo")
     
    1213?>
    1314
     15
    1416<?lua
    15   include("templates/spaceshipAssff2.oxt")
    16   include("templates/spaceshipPirate.oxt")
    1717  include("templates/spaceshipAsteroids.oxt")
    18   include("overlays/InvaderHUD.oxo")
    1918?>
    2019
    21 <Template name=asteroidsshipcamera defaults=0>
    22   <AsteroidsShip>
    23     <camerapositions>
    24       <CameraPosition position="55,75,200" absolute=true />
    25       <!--CameraPosition position="0,50,160" drag=true mouselook=true />
    26       <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true /-->
    27     </camerapositions>
    28   </AsteroidsShip>
    29 </Template>
    30 
    31 <Template name=asteroidsship>
    32   <AsteroidsShip camerapositiontemplate=asteroidsshipcamera>
    33   </AsteroidsShip>
    34 </Template>
     20<!--Templates schreiben oder von spaceship kopieren-->
    3521
    3622<Level
    37   plugins = asteroids
     23  plugin = asteroids
    3824  gametype = Asteroids
    3925>
     
    4430
    4531    <!-- ambientlight = "0.8, 0.8, 0.8"
    46     skybox       = "Orxonox/Starbox" -->
     32    skybox       = "Orxonox/Starbox"
     33    WorldRange lieber im src einschraenken-->
    4734  <Scene
    4835    ambientlight = "0.8, 0.7, 0.4"
    4936    skybox     = "Orxonox/skyBoxBasic"
     37    negativeWorldRange = "-100000, -100000, -100000"
     38    positiveWorldRange = " 100000,  100000,  100000"
    5039  >
     40 
     41  <WorldAmbientSound
     42    source="Earth.ogg"
     43    looping="true"
     44    playOnLoad="true"
     45  />
    5146
    5247    <!-- <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> -->
    5348    <Light type=directional position="1100, 11000, -7000" lookat="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    54     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=AsteroidsShip pawndesign=asteroidsship />
     49
     50    <SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass=AsteroidsShip pawndesign=spaceshipasteroids/>
    5551
    5652    <DistanceTrigger name="start" position="-200,0,0" target="Pawn" distance=10 stayActive="true" delay=0 />
    5753
     54    <AsteroidsCenterPoint name=asteroidscenter />
    5855
    59     <AsteroidsCenterPoint name=asteroidscenter />
     56    <Model mesh="axes.mesh" scale=10 position="0,0,-100" />
    6057   
    6158   
  • code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids.oxt

    r11541 r11555  
    1 <Template name=spaceshipescort>
     1<Template name=spaceshipasteroids>
    22  <SpaceShip
    33   hudtemplate            = spaceshiphud
     
    7777  <SpaceShip>
    7878    <camerapositions>
    79       <CameraPosition position="0,150,0" pitch=-90 absolute=true />
     79      <CameraPosition position="0,300,0" pitch=-90 absolute=true />
    8080      <CameraPosition position="0,50,160" drag=true mouselook=true />
    8181      <CameraPosition position="0,40,125" drag=true mouselook=true />
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc

    r11541 r11555  
    6060        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    6161        this->center_ = nullptr;
     62        this->lives = 3;
    6263        bEndGame = false;
    6364        lives = 3;
     
    6566
    6667        // Pre-set the timer, but don't start it yet.
    67         this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
     68        //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
    6869    }
    6970
     
    7980    }
    8081
    81     /**
    82     @brief
    83         Destructor. Cleans up, if initialized.
    84     */
    85     Asteroids::~Asteroids()
     82    void Asteroids::spawnStone(int newsize)
    8683    {
    87         if (this->isInitialized())
    88             this->cleanup();
    89     }
     84        //no player -> should end game?
     85        if(getPlayer() == nullptr) return;
     86        //invalid size
     87        if(newsize > 3 || newsize < 1) return;
     88        AsteroidsStone* newStone;
     89        newStone = new AsteroidsStone(this->center_->getContext());
     90        newStone.size = newsize;
     91        if(newsize == 1) newStone->addTemplate("asteroidsstone1");
     92        else if(newsize == 2) newStone->addTemplate("asteroidsstone2");
     93        else newStone->addTemplate("asteroidsstone3");
     94        newStone->setAsteroidsPlayer(player);
    9095
    91     /**
    92     @brief
    93         Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids.
    94     */
    95     void Asteroids::cleanup()
    96     {
    97         if (this->stones_ != nullptr) // Destroy the ball, if present.
    98         {
    99             this->stones_->destroy();
    100             this->stones_ = nullptr;
    101         }
    102 
    103         // Destroy AsteroidsShip
    104 
    105         if (this->player != nullptr)
    106         {
    107             this->player->destroy();
    108             this->player = nullptr;
    109         }
    11096    }
    11197
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h

    r11528 r11555  
    6767           
    6868        private:
    69             void toggleShowLevel(){bShowLevel = !bShowLevel;}
    70             void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    7169            AsteroidsShip* getPlayer();
    7270            WeakPtr<AsteroidsCenterPoint> center_;
     
    7573            WeakPtr<AsteroidsStones> stones_;
    7674
    77             Timer enemySpawnTimer;
     75
    7876            //Context* context;
    79             int level;
     77            int lives;
    8078            int point;
    81             bool b_combo;
    8279
    8380            Timer starttimer_; //!< A timer to delay the start of the game.
     81            Timer enemySpawnTimer;
    8482    };
    8583}
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc

    r11541 r11555  
    1919        RegisterObject(AsteroidsShip);
    2020
    21         angle= 0.0f;
    22 
    23 
     21        direction= 0.0f;
    2422
    2523        isFireing = false;
     
    3028        lastTime = 0;
    3129
    32         height = this->getGame()->center_->getFieldHeight();
    33         width = this->getGame()->center_->getFieldWidth();
    34 
    35         force.x =0;
    36         force.y =0;
    37 
    38         velocity.x = 0;
    39         velocity.y = 0;
    40 
     30        height = 600;
     31        width = 1000;
    4132    }
    42 
    43     //Destructor
    44     AsteroidsShip::~AsteroidsShip()
    45     {
    46         if (this->isInitialized())
    47             this->cleanup();
    48     }
    49 
    5033
    5134
     
    5336    void AsteroidsShip::tick(float dt)
    5437    {
     38        orxout() << "ich ticke!"<< endl;
     39        SUPER(AsteroidsShip, tick, dt);
     40
    5541        //Movement computation beachte Beschleunigung?
    5642        Vector3 pos = getPosition();
     43        Vector3 vel = getVelocity();
    5744
    58         float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y);
     45        float speed = sqrt(vel.x*vel.x+ vel.z*velo.z);
     46
     47
     48        //Daempfung falls das spaceship zu schnell wird
    5949        if(speed > maxspeed)
    6050        {
    61             velocity.x *= maxspeed/speed;
    62             velocity.y *= mayspeed/speed;
     51            vel.x *= maxspeed/speed;
     52            vel.z *= mayspeed/speed;
    6353        }
    6454
    65         pos.x += velocity.x*dt;
    66         pos.y += velocity.y*dt;
     55        if(moveUpPressed_)
     56        {
     57            //Gas geben
     58            vel.x += 1;
     59            vel.z += 1;
     60
     61        }else if(moveDownPressed_){
     62            //Bremsen
     63            vel.x += 1;
     64            vel.z += 1;
     65        }else if(moveLeftPressed_){
     66            //rotate left
     67        }else if (moveRightPressed_){
     68            //rotateright
     69        }   
     70
     71        setVelocity(vel);
     72       
     73        pos.x += vel.x*dt;
     74        pos.z += vel.z*dt;
    6775
    6876
    69         //haelt ship innerhalb des Kamerafensters
    70         if(x>width) x=0;
    71         if(x<0) x=width;
    72         if(y>height) y=0;
    73         if(y<0) y=height);
     77
     78        //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0)
     79        if(pos.x > width/2)   pos.x = -width/2;
     80        if(pos.x < -width/2)  pos.x = width/2;
     81        if(pos.z > height/2)  pos.z = -height/2;
     82        if(pos.z < -height/2) pos.z = height/2;
    7483
    7584
    7685        //Schiessen wenn geschossen wurde
    7786        // shoot!
    78 /*
     87
    7988        if (isFireing)
    8089            ControllableEntity::fire(0);
    81         */
    82 
    83         //Execute movement
    84         if (this->hasLocalController())
    85         {
    86             force.x += 1;
    87             force.y += 1;
    88 
    89         }
    90 
    91 
    92 
    93         //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
    94         Camera* camera = this->getCamera();
    95         if (camera != nullptr)
    96         {
    97             camera->setPosition(Vector3(0,cameradistance, 0));
    98             camera->setOrientation(Vector3::UNIT_Z, Degree(90));
    99         }
    100 
    101 
     90   
    10291
    10392        // bring back on track!
     
    10796        }
    10897
    109         velocity.x *= damping;
    110         velocity.y *= damping;
     98        //Reibung?
     99        vel.x *= damping;
     100        vel.y *= damping;
     101
    111102
    112103        setPosition(pos);
    113         setOrientation(Vector3::UNIT_Y, Degree(270));
     104        setOrientation(Vector3::UNIT_Y, Degree(direction));
    114105
    115         SUPER(AsteroidsShip, tick, dt);
     106        // Reset key variables
     107        moveUpPressed_ = false;
     108        moveDownPressed_ = false;
     109        moveLeftPressed_ = false;
     110        moveDownPressed_ = false;
     111
    116112
    117113    }
     
    119115    void AsteroidsShip::moveFrontBack(const Vector2& value)
    120116    {
    121         velocity.x += 1;
    122     }
     117        if (value.x > 0)
     118        {
     119            moveUpPressed_ = true;
     120            moveDownPressed_ = false
     121            if(moveUpPressed_)
     122            {
     123                orxout() << "up" << endl;
     124            }
     125        }
     126        else
     127        {
     128            moveUpPressed_ = false;
     129            moveDownPressed_ = true;
     130            if(moveDownPressed_)
     131            {
     132                orxout() << "down" << endl;
     133            }
     134        }
     135    }
    123136
    124     void AsteroidsShip::moveUpDown(const Vector2& value)
     137    void AsteroidsShip::moveRightLeft(const Vector2& value)
    125138    {
    126         velocity.y +=1;
     139        if (value.x > 0)
     140        {
     141            moveLeftPressed_ = false;
     142            moveRightPressed_ = true;
     143        }
     144            if(moveRightPressed_)
     145            {
     146                orxout() << "right" << endl;
     147            }
    127148
     149        else
     150        {
     151            moveLeftPressed_ = true;
     152            moveRightPressed_ = false;
     153            if(moveLeftPressed_)
     154            {
     155                orxout() << "left" << endl;
     156            }
     157        }
    128158    }
    129     void AsteroidsShip::moveFrontLeftRight(const Vector2& value)
    130     {
    131 
    132     }
     159   
    133160
    134161    Asteroids* AsteroidsShip::getGame()
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h

    r11541 r11555  
    5353            virtual void tick(float dt) override;
    5454
    55             // overwrite for 2d movement
     55            //overwrite for 2d movement
    5656            virtual void moveFrontBack(const Vector2& value) override;
    5757            virtual void moveRightLeft(const Vector2& value) override;
    58             virtual void moveUpDown(const Vector2& value) override;
    5958
    6059            // Starts or stops fireing
    61             virtual void boost(bool bBoost) override;
     60            //virtual void boost(bool bBoost) override;
    6261
    6362
     
    6968
    7069            bool bEndGame;
    71             bool bShowLevel;
    7270            int lives;
    73             float angle, radius;
    74             float damping, posforeward;
     71            float direction;
     72            float damping;
    7573            bool isFireing;
    76             float dx, dy;
    7774            const float maxspeed = 500;
    78             const float cameradistance = 100;
     75
    7976
    8077            //Nachschauen wie gross das Spielfeld ist!
     
    9188            WeakPtr<Asteroids> game;
    9289            WeakPtr<WorldEntity> lastEntity;
    93             Camera* camera;
    9490            float lastTimeFront, lastTimeLeft, lastTime;
    95             struct Vector
    96             {
    97                 float x;
    98                 float y;
    99             }force, velocity
     91
     92            //Controller
     93            bool moveUpPressed_, moveDownPressed_, moveRightPressed_, moveLeftPressed_;
    10094           
    10195    };
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc

    r11541 r11555  
    2828
    2929/**
    30     @file InvaderEnemy.h
    31     @brief Declaration of the InvaderEnemy class.
     30    @file AsteroidsEnemy.h
     31    @brief Declaration of the AsteroidsEnemy class.
    3232*/
    3333
     
    3636#include "Asteroids.h"
    3737#include "AsteroidsShip.h"
     38#include <cstdlib>
    3839#include <cmath>
    3940#include "util/Math.h"
    4041
     42const float delta = 3;
    4143
    4244namespace orxonox
     
    4850        RegisterObject(AsteroidsStone);
    4951
     52        direction = 0;
     53        //Spielfeld x als Horizontale und z als Vertikale
     54        fieldWidth_ = this->getGame()->center_->getFieldWidth;
     55        fieldHeigth_ = this->getGame()->center_->getFieldHeight;
     56
     57
     58        //Random size 1, 2, 3 ->muss noch realisiert werden. Templates erstellen
     59        this.size = 1;
    5060        maxspeed = 50.0f;
    5161        //Random Spawn? pos= random? -> spawn durch timer in der Asteroids Klasse
    52         this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0);
     62        this->setPosition(rnd(fieldWidth_), 0, rnd(fieldHeigth));
    5363
    54                 //random Geschwindigkeit und Richtung
    55                 velocity.x = rnd(0, maxspeed);
    56                 velocity.y = rnd(0, maxspeed);
    57         this->context = context;
     64        //random Geschwindigkeit und Richtung
     65        velocity.x = rnd(maxspeed);
     66        velocity.y = rnd(maxspeed);
     67    }
     68
     69    inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
     70    {
     71        if(orxonox_cast<AsteroidsShip*>(otherObject))
     72            removeHealth(2000);
     73        return false;
    5874    }
    5975
     
    6480        }else if(this->size == 2){
    6581            Pawn::death();
    66 
    6782            //Wie mache ich das ? Eigentlich in der game Klasse? sonst zeigt der Pointer auf einen falschen Bereich
    68 
    6983            for(int i = 0; i<2; i++)
    7084            {
    7185                AsteroidsStone* newStone;
    72                 newStone = new AsteroidsStone(this->context);
     86                newStone = new AsteroidsStone(this->getGame()->center_->getContext());
    7387                newStone->addTemplate("asteroidsstone");
    74                 newStone->setAsteroidsPlayer(player);
     88                newStone->setAsteroidsPlayer(this->getGame()->player);
    7589            }
    7690
    7791        }
     92    }
     93   
     94
     95    Asteroids* AsteroidsStone::getGame()
     96    {
     97        if (game == nullptr)
     98        {
     99            for (Asteroids* Asteroids : ObjectList<Asteroids>())
     100                game = asteroids;
     101        }
     102        return game;
    78103    }
    79104
     
    82107    void AsteroidsStone::tick(float dt)
    83108    {
    84         Vector3 pos = this->getPosition();
    85         pos.x += velocity.x*dt;
    86         pos.z += velocity.y*dt;
     109        Vector3 pos = getPosition();
    87110
     111
     112
     113
     114        //bounce on the borders
     115        if(pos.x-delta <= 0 || pos.x+delta >= fieldWidth_)
     116            direction = -direction;
     117
     118
     119
     120        //zurück bringen
    88121        if(pos.y != 0){
    89122            pos.y=0;
    90123        }
     124
     125        //spin
     126
     127        setOrientation()
    91128        setPosition(pos);
     129
    92130        SUPER(AsteroidsStone, tick, dt);
    93131    }
     
    95133    inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    96134    {
    97         if(orxonox_cast<InvaderShip*>(otherObject))
     135        if(orxonox_cast<AsteroidsShip*>(otherObject))
    98136            removeHealth(2000);
    99137        return false;
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h

    r11541 r11555  
    5050            //Es gibt 3 Groessen von Meteroiden gross, mittel, klein, gross ->2 mittleren, mittel -> 2 kleinen, kleine-> verschwinden
    5151            int size;
    52             int level;
     52
    5353            virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;}
     54            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
     55
    5456
    5557
    5658        protected:
     59
     60            Asteroids* getGame();
     61            WeakPtr<Asteroids> game;
    5762
    5863            virtual void death() override;
     
    6065
    6166            //herausfinden->ueber Kamera Einstellung wie bei Pong?
    62             float fieldWidth_=500;
    63             float fieldHeight_=700;
     67            float fieldWidth_;
     68            float fieldHeight_;
    6469            Vector2 velocity;
    6570            float maxspeed;
     71            float direction;
    6672
    67         private:
    68             Context* context;
    6973    };
    7074}
Note: See TracChangeset for help on using the changeset viewer.