예제 #1
0
 // Called when koala finished walking into the door
 void DreamKoalaDoorState::onInDoor(ichigo::Agent *agent)
 {
     // Switch to new area
     ichigo::Point spawnPos = _office->enterPortal();
     
     // Position koala at new door
     _koala->setFloor(_office->getFloorForTilePos(spawnPos.y));
     ichigo::SpriteActorView *koalaView = (ichigo::SpriteActorView *)_koala->getView();
     spawnPos.x += CONST_FLOAT("DKOALA_DOOR_X");
     spawnPos.y += CONST_FLOAT("DKOALA_DOOR_INSIDE_Y");
     koalaView->setPosition(spawnPos);
     
     // Walk into new room
     koalaView->playAnimation("out");
 }
예제 #2
0
    // Called when the lift door opened (it should always be the lift on the floor with the koala)
    void DreamKoalaLiftState::onLiftOpened(ichigo::Agent *agent)
    {
        // Going in or out?
        if (!_isInLift)
        {
            // Walk into lift
            ichigo::SpriteActorView *koalaSprite = (ichigo::SpriteActorView *)_koala->getView();
        
            // Find koala offset in lift tile
            ichigo::Point offsetInTile;
            ((ichigo::TileMapView *)_office->getView())->getTileAtPosition(_koala->getView()->getPosition().x, 
                                                                           _koala->getView()->getPosition().y, 
                                                                           &offsetInTile);
        
            // Find how much koala needs to move from current position to destination
            offsetInTile.x = CONST_FLOAT("DKOALA_LIFT_INSIDE_X") - offsetInTile.x;
            offsetInTile.y = CONST_FLOAT("DKOALA_LIFT_INSIDE_Y") - offsetInTile.y;
        
            // Move into lift
            koalaSprite->playAndMoveBy("in", offsetInTile);
 
            _isInLift = true;
        }
        else
        {
            // Walk out of lift
            ichigo::SpriteActorView *koalaSprite = (ichigo::SpriteActorView *)_koala->getView();
            
            // Put koala in front of doors
            koalaSprite->setZOrder(3);
            
            // Find koala offset in lift tile
            ichigo::Point offsetInTile;
            ((ichigo::TileMapView *)_office->getView())->getTileAtPosition(_koala->getView()->getPosition().x, 
                                                                           _koala->getView()->getPosition().y, 
                                                                           &offsetInTile);
            
            // Find how much koala needs to move from current position to destination
            offsetInTile.x = CONST_FLOAT("DKOALA_LIFT_ENTRY_X") - offsetInTile.x;
            offsetInTile.y = CONST_FLOAT("DKOALA_LIFT_ENTRY_Y") - offsetInTile.y;
            
            // Move out of lift
            koalaSprite->playAndMoveBy("out", offsetInTile);
            
            _isInLift = false;
        }
    }
예제 #3
0
 // Called on each frame
 void DreamKoalaStandState::onUpdate(float dt)
 {
     FSMState::onUpdate(dt);
     
     if (!_isTurning)
     {
         // Check if there is a difference between current position and target position
         float distToTarget = _koala->getPosX() - _koala->getTargetX();
     
         if (distToTarget < -CONST_FLOAT("DKOALA_MOVE_THRESHOLD"))
         {
             // Target is at right of koala. Turn towards it and walk there.
             if (_koala->getDir() != DKD_RIGHT)
             {
                 turnRight();
             }
             else
             {
                 walk();
             }
         }
         else if (distToTarget > CONST_FLOAT("DKOALA_MOVE_THRESHOLD"))
         {
             // Target is at left of koala. Turn towards is and walk there.
             if (_koala->getDir() == DKD_LEFT)
             {
                 walk();
             }
             else 
             {
                 turnLeft();
             }
         }
         else if (_koala->getFloor() != _koala->getTargetFloor())
         {
             // Koala needs to go to a different floor. Turn towards lift and switch to lift state
             if (_koala->getDir() != DKD_IN)
             {
                 turnIn();
             }
             else
             {
                 startLiftSequence();
             }
         }
     }
 }
예제 #4
0
/**
 * Animates the game scene.
 *
 * @param dt Delta time.
 */
void EngineCore::animate(float dt)
{
	dt *= CONST_FLOAT("Gameplay::GameSpeedMultiplier");

	LuaManager::getInstance()->callFunction("animateSceneL", dt);

	// TODO: animate components
}
예제 #5
0
 // Called every time touch has been moved
 void ItemDragState::onTouchMoved(ichigo::Agent *agent)
 {
     ichigo::Director *director = (ichigo::Director *)agent;
     ichigo::TouchPoint *tp = director->getTouchPoint(_touchID);
     
     if (tp)
     {
         ichigo::Point localPos = _itemView->convertScreenToLocal(tp->getPos());
         localPos.x += CONST_FLOAT("ITEM_DRAG_OFFSET_X");
         localPos.y += CONST_FLOAT("ITEM_DRAG_OFFSET_Y");
         _itemView->setPosition(localPos);
     }
     else
     {
         endDrag();
     }
 }
예제 #6
0
 // Gets called when a touch is dragging or stretching the office. In this case we mark it so touch isn't considered as an
 // interaction with the office itself
 void OfficeStretchingState::onTouchMoved(ichigo::Agent *director)
 {
     ichigo::TouchPoint *tp = ((ichigo::Director *)director)->getTouchPoint(_touchID1);
     if (tp && !_touchPointMoved && tp->getPos().distanceTo(_touchPoint1) >= CONST_FLOAT("OFFICE_INTERACTION_DRAG_THRESHOLD"))
     {
         _touchPointMoved = true;
     }
     
     StretchingState::onTouchMoved(director);
 }