Skip to content

Commit

Permalink
magic triplet to rebuild active room at any moment
Browse files Browse the repository at this point in the history
   is option & shift & r

inviolablility is now granted on mortal floor too

and bin redundant “ preserving of orientation ” for player item

there’s no issue #11 since yet
  • Loading branch information
dougmencken committed Oct 7, 2017
1 parent 2d6942b commit f3c627c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 58 deletions.
26 changes: 21 additions & 5 deletions src/Isomot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ BITMAP* Isomot::update()
key[ KEY_MINUS ] = 0;
}

if( ( key_shifts & KB_ALT_FLAG ) && ( key_shifts & KB_SHIFT_FLAG ) && key[ KEY_R ] )
{
////Direction direction = activeRoom->getMediator()->getActivePlayer()->getDirection();

playTuneForScenery( activeRoom->getScenery () );

activeRoom = mapManager->rebuildRoom();
////activeRoom->getMediator()->getActivePlayer()->setDirection( direction );

key[ KEY_R ] = 0;
}

if( ( key_shifts & KB_ALT_FLAG ) && ( key_shifts & KB_SHIFT_FLAG ) && key[ KEY_J ] )
{
PlayerItem* activePlayer = activeRoom->getMediator()->getActivePlayer();
Expand Down Expand Up @@ -358,11 +370,7 @@ BITMAP* Isomot::update()

if ( activeRoom != 0 )
{
std::string scenery = activeRoom->getScenery ();
if ( scenery != "" )
{
SoundManager::getInstance()->playOgg ( "music/" + scenery + ".ogg", /* loop */ false );
}
playTuneForScenery( activeRoom->getScenery () );
}
}
}
Expand Down Expand Up @@ -404,6 +412,14 @@ BITMAP* Isomot::update()
return this->view;
}

void Isomot::playTuneForScenery ( const std::string& scenery )
{
if ( scenery != "" )
{
SoundManager::getInstance()->playOgg ( "music/" + scenery + ".ogg", /* loop */ false );
}
}

void Isomot::updateEndRoom()
{
Room* activeRoom = mapManager->getActiveRoom();
Expand Down
2 changes: 2 additions & 0 deletions src/Isomot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Isomot

private:

void playTuneForScenery ( const std::string& scenery ) ;

void offVidasInfinitas () ;

void offInviolability () ;
Expand Down
12 changes: 3 additions & 9 deletions src/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,31 @@ bool Item::animate()
return cycle;
}

void Item::changeItemData( ItemData* itemData, const Direction& direction, const std::string& initiatedBy )
void Item::changeItemData( ItemData* itemData, const std::string& initiatedBy )
{
std::cout << "metamorphosis of data for item with label \"" << getLabel()
<< "\" to data of \"" << itemData->label
<< "\" initiated by \"" << initiatedBy << "\"" << std::endl ;

this->dataOfItem = itemData;
this->direction = direction;
this->frameIndex = 0;
this->backwardMotion = false;
}

