Пример #1
0
 void TrapDoorUp::onFrameChanged(FrameChangeType frameChangeType)
 {
     ItemNode::onFrameChanged( frameChangeType );
     auto pos = getRoomBoundPosition();
     getLevel().findFloorSectorWithClampedPosition( pos );
     setCurrentRoom( pos.room );
 }
Пример #2
0
bool player::moveNextRoom()
{
    int choice;
    choice = currentRoom->chooseAdjacentRoom();     //Picks a random valid door

    if(choice == 1)
        setCurrentRoom(currentRoom->getNorth());
    if(choice == 2)
        setCurrentRoom(currentRoom->getEast());
    if(choice == 3)
        setCurrentRoom(currentRoom->getSouth());
    if(choice == 4)
        setCurrentRoom(currentRoom->getWest());

    return combat();        //combat() only returns false if player dies
}
Пример #3
0
        void SwingingBlade::onFrameChanged(FrameChangeType frameChangeType)
        {
            auto room = getCurrentRoom();
            auto sector = getLevel().findFloorSectorWithClampedPosition( getPosition().toInexact(), &room );
            setCurrentRoom( room );
            setFloorHeight( HeightInfo::fromFloor( sector, getPosition().toInexact(), getLevel().m_cameraController )
                                    .distance );

            ItemNode::onFrameChanged( frameChangeType );
        }
