Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10406


Ignore:
Timestamp:
Apr 26, 2015, 10:16:26 PM (9 years ago)
Author:
fvultier
Message:

There is now a cube that can be moved on the playground using the arrow keys.

Location:
code/branches/towerdefenseFS15
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/towerdefenseFS15/data/levels/towerDefense.oxw

    r10378 r10406  
    2525?>
    2626
    27 <!-- Specify the position of the camera -->
    28 <Template name=centerpointmarkcamera defaults=0>
    29   <Pawn team=0>
     27
     28<Template name=selectercameras defaults=0>
     29  <TowerDefenseSelecter>
    3030    <camerapositions>
    31       <CameraPosition position="0,0,1500"/>
     31      <CameraPosition position="0,0,1400" lookat="0,0,0" absolute=true />
    3232    </camerapositions>
    33   </Pawn>
     33  </TowerDefenseSelecter>
    3434</Template>
    3535
    36 <!-- Loads a mesh to mark the center-->
    37 <Template name=centerpointmark>
    38   <Pawn team=0 camerapositiontemplate=centerpointmarkcamera>
     36<Template name=selectertemplate>
     37  <TowerDefenseSelecter team=0 camerapositiontemplate=selectercameras>
    3938    <attached>
    40       <Model position="0,0,0" mesh="cylinder.mesh" scale3D="1,1,1" /> <!-- the camera is attached to this -->
     39      <Model position="0,0,0" mesh="cube.mesh" scale=45 />
    4140    </attached>
    42   </Pawn>
     41  </TowerDefenseSelecter>
    4342</Template>
     43
     44
    4445
    4546
     
    5960
    6061    <!-- Spawns the camera, attached to a crate -->
    61     <SpawnPoint team=0 position="0,0,0" pawndesign=centerpointmark />
    62     <!--TeamSpawnPoint team=0 position="-7,7,4" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff /-->
    63 
    64     <!--SpawnPoint team=0 position="0,0,10" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff  /-->
    65     <!--SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /-->
    66 
    67 
    68 
    69 
    70     <!--invisible entity to attach towers to, since playfield is static and towers are dynamic-->
    71     <StaticEntity position=0,0,0>
    72 
    73         <attached>
    74             <Model position="-50,-50,0" mesh="Playfield_ME.mesh" scale=80 />
    75             <!-- Base -->
    76             <Model position="500,700,100" mesh="sphere.mesh" scale=80 />
    77             <!--Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" /--> <!-- Only temporary needed to help align the collisionshape -->
    78             <!-- This was used to mark the playfield, let's let it be here for now -->
    79             <!--Model position="-8,8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    80             <!--Model position="-8,-8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    81             <!--Model position="8,-8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    82             <!--Model position="8,8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    83         </attached>
    84         <collisionShapes> <!-- The collisionshape forbids other worldentities that have a collisionShape to fly through it.
    85 
    86                                TODO: Find correct size for the collisionshape; since a collisionShape is invisible
    87                                I added the crate wich currently has the same dimensions as the collisionshape.
    88                                You have to adjust the crate's scale3D as well as the collisionshape's halfExtens to
    89                                find the proper shape. -->
    90            <BoxCollisionShape position="0,0,0" halfExtents="400,400,100" />
    91         </collisionShapes>
    92     </StaticEntity>
    93 
    94 
    95 
     62    <SpawnPoint team=0 position="0,0,0"/>
    9663
    9764    <!-- PlayField -->
    9865    <TowerDefenseCenterpoint
    9966    name=towerdefensecenter
     67
     68    selecterTemplate=selectertemplate
     69
    10070    width=16
    10171    height=16
     
    10575    collisionType=dynamic
    10676    mass=100000
    107     />
     77    >
     78        <attached>
     79            <Model position="-50,-50,0" mesh="Playfield_ME.mesh" scale=80 />
     80            <Model position="500,700,100" mesh="sphere.mesh" scale=80 />
     81        </attached>
     82        <camerapositions>
     83      <CameraPosition position="0,0,1500" lookat="0,0,0" absolute=true/>
     84    </camerapositions>
     85    </TowerDefenseCenterpoint>
    10886
    10987  </Scene>
  • code/branches/towerdefenseFS15/src/modules/tetris/Tetris.h

    r9833 r10406  
    9090            void clearRow(unsigned int row);
    9191
    92 
    9392            PlayerInfo* player_;
    9493
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TDCoordinate.cc

    r10258 r10406  
    1717    {
    1818        //RegisterObject(TDCoordinate);
    19         x=0;
    20         y=0;
     19        Set(0,0);
    2120
    2221    }
    2322
    2423    TDCoordinate::TDCoordinate(int x, int y)
    25     {
    26         this->x=x;
    27         this->y=y;
     24    {       
     25        Set(x,y);
     26    }
     27
     28    void TDCoordinate::Set(int x, int y)
     29    {       
     30        if (x < 0)
     31        {
     32            _x = 0;
     33        }
     34        else if (x > 15)
     35        {
     36            _x = 15;
     37        }
     38        else
     39        {
     40            _x = x;
     41        }
     42
     43        if (y < 0)
     44        {
     45            _y = 0;
     46        }
     47        else if (y > 15)
     48        {
     49            _y = 15;
     50        }
     51        else
     52        {
     53            _y = y;
     54        }
     55    }
     56
     57    int TDCoordinate::GetX()
     58    {       
     59        return _x;
     60    }
     61
     62    int TDCoordinate::GetY()
     63    {       
     64        return _y;
    2865    }
    2966
     
    3471
    3572        Vector3 *coord = new Vector3();
    36         coord->x= (x-8) * tileScale;
    37         coord->y= (y-8) * tileScale;
     73        coord->x= (_x-8) * tileScale;
     74        coord->y= (_y-8) * tileScale;
    3875        coord->z=100;
    3976
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TDCoordinate.h

    r10258 r10406  
    1616    {
    1717        public:
    18             int x;
    19             int y;
     18            TDCoordinate();
     19            TDCoordinate(int x, int y);
     20            virtual ~TDCoordinate() {};
     21            virtual void Set(int x, int y);
     22            virtual int GetX();
     23            virtual int GetY();
     24            virtual Vector3 get3dcoordinate();
    2025
    21             TDCoordinate();
    22 
    23             Vector3 get3dcoordinate();
    24 
    25             virtual ~TDCoordinate() {};
    26 
    27             TDCoordinate(int x, int y);
     26        private:
     27            int _x;
     28            int _y;
    2829    };
    2930
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefense.cc

    r10397 r10406  
    3535 * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn )
    3636 * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben.
    37  *
    3837 *
    3938 *
     
    110109
    111110        selecter = NULL;
    112 
    113 
     111        this->player_ = NULL;       
    114112        this->setHUDTemplate("TowerDefenseHUD");
    115113        this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this)));
     
    145143    void TowerDefense::start()
    146144    {
     145        if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place.
     146        {
     147            if (selecter == NULL)
     148            {
     149                selecter = new TowerDefenseSelecter(this->center_->getContext());               
     150            }
     151            selecter->addTemplate(center_->getSelecterTemplate());
     152            center_->attach(selecter);
     153        }
     154        else // If no centerpoint was specified, an error is thrown and the level is exited.
     155        {
     156            orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
     157            return;
     158        }
    147159
    148160        TeamDeathmatch::start();
    149161
    150 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
     162        // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
    151163        for (int i=0; i < 16 ; i++)
    152164        {
     
    158170        }
    159171
    160         selecter = new TowerDefenseSelecter(this->center_->getContext());
     172       
     173
     174        if (player_ != NULL)
     175        {
     176            //this->player_->startControl(selecter);
     177        }
     178        else
     179        {
     180            orxout() << "player=NULL" << endl;
     181        }
     182
    161183
    162184        Model* dummyModel = new Model(this->center_->getContext());
     
    219241        en1->setTeam(2);
    220242        en1->getController();
    221         en1->setPosition(path.at(0)->get3dcoordinate());
     243        en1->setPosition(path.at(0)->get3dcoordinate());       
    222244        TowerDefenseEnemyvector.push_back(en1);
    223245
     
    237259    }
    238260
     261    void TowerDefense::spawnPlayer(PlayerInfo* player)
     262    {
     263        assert(player);
     264        this->player_ = player;
     265
     266        if (selecter->getPlayer() == NULL)
     267        {
     268            this->player_ = player;
     269            player->startControl(selecter);
     270            players_[player].state_ = PlayerState::Alive;
     271        }
     272    }
     273
     274    /**
     275    @brief
     276        Get the player.
     277    @return
     278        Returns a pointer to the player. If there is no player, NULL is returned.
     279    */
     280    PlayerInfo* TowerDefense::getPlayer(void) const
     281    {
     282        return this->player_;
     283    }
     284
    239285    //not working yet
    240286    void TowerDefense::upgradeTower(int x,int y)
    241287    {
     288        TDCoordinate* coord = new TDCoordinate(x,y);
     289        x = coord->GetX();
     290        y = coord->GetY();
     291       
    242292        const int upgradeCost = 20;
    243293
     
    266316    /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
    267317    so towers have ability if the turrets
    268 
    269318    */
     319
    270320    void TowerDefense::addTower(int x, int y)
    271     {
     321    {       
     322        TDCoordinate* coord = new TDCoordinate(x,y);
     323        x = coord->GetX();
     324        y = coord->GetY();
     325
    272326        const int towerCost = 20;
    273327
     
    291345        int tileScale = (int) this->center_->getTileScale();
    292346
    293         if (x > 15 || y > 15 || x < 0 || y < 0)
     347        /*if (x > 15 || y > 15 || x < 0 || y < 0)
    294348        {
    295349            //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet)
    296350            orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl;
    297351            return;
    298         }
    299 
    300         orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
    301 
     352        }*/
     353
     354        //orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
     355        orxout() << "Will add tower at (" << x << "," << y << ")" << endl;
    302356
    303357
    304358        //Create Model
    305         Model* newtowermodel = new Model(this->center_->getContext());
    306         newtowermodel->setMeshSource("Tower.mesh");
    307         newtowermodel->setScale(45);
    308         newtowermodel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50);
    309 
    310 
     359        Model* newTowerModel = new Model(this->center_->getContext());
     360        newTowerModel->setMeshSource("Tower.mesh");
     361        newTowerModel->setScale(45);
     362        newTowerModel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50);
    311363
    312364        //Creates tower
     
    318370        //Reduce credit
    319371         this->buyTower(towerCost);
    320          towerModelMatrix [x][y]= newtowermodel;
     372         towerModelMatrix [x][y]= newTowerModel;
    321373         towerTurretMatrix [x][y]= towernew;
    322     }
     374    }   
    323375
    324376    bool TowerDefense::hasEnoughCreditForTower(int towerCost)
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefense.h

    r10397 r10406  
    4545#include "core/object/WeakPtr.h"
    4646#include "TowerDefenseSelecter.h"
     47#include "graphics/Camera.h"   
    4748
    4849
     
    6263        virtual void end();
    6364        virtual void tick(float dt);
    64         //virtual void playerEntered(PlayerInfo* player);
    65         //virtual bool playerLeft(PlayerInfo* player);
    66         //Player Stats (set,get, reduce)
     65        virtual void spawnPlayer(PlayerInfo* player);
     66        PlayerInfo* getPlayer(void) const;
    6767        int getCredit(){ return this->credit_; }
    6868        int getLifes(){ return this->lifes_; }
     
    7575        void nextwave(){ TowerDefenseEnemyvector.clear(); waves_++; time=0;}
    7676        int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes; }
    77         TDCoordinate* selectedPos;
    7877        TowerDefenseSelecter* selecter;
    7978
     
    8988        /* Adds a tower at x, y in the playfield */
    9089        void addTower(int x, int y);
    91 
    9290        void upgradeTower(int x, int y);
    9391
     
    9997    private:
    10098        TowerDefenseCenterpoint *center_;
     99        PlayerInfo* player_;
    101100        float time;
    102101//        float time2;
     
    109108        bool hasEnoughCreditForTower(int towerCost);
    110109        bool hasEnoughCreditForUpgrade();
    111 
    112 
    113 
    114         std::vector<TowerTurret*> towers_;
    115110    };
    116111}
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseCenterpoint.cc

    r10325 r10406  
    7171        XMLPortParam(TowerDefenseCenterpoint, "height", setHeight, getHeight, xmlelement, mode);
    7272        XMLPortParam(TowerDefenseCenterpoint, "tileScale", setTileScale, getTileScale, xmlelement, mode);
     73        XMLPortParam(TowerDefenseCenterpoint, "selecterTemplate", setSelecterTemplate, getSelecterTemplate, xmlelement, mode);
    7374
    7475        //TODO: add XMLPortObject(TowerDefenseCenterpoint, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseCenterpoint.h

    r10325 r10406  
    6060            void setWidth(unsigned int width)
    6161                { this->width_ = width; }
    62 
    6362            unsigned int getWidth(void) const
    6463                { return this->width_; }
    65 
    6664            void setHeight(unsigned int height)
    6765                { this->height_ = height; }
    68 
    6966            unsigned int getHeight(void) const
    7067                { return this->height_; }
    71 
     68            void setSelecterTemplate(const std::string& newTemplate)
     69                { this->selecterTemplate_ = newTemplate; }
     70            const std::string& getSelecterTemplate() const
     71                { return this->selecterTemplate_; }   
    7272            /**
    7373                @brief How to convert to world coordinates, e.g. that 0,15 is not at -8,-8 but at -80,-80 (if scale would be 10)
     
    8282            void checkGametype();
    8383
     84            std::string selecterTemplate_;
    8485            unsigned int width_;
    8586            unsigned int height_;
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseSelecter.cc

    r10397 r10406  
    5151        moveLeftPressed_ = false;
    5252        moveRightPressed_ = false;
    53         selectedPos_ = new TDCoordinate(0,0);
    54 
    55         Model* selecterModel = new Model(context);
    56         selecterModel->setMeshSource("cube.mesh");
    57         selecterModel->setScale(45);
    58 
     53        setSelectedPosition(0,0);     
    5954    }
    6055
     
    6762    {
    6863        SUPER(TowerDefenseSelecter, XMLPort, xmlelement, mode);
    69         // Beispielport // XMLPortParam(TowerDefenseSelecter, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode);
    70 
    7164    }
    7265
     
    7770        if (hasLocalController())
    7871        {
     72            int selecterPosX = selectedPos_->GetX();
     73            int selecterPosY = selectedPos_->GetY();
    7974
    8075            if (moveUpPressed_ == true)
    8176            {
    82                 if(this->selectedPos_->y >= 15)
    83                 {
    84                 }
    85                 else
    86                 {
    87                         this->selectedPos_->y +=1;
    88                         this->setPosition(selectedPos_->get3dcoordinate());
    89                 }
    90 
     77                selectedPos_->Set(selecterPosX, selecterPosY + 1);
     78                updatePosition();
     79                orxout() << "up" << endl;
    9180            }
    9281            if (moveDownPressed_ == true)
    9382            {
    94                 if(this->selectedPos_->y <= 0)
    95                 {
    96                                 }
    97                                 else
    98                                 {
    99                                         this->selectedPos_->y -= 1;
    100                                         this->setPosition(selectedPos_->get3dcoordinate());
    101                                 }
    102 
    103                 moveDownPressed_ = false;
     83                selectedPos_->Set(selecterPosX, selecterPosY - 1);
     84                updatePosition();
     85                orxout() << "Down" << endl;
    10486            }
    10587
    10688            if (moveLeftPressed_ == true)
    10789            {
    108                 if(this->selectedPos_->x <= 0)
    109                 {
    110                 }
    111                 else
    112                 {
    113                         this->selectedPos_->x -=1;
    114                         this->setPosition(selectedPos_->get3dcoordinate());
    115                 }
    116 
     90                selectedPos_->Set(selecterPosX - 1, selecterPosY);
     91                updatePosition();
     92                orxout() << "Left" << endl;
    11793            }
    11894            if (moveRightPressed_ == true)
    11995            {
    120                 if(this->selectedPos_->x >= 15)
    121                 {
    122                                 }
    123                                 else
    124                                 {
    125                                         this->selectedPos_->x += 1;
    126                                         this->setPosition(selectedPos_->get3dcoordinate());
    127                                 }
    128 
    129                 moveDownPressed_ = false;
     96                selectedPos_->Set(selecterPosX + 1, selecterPosY);
     97                updatePosition();
     98                orxout() << "Right" << endl;
    13099            }
    131 
    132 
    133100
    134101            /*
     
    137104                firePressed_ = false;
    138105                timeSinceLastFire_ = 0.0;
    139                 fireSignal_ = true;
    140106            }
    141107            */
     
    146112        moveDownPressed_ = false;
    147113        moveLeftPressed_ = false;
    148         moveDownPressed_ = false;
     114        moveRightPressed_ = false;
    149115        //firePressed_ = false;
    150116    }
     
    199165        //firePressed_ = true;
    200166    }
     167
     168    void TowerDefenseSelecter::updatePosition()
     169    {
     170        setPosition(selectedPos_->get3dcoordinate());
     171    }
     172
     173    void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos)
     174    {
     175        selectedPos_ = newPos;
     176        updatePosition();
     177    }
     178
     179    void TowerDefenseSelecter::setSelectedPosition(int x,  int y)
     180    {
     181        setSelectedPosition(new TDCoordinate(x,y));
     182    }
     183
     184
    201185}
  • code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseSelecter.h

    r10397 r10406  
    4141            TowerDefenseSelecter(Context* context); //!< Constructor. Registers and initializes the object.
    4242            virtual ~TowerDefenseSelecter();
    43             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    44             virtual void tick(float dt);
     43            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
     44            virtual void tick(float dt);           
    4545            virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
    4646            virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
     
    5050            void fire(unsigned int firemode);
    5151            virtual void fired(unsigned int firemode);
     52            virtual void setSelectedPosition(TDCoordinate* newPos);
     53            virtual void setSelectedPosition(int x, int y);
     54
     55        private:           
     56            virtual void updatePosition();
     57           
    5258            TDCoordinate* selectedPos_;
    53 
    54 
    55 
    56         private:
    57 
    5859            bool moveUpPressed_;
    5960            bool moveDownPressed_;
    6061            bool moveLeftPressed_;
    61             bool moveRightPressed_;
     62            bool moveRightPressed_;           
    6263    };
    6364}
Note: See TracChangeset for help on using the changeset viewer.