Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2011, 4:12:27 PM (13 years ago)
Author:
sven
Message:

Spaceships attach now to the dock, fixed DockingController.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dockingsystem2/src/modules/docking/DockingController.cc

    r8501 r8544  
    2929#include "DockingController.h"
    3030
     31#include <cmath>
     32
    3133#include "infos/PlayerInfo.h"
    3234#include "worldentities/ControllableEntity.h"
     
    4951    void DockingController::tick(float dt)
    5052    {
    51         this->moveToTargetPosition();
     53        ControllableEntity* entity = this->getControllableEntity();
     54        if (!entity)
     55            return;
     56
     57        float distance = (dock->getWorldPosition() - entity->getPosition()).length();
     58        Vector2 coord = get2DViewdirection(     // I don't understand this too
     59            entity->getPosition(),
     60            entity->getOrientation() * WorldEntity::FRONT,
     61            entity->getOrientation() * WorldEntity::UP,
     62            dock->getWorldPosition()
     63        );
     64
     65        // adjust direction of spaceship
     66        if (distance > 10)
     67        {
     68            entity->rotateYaw(-1.0f * 0.8f * sgn(coord.x) * coord.x*coord.x);
     69            entity->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     70        }
     71
     72        /*// adjust speed
     73        if (distance < 200 && entity->getVelocity().squaredLength() > dock->getVelocity().squaredLength())
     74            entity->moveFrontBack(0.2f);
     75        else
     76            entity->moveFrontBack(0.8f);*/
     77
     78        entity->moveFrontBack(0.5f * log(distance/10.0f));
     79
     80        if (distance < 20)
     81            this->positionReached();
    5282
    5383        SUPER(DockingController, tick, dt);
    5484    }
    5585
     86    void DockingController::takeControl(bool docking)
     87    {
     88        this->docking = docking;
     89
     90        entity = player->getControllableEntity();
     91        assert(entity);
     92
     93        if (docking)
     94        {
     95            COUT(0) << "DockingController::takeControl Taking over control." << std::endl;
     96
     97            entity->setDestroyWhenPlayerLeft(false);
     98            player->pauseControl();
     99            entity->setController(this);
     100            this->setControllableEntity(entity);
     101        }
     102    }
     103
    56104    void DockingController::positionReached()
    57105    {
    58         // TODO; Give control back to player
    59         PlayerInfo* player = this->entity->getPlayer();
    60         assert(player);
     106        COUT(0) << "DockingController::positionReached() called." << std::endl;
     107
     108        assert(this->player);
     109        assert(this->dock);
     110
     111        // stop spaceship
     112        dock->attach(entity);
     113        entity->setVelocity(0, 0, 0);
     114        entity->setOrientation(dock->getOrientation());
     115
     116        // give control back to player
     117        player->startControl(entity);
     118        this->setActive(false);
     119        this->controllableEntity_ = NULL;
    61120
    62121        if (docking)
    63122            dock->dockingAnimationFinished(player);
    64         else
    65             dock->undockingAnimationFinished(player);
     123        /*else
     124            dock->undockingAnimationFinished(player);*/
     125
     126        this->destroy();
    66127    }
    67128}
Note: See TracChangeset for help on using the changeset viewer.