Пример #4
0
void DungeonGenerator::generateLevel(int floorIndex, Dungeon* dungeon, int width, int height, std::default_random_engine engine, int startRoomX, int startRoomY)
{
	RoomDescriptionGenerator roomDescriptionGenerator;

	for (auto x = 0; x < width; x++)
	{
		for (auto y = 0; y < height; y++)
		{
			dungeon->setRoom(new Room(floorIndex, x, y, roomDescriptionGenerator.getRandomDescription()), x, y, floorIndex);
		}
	}

	for (auto x = 0; x < width; x++)
	{
		for (auto y = 0; y < height; y++)
		{
			resetPossibleRandomDirections();

			if (x == 0)
			{
				removeFromPossibleRandomDirections(Direction::WEST);
			}
			else if (x == (width - 1))
			{
				removeFromPossibleRandomDirections(Direction::EAST);
			}

			if (y == 0)
			{
				removeFromPossibleRandomDirections(Direction::NORTH);
			}
			else if (y == (height - 1))
			{
				removeFromPossibleRandomDirections(Direction::SOUTH);
			}

			std::uniform_int_distribution<int> amountOfRoomsDistibution {1, static_cast<int>(possibleRandomDirections_ ->size())};
			Direction roomDirection;

			auto amountOfConnectedRooms = amountOfRoomsDistibution(engine);

			if (dungeon->getRoom(x, y, floorIndex)->getRoom(Direction::NORTH) != nullptr)
			{
				amountOfConnectedRooms--;
			}

			if (dungeon->getRoom(x, y, floorIndex)->getRoom(Direction::EAST) != nullptr)
			{
				amountOfConnectedRooms--;
			}

			if (dungeon->getRoom(x, y, floorIndex)->getRoom(Direction::SOUTH) != nullptr)
			{
				amountOfConnectedRooms--;
			}

			if (dungeon->getRoom(x, y, floorIndex)->getRoom(Direction::WEST) != nullptr)
			{
				amountOfConnectedRooms--;
			}

			for (auto i = 0; i < amountOfConnectedRooms; i++)
			{
				do
				{
					roomDirection = possibleRandomDirections_->at(amountOfRoomsDistibution(engine) - 1);
				}
				while (dungeon->getRoom(x, y, floorIndex)->getRoom(roomDirection) != nullptr);

				dungeon->createDirection(x, y, floorIndex, roomDirection);
			}
		}
	}

	std::uniform_int_distribution<int> xDistribution { 0, (width - 1) };
	std::uniform_int_distribution<int> yDistribution { 0, (height - 1) };

	auto finishRoomX = xDistribution(engine);
	auto finishRoomY = yDistribution(engine);

	if (floorIndex <= 0)
	{
		dungeon->setStartRoom(dungeon->getRoom(finishRoomX, finishRoomY, floorIndex));
	}

	if (floorIndex > 0)
	{
		while (startRoomX == finishRoomX && startRoomY == finishRoomY)
		{
			finishRoomX = xDistribution(engine);
			finishRoomY = yDistribution(engine);
		}

		dungeon->getRoom(finishRoomX, finishRoomY, floorIndex - 1)->setRoom(Direction::DOWN, dungeon->getRoom(finishRoomX, finishRoomY, floorIndex));
		dungeon->getRoom(finishRoomX, finishRoomY, floorIndex)->setRoom(Direction::UP, dungeon->getRoom(finishRoomX, finishRoomY, floorIndex - 1));
	}

	if (floorIndex < (MAX_DUNGEON_LEVEL - 1))
	{
		int nPokemon = static_cast<int>((dungeon->getWidth() * dungeon->getHeight()) * POKEMON_PER_ROOM);
		Pokemon* pokemon = nullptr;

		for (auto counter = 0; counter < nPokemon; ++counter)
		{
			pokemon = pokemonGenerator_->getRandomPokemon();

			if (pokemon != nullptr)
			{
				pokemon->levelUpTo(floorIndex + 1);
				pokemon->setCurrentRoom(dungeon->getRoom(xDistribution(engine), yDistribution(engine), floorIndex));
			}
		}

		auto nItems =static_cast<int>((dungeon->getWidth() * dungeon->getHeight()) * ITEMS_PER_ROOM);

		for (auto counter = 0; counter < nItems; ++counter)
		{
			dungeon->getRoom(xDistribution(engine), yDistribution(engine), floorIndex)->addItem(itemGenerator_->getRandomItem());
		}

		auto nTraps = static_cast<int>((dungeon->getWidth() * dungeon->getHeight()) * TRAPS_PER_ROOM);

		Room* trapRoom;
		std::map<Direction, Trap*>* traps = nullptr;
		std::map<Direction, Room*> rooms;
		std::vector<Direction> directions;
		Direction randomDirection;
		bool setTrap;

		for (auto counter = 0; counter < nTraps; ++counter)
		{
			setTrap = false;

			do
			{
				trapRoom = dungeon->getRoom(xDistribution(engine), yDistribution(engine), floorIndex);
				traps = trapRoom->getTraps();
				rooms = trapRoom->getAccessableRooms();

				if (traps->size() < rooms.size())
				{
					directions.clear();

					for (auto i : rooms)
					{
						directions.push_back(i.first);
					}

					do
					{
						std::random_shuffle(directions.begin(), directions.end());
						randomDirection = directions.at(0);
					} while (traps->count(randomDirection) > 0);

					trapRoom->setTrap(randomDirection, trapGenerator_->getRandomTrap());
					setTrap = true;
				}
			} while (!setTrap);
		}

		generateLevel(++floorIndex, dungeon, width, height, engine, finishRoomX, finishRoomY);
	}
	else
	{
		auto mewXLoc = xDistribution(engine);
		auto mewYLoc = yDistribution(engine);

		int mewtwoXLoc;
		int mewtwoYLoc;

		do
		{
			mewtwoXLoc = xDistribution(engine);
			mewtwoYLoc = yDistribution(engine);
		}
		while (mewXLoc == mewtwoXLoc && mewYLoc == mewtwoYLoc);

		auto boss1 = pokemonGenerator_->getBoss(0);
		auto boss2 = pokemonGenerator_->getBoss(1);

		boss1->levelUpTo(BOSS_LEVEL);
		boss2->levelUpTo(BOSS_LEVEL);

		dungeon->getRoom(mewtwoXLoc, mewtwoYLoc, floorIndex)->setBoss(boss1);
		boss1->setCurrentRoom(dungeon->getRoom(mewtwoXLoc, mewtwoYLoc, floorIndex));
		dungeon->getRoom(mewXLoc, mewYLoc, floorIndex)->setBoss(boss2);
		boss2->setCurrentRoom(dungeon->getRoom(mewXLoc, mewYLoc, floorIndex));
	}
}