Exemplo n.º 1
0
VariablesGrid VariablesGrid::getTimeSubGrid(	double startTime,
												double endTime
												) const
{
    uint startIdx = getCeilIndex( startTime );
	uint endIdx   = getFloorIndex( endTime );

	VariablesGrid newVariablesGrid;

	if ( ( isInInterval( startTime ) == BT_FALSE ) || ( isInInterval( endTime ) == BT_FALSE ) )
		return newVariablesGrid;
	
	if ( ( startIdx >= getNumPoints( ) ) || ( endIdx >= getNumPoints( ) ) )
		return newVariablesGrid;

// 	if ( startIdx > endIdx )
// 		return newVariablesGrid;
	
	// add all matrices in interval (constant interpolation)
	if ( ( hasTime( startTime ) == BT_FALSE ) && ( startIdx > 0 ) )
		newVariablesGrid.addMatrix( *(values[ startIdx-1 ]),startTime );
	
	for( uint i=startIdx; i<=endIdx; ++i )
		newVariablesGrid.addMatrix( *(values[i]),getTime( i ) );
	
	if ( hasTime( endTime ) == BT_FALSE )
		newVariablesGrid.addMatrix( *(values[ endIdx ]),endTime );

    return newVariablesGrid;
}
Exemplo n.º 2
0
bool MoveEnemiesCommand::performWithSuccess(GameLoop* gameLoop)
{
	PrintHelper::clearScreen();

	CompassCommand compass;

	auto playerRoom = gameLoop->getGame()->getPlayer()->getCurrentRoom();
	auto floorIndex = playerRoom->getFloorIndex();
	auto dungeon = gameLoop->getGame()->getDungeon();
	auto stairRoom = compass.shortestPathAlgorithm(playerRoom, gameLoop->getGame()->getDungeon());

	list<Room*> rooms;
	Room* room;
	std::vector<Pokemon*>* pokemon = nullptr;

	std::cout << "All the pokemon in the gungeon feel the urge to move to different locations..." << std::endl;

	if (stairRoom == nullptr)
	{
		std::cout << "But they decided to stay on their current positions, since they can't block your path to the next stairs down, since there are none." << std::endl;
	}
	else
	{
		rooms = compass.getShortestPath(stairRoom, playerRoom);

		if (rooms.size() > 0)
		{
			size_t roomCounter = 0;
			std::list<Room*>::iterator roomIterator;

			for (auto x = 0; x < dungeon->getWidth(); ++x)
			{
				for (auto y = 0; y < dungeon->getHeight(); ++y)
				{
					room = dungeon->getRoom(x, y, floorIndex);

					if (std::find(rooms.begin(), rooms.end(), room) != rooms.end())
					{
						continue;
					}

					pokemon = room->getPokemon();

					for (auto pokemonIt = pokemon->begin(); pokemonIt != pokemon->end(); ++pokemonIt)
					{
						roomIterator = rooms.begin();
						std::advance(roomIterator, roomCounter++);
						(*pokemonIt)->setCurrentRoom(*roomIterator);
						pokemonIt = pokemon->begin();
						
						if (roomCounter >= rooms.size())
						{
							roomCounter = 0;
						}

						if (pokemonIt == pokemon->end())
						{
							break;
						}
					}
				}
			}

			std::cout << "The Pokemon have moved to a location to block your path to the stairs to another level down." << std::endl;
		}
		else
		{
			std::cout << "The Pokemon can't possibly block your path to the stairs down, since you are already in that room." << std::endl;
		}
	}

	return true;

	return true;
}