onut::Entity* LevelGenerator::createRoom(int startX, int startY, const sRoom& room) { auto pRoomEntity = new onut::Entity(); pRoomEntity->setPosition({static_cast<float>(startX), static_cast<float>(startY), 0.f}); // Create floor. 5x5 for (int y = 0; y < room.h; ++y) { for (int x = 0; x < room.w; ++x) { const auto& tileId = room.tiles[(room.h - y - 1) * room.w * 2 + x * 2]; const auto& modifier = room.tiles[(room.h - y - 1) * room.w * 2 + x * 2 + 1]; onut::Entity* pEntity = nullptr; // Solid if (isWall(tileId)) { pEntity = onut::EntityFactory::createMesh({static_cast<float>(x), static_cast<float>(y), 0.f}, "assets/meshes/wall1.mesh", "assets/materials/wall1.material"); } else if (isFloor(tileId)) { if (onut::randb(.04f)) { pEntity = onut::EntityFactory::createMesh({static_cast<float>(x), static_cast<float>(y), 0.f}, "assets/meshes/floor2.mesh", "assets/materials/floor2.material"); } else { pEntity = onut::EntityFactory::createMesh({static_cast<float>(x), static_cast<float>(y), 0.f}, "assets/meshes/floor.mesh", "assets/materials/floor.material"); } } // Addons if (pEntity) { if (isTorch(tileId) && onut::randb(.85f)) { pEntity->add(createTorch({0.f, 0.75f})); } pEntity->setRotation({0, 0, getAngle(modifier)}); } pRoomEntity->add(pEntity); } } return pRoomEntity; }
WorldItem ItemCreator::createSmallItem(int quality, RandomMachine& random) { WorldItem item; int val = random.getInt() & 127; if(val < 40) { return createAntiDepressant(quality, random); } else if(val < 80) { return createMediKit(quality, random); } else { return createTorch(quality, random); } }