void Item::changeDirection( const Direction& direction )
{
// Se cambia la dirección sólo si el elemento tiene distintos fotogramas para representar
// distintas direcciones
// direction is changed only when item has different frames for different directions
if ( dataOfItem->directionFrames > 1 )
{
// Cálculo del fotograma correspondiente a la nueva dirección
// get frame for new direction
unsigned int currentFrame = ( ( dataOfItem->motion.size() - dataOfItem->extraFrames ) / dataOfItem->directionFrames ) * direction;

// Si la imagen actual es distinta a la nueva imagen entonces se cambia
if ( this->rawImage != 0 && currentFrame < dataOfItem->motion.size() && this->rawImage != dataOfItem->motion[ currentFrame ] )
{
// Actualiza la dirección
this->direction = direction;

// Actualiza la imagen
changeImage( dataOfItem->motion[ currentFrame ] );

// Si cambia la imagen entonces cambia la sombra
if ( this->shadow != 0 )
changeShadow( dataOfItem->shadows[ currentFrame ] );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Item : public Mediated
/**
* Change data of item preserving its label. Used when there’s a metamorphosis such as when player teleports
*/
void changeItemData ( ItemData * itemData, const Direction& direction, const std::string& initiatedBy ) ;
void changeItemData ( ItemData * itemData, const std::string& initiatedBy ) ;

/**
* Cambia la dirección del elemento y establece el fotograma adecuado
Expand Down
4 changes: 2 additions & 2 deletions src/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Room* MapManager::changeRoom( const Direction& exit )
const int exitY = oldItemOfRoamer->getY ();
const int exitZ = oldItemOfRoamer->getZ ();

const Direction exitOrientation = oldItemOfRoamer->getOrientation ();
const Direction exitOrientation = oldItemOfRoamer->getDirection ();

// get limits of room
// there’s possibility to exit and to enter new room in cases when player travels through floor, roof or via teletransport
Expand Down Expand Up @@ -412,7 +412,7 @@ Room* MapManager::rebuildRoom()
removeRoom( roomToForget );
}

direction = player->getOrientation();
direction = player->getDirection();

Direction entry = player->getDirectionOfEntry();

Expand Down
40 changes: 38 additions & 2 deletions src/PlayerItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ PlayerItem::PlayerItem( ItemData* itemData, int x, int y, int z, const Direction
, shield( 0 )
, howManyDoughnuts( 0 )
, exit( NoExit )
, orientation( NoDirection )
, entry( JustWait )
, shieldTimer( 0 )
, shieldTime( 25.0 )
Expand All @@ -37,7 +36,6 @@ PlayerItem::PlayerItem( const PlayerItem& playerItem )
, tools( playerItem.tools )
, howManyDoughnuts( playerItem.howManyDoughnuts )
, exit( playerItem.exit )
, orientation( playerItem.orientation )
, entry( playerItem.entry )
, shieldTimer( 0 )
, shieldTime( playerItem.shieldTime )
Expand All @@ -53,6 +51,44 @@ PlayerItem::~PlayerItem()
}
}

void PlayerItem::setDirectionOfExit ( const Direction& direction )
{
this->exit = direction;

switch ( direction )
{
case North:
case South:
case East:
case West:
setDirection( direction );
break;

case Northeast:
case Northwest:
setDirection( North );
break;

case Southeast:
case Southwest:
setDirection( South );
break;

case Eastnorth:
case Eastsouth:
setDirection( East );
break;

case Westnorth:
case Westsouth:
setDirection( West );
break;

default:
;
}
}

void PlayerItem::autoMoveOnEntry ( const Direction& entry )
{
setDirectionOfEntry( entry );
Expand Down
15 changes: 2 additions & 13 deletions src/PlayerItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace isomot
class ItemData ;
class GameManager ;


/**
* Item of player controller by the user
*/
Expand Down Expand Up @@ -229,11 +230,6 @@ class PlayerItem : public FreeItem
*/
Direction exit ;

/**
* Direction player looks at when it leaves room
*/
Direction orientation ;

/**
* How player enters room: through door, or via teleport, or going below floor or above ceiling
*/
Expand Down Expand Up @@ -310,17 +306,10 @@ class PlayerItem : public FreeItem
/**
* Direction of player when it leaves room
*/
void setDirectionOfExit ( const Direction& direction ) { this->exit = direction ; }
void setDirectionOfExit ( const Direction& direction ) ;

Direction getDirectionOfExit () const { return this->exit ; }

/**
* Direction player looks at when it leaves room
*/
void setOrientation ( const Direction& direction ) { this->orientation = direction ; }

Direction getOrientation () const { return this->orientation ; }

/**
* How player enters room
*/
Expand Down
6 changes: 4 additions & 2 deletions src/activities/FallKindOfActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ bool FallKindOfActivity::fall( Behavior * behavior )
if ( mediator->getRoom()->getKindOfFloor() == "none" )
{
playerItem->setDirectionOfExit( Down );
playerItem->setOrientation( playerItem->getDirection() );
}
else
if ( mediator->getRoom()->getKindOfFloor() == "mortal" )
{
playerItem->getBehavior()->changeActivityOfItem( MeetMortalItem );
if ( ! GameManager::getInstance()->isImmuneToCollisionsWithMortalItems () )
{
playerItem->getBehavior()->changeActivityOfItem( MeetMortalItem );
}
}
else
/* if ( mediator->getRoom()->getKindOfFloor() == "plain" ) */
Expand Down
12 changes: 0 additions & 12 deletions src/activities/KindOfActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,62 +149,50 @@ void KindOfActivity::propagateActivityToAdjacentItems( Item * sender, const Acti
{
case NorthBorder:
player->setDirectionOfExit( North );
player->setOrientation( North );
break;

case SouthBorder:
player->setDirectionOfExit( South );
player->setOrientation( South );
break;

case EastBorder:
player->setDirectionOfExit( East );
player->setOrientation( East );
break;

case WestBorder:
player->setDirectionOfExit( West );
player->setOrientation( West );
break;

case NortheastBorder:
player->setDirectionOfExit( Northeast );
player->setOrientation( North );
break;

case NorthwestBorder:
player->setDirectionOfExit( Northwest );
player->setOrientation( North );
break;

case SoutheastBorder:
player->setDirectionOfExit( Southeast );
player->setOrientation( South );
break;

case SouthwestBorder:
player->setDirectionOfExit( Southwest );
player->setOrientation( South );
break;

case EastnorthBorder:
player->setDirectionOfExit( Eastnorth );
player->setOrientation( East );
break;

case EastsouthBorder:
player->setDirectionOfExit( Eastsouth );
player->setOrientation( East );
break;

case WestnorthBorder:
player->setDirectionOfExit( Westnorth );
player->setOrientation( West );
break;

case WestsouthBorder:
player->setDirectionOfExit( Westsouth );
player->setOrientation( West );
break;

default:
Expand Down
1 change: 0 additions & 1 deletion src/activities/MoveKindOfActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ void MoveKindOfActivity::ascent( FreeItem* freeItem, int z )
if ( playerItem != 0 && playerItem->getZ() >= MaxLayers * LayerHeight )
{
playerItem->setDirectionOfExit( Up );
playerItem->setOrientation( playerItem->getDirection() );
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/behaviors/UserControlled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ void UserControlled::jump( PlayerItem * player )
if ( player->getZ() >= MaxLayers * LayerHeight )
{
player->setDirectionOfExit( Up );
player->setOrientation( player->getDirection() );
}
}

Expand Down Expand Up @@ -390,11 +389,10 @@ void UserControlled::wayInTeletransport( PlayerItem * player )
switch ( activity )
{
case BeginWayInTeletransport:
// preserve orientation of player
player->setOrientation( player->getDirection() );
// change to bubbles preserving label of player
playerData = player->getDataOfFreeItem() ;
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "begin way in teletransport" );
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "begin way in teletransport" );

// backward animation of bubbles
player->setBackwardMotion();

Expand All @@ -407,9 +405,7 @@ void UserControlled::wayInTeletransport( PlayerItem * player )
if ( player->animate() )
{
// back to original appearance of player
player->changeItemData( playerData, NoDirection, "way in teletransport" );
// restore original orientation
player->changeDirection( player->getOrientation() );
player->changeItemData( playerData, "way in teletransport" );

activity = Wait;
}
Expand All @@ -425,10 +421,9 @@ void UserControlled::wayOutTeletransport( PlayerItem * player )
switch ( activity )
{
case BeginWayOutTeletransport:
// preserve orientation of player
player->setOrientation( player->getDirection() );
// change to bubbles retaining player’s label
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "begin way out teletransport" );
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "begin way out teletransport" );

// begin teleportation
activity = WayOutTeletransport;
break;
Expand Down Expand Up @@ -457,7 +452,7 @@ void UserControlled::collideWithMortalItem( PlayerItem* player )
if ( player->getShieldTime() == 0 )
{
// change to bubbles retaining player’s label
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "collide with mortal item" );
player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "collide with mortal item" );

activity = Vanish;
}
Expand Down

0 comments on commit f3c627c

Please sign in to comment.