Exemplo n.º 1
0
 void generateLevels()
 {
     levels_ = std::vector<Level>( 100 );
     for( std::size_t i = 0 ; i < 100 ; i++ )
     {
         Level level;
         for( std::size_t ii = 0 ; ii < 50000 ; ii++ )
         {
             makeRoomSilentlyFail( level );
             if( level.rooms.size() == 99 )
             {
                 break;
             }
         }
         level.fillTiles();
         levels_.push_back( level );
     }
 }
Exemplo n.º 2
0
void BarycenterHeuristic::call (Level &L)
{
	const Hierarchy& H = L.hierarchy();

	for (int i = 0; i <= L.high(); ++i) {
		node v = L[i];
		long sumpos = 0L;
    
		const Array<node> &adjNodes = L.adjNodes(v);
		for(int j = 0; j <= adjNodes.high(); ++j)
			sumpos += H.pos(adjNodes[j]);

		m_weight[v] = (adjNodes.high() < 0) ? 0.0 :
			double(sumpos) / double(adjNodes.size());
	}
	
	L.sort(m_weight);
}
  void BlockedCoarseMapFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level &currentLevel) const {
    this->Input(currentLevel, "Aggregates");
    this->Input(currentLevel, "Nullspace");

    // Get CoarseMap from previously defined block
    RCP<const FactoryBase> prevCoarseMapFact = this->GetFactory("CoarseMap");
    TEUCHOS_TEST_FOR_EXCEPTION(prevCoarseMapFact==Teuchos::null, Exceptions::RuntimeError, "MueLu::BlockedCoarseMapFactory::getDomainMapOffset: user did not specify CoarseMap of previous block. Do not forget to set the CoarseMap factory.");
    currentLevel.DeclareInput("CoarseMap", prevCoarseMapFact.get(), this); // --
  }
Exemplo n.º 4
0
Arquivo: save.cpp Projeto: kekimmo/tuk
void save_level (FILE* file, const Level& level) {
  fprintf(file, "Level: %d x %d\n", level.w, level.h);
  for (int y = 0; y < level.h; ++y) {
    for (int x = 0; x < level.w; ++x) {
      save_tile(file, level.tile(x, y));
    }
    fprintf(file, "\n");
  }
}
Exemplo n.º 5
0
void UserAggregationFactory<LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level &currentLevel) const {
  FactoryMonitor m(*this, "Build", currentLevel);

  const ParameterList & pL = GetParameterList();

  RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
  const int myRank = comm->getRank();

  std::string fileName = pL.get<std::string>("filePrefix") + toString(currentLevel.GetLevelID()) + "_" + toString(myRank) + "." + pL.get<std::string>("fileExt");
  std::ifstream ifs(fileName.c_str());
  if (!ifs.good())
    throw Exceptions::RuntimeError("Cannot read data from \"" + fileName + "\"");

  LO numVertices, numAggregates;
  ifs >> numVertices >> numAggregates;

  // FIXME: what is the map?
  Xpetra::UnderlyingLib  lib       = Xpetra::UseEpetra;
  const int              indexBase = 0;
  RCP<Map> map = MapFactory::Build(lib, numVertices, indexBase, comm);

  RCP<Aggregates> aggregates = rcp(new Aggregates(map));
  aggregates->setObjectLabel("User");

  aggregates->SetNumAggregates(numAggregates);

  Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
  Teuchos::ArrayRCP<LO> procWinner   = aggregates->GetProcWinner()  ->getDataNonConst(0);

  for (LO i = 0; i < numAggregates; i++) {
    int aggSize = 0;
    ifs >> aggSize;

    std::vector<LO> list(aggSize);
    for (int k = 0; k < aggSize; k++) {
      // FIXME: File contains GIDs, we need LIDs
      // for now, works on a single processor
      ifs >> list[k];
    }

    // Mark first node as root node for the aggregate
    aggregates->SetIsRoot(list[0]);

    // Fill vertex2AggId and procWinner structure with information
    for (int k = 0; k < aggSize; k++) {
      vertex2AggId[list[k]] = i;
      procWinner  [list[k]] = myRank;
    }
  }

  // FIXME: do the proper check whether aggregates cross interprocessor boundary
  aggregates->AggregatesCrossProcessors(false);

  Set(currentLevel, "Aggregates", aggregates);

  GetOStream(Statistics0, 0) << aggregates->description() << std::endl;
}
Exemplo n.º 6
0
void Season::initLevels(int startLevel) {
    clearLevelData();

    QuestionSet* q = g_SeasonQuestions[m_id];
    int qCount = q->count();
    int levelCount = qCount / MAX_LEVEL_QUESTION_COUNT+ ((qCount % MAX_LEVEL_QUESTION_COUNT) ? 1 : 0);
    for (int i = 0; i < levelCount; i++) {
        Level* level = new Level(i+startLevel, m_id);
        int start = i * MAX_LEVEL_QUESTION_COUNT;
        int end = start + MAX_LEVEL_QUESTION_COUNT;
        for ( int j = start; j < end && j < qCount; j++) {
            level->addQuestion(q->question(j));
        }
        if (level->level() == 1)
            level->unlock();
        m_levels.insert(pair<int, Level*>(level->level(), level));
    }
}
Exemplo n.º 7
0
void BlockedPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::DeclareInput(Level &fineLevel, Level &coarseLevel) const {
  Input(fineLevel, "A");
  //fineLevel.DeclareInput("A",AFact_.get(),this);

  //Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));

  std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
  for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
    SetFactoryManager fineSFM  (rcpFromRef(fineLevel),   *it);
    SetFactoryManager coarseSFM(rcpFromRef(coarseLevel), *it);

    if (!restrictionMode_)
      coarseLevel.DeclareInput("P",(*it)->GetFactory("P").get(), this);
    else
      coarseLevel.DeclareInput("R",(*it)->GetFactory("R").get(), this);
  }

}
  void UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel) const {
    Input(currentLevel, "Graph");
    Input(currentLevel, "DofsPerNode");

    const ParameterList& pL = GetParameterList();

    // request special data necessary for OnePtAggregationAlgorithm
    std::string mapOnePtName = pL.get<std::string>("OnePt aggregate map name");
    if (mapOnePtName.length() > 0) {
      std::string mapOnePtFactName = pL.get<std::string>("OnePt aggregate map factory");
      if (mapOnePtFactName == "" || mapOnePtFactName == "NoFactory") {
        currentLevel.DeclareInput(mapOnePtName, NoFactory::get());
      } else {
        RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
        currentLevel.DeclareInput(mapOnePtName, mapOnePtFact.get());
      }
    }
  }
  void BraessSarazinSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel) const {
    this->Input(currentLevel, "A");

    TEUCHOS_TEST_FOR_EXCEPTION(FactManager_.is_null(), Exceptions::RuntimeError,
                               "MueLu::BraessSarazinSmoother::DeclareInput: FactManager_ must not be null! "
                               "Introduce a FactoryManager for the SchurComplement equation.");

    // carefully call DeclareInput after switching to internal FactoryManager
    {
      SetFactoryManager currentSFM(rcpFromRef(currentLevel), FactManager_);

      // request "Smoother" for current subblock row.
      currentLevel.DeclareInput("PreSmoother", FactManager_->GetFactory("Smoother").get());

      // request Schur matrix just in case
      currentLevel.DeclareInput("A", FactManager_->GetFactory("A").get());
    }
  }
  void RebalanceMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(Level &level) const {
    FactoryMonitor m(*this, "Build", level);

    //Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));

    // extract data from Level object
    const Teuchos::ParameterList & pL = GetParameterList();
    std::string mapName = pL.get<std::string> ("Map name");
    Teuchos::RCP<const FactoryBase> mapFactory = GetFactory ("Map factory");

    RCP<const Import> rebalanceImporter = Get<RCP<const Import> >(level, "Importer");

    if(rebalanceImporter != Teuchos::null) {
      // input map (not rebalanced)
      RCP<const Map> map = level.Get< RCP<const Map> >(mapName,mapFactory.get());

      // create vector based on input map
      // Note, that the map can be a part only of the full map stored in rebalanceImporter.getSourceMap()
      RCP<Vector> v = VectorFactory::Build(map);
      v->putScalar(1.0);

      // create a new vector based on the full rebalanceImporter.getSourceMap()
      // import the partial map information to the full source map
      RCP<const Import> blowUpImporter = ImportFactory::Build(map, rebalanceImporter->getSourceMap());
      RCP<Vector> pv = VectorFactory::Build(rebalanceImporter->getSourceMap());
      pv->doImport(*v,*blowUpImporter,Xpetra::INSERT);

      // do rebalancing using rebalanceImporter
      RCP<Vector> ptv = VectorFactory::Build(rebalanceImporter->getTargetMap());
      ptv->doImport(*pv,*rebalanceImporter,Xpetra::INSERT);

      if (pL.get<bool>("repartition: use subcommunicators") == true)
        ptv->replaceMap(ptv->getMap()->removeEmptyProcesses());

      // reconstruct rebalanced partial map
      Teuchos::ArrayRCP< const Scalar > ptvData = ptv->getData(0);
      std::vector<GlobalOrdinal> localGIDs;  // vector with GIDs that are stored on current proc

      for (size_t k = 0; k < ptv->getLocalLength(); k++) {
        if(ptvData[k] == 1.0) {
          localGIDs.push_back(ptv->getMap()->getGlobalElement(k));
        }
      }

      const Teuchos::ArrayView<const GlobalOrdinal> localGIDs_view(&localGIDs[0],localGIDs.size());

      Teuchos::RCP<const Map> localGIDsMap = MapFactory::Build(
          map->lib(),
          Teuchos::OrdinalTraits<int>::invalid(),
          localGIDs_view,
          0, ptv->getMap()->getComm());  // use correct communicator here!

      // store rebalanced partial map using the same name and generating factory as the original map
      // in the level class
      level.Set(mapName, localGIDsMap, mapFactory.get());
    }
  } //Build()
Exemplo n.º 11
0
void InterlevelScene::restore()
{
	Actor::fixTime();
	
	GameLog::wipe();
	
	Dungeon::loadGame(StartScene::curClass);
	if (Dungeon::depth == -1) 
	{
		Dungeon::depth = Statistics::deepestFloor;
		Dungeon::switchLevel(Dungeon::loadLevel(StartScene::curClass), -1);
	}
	else 
	{
		Level* level = Dungeon::loadLevel(StartScene::curClass);
		Dungeon::switchLevel(level, Level::resizingNeeded ? level->adjustPos(Dungeon::hero->pos) : Dungeon::hero->pos);
	}
}
Exemplo n.º 12
0
int main(int argc, char** argv) {
	
	sf::RenderWindow App(sf::VideoMode(1280,720),"Savage Heat: A bit Harder than the Corps");
	App.setFramerateLimit(60);
	//App.setVerticalSyncEnabled(true);
	BulletTracker bulletList;
	sf::Texture tex = loadImage("Images/Player1.bmp");
	sf::Texture tex2 = loadImage("Images/Bullet2.bmp");
	sf::Clock clock;
	Level disLevel;
	Player p1(tex,tex2);
	p1.name = "Player 1";
	
	
	while(App.isOpen()){
		sf::Event event;
		sf::Time time = clock.restart();
		float elapsed = time.asSeconds();
		
		while(App.pollEvent(event)){
			if(event.type == sf::Event::Closed){
				App.close();
			}
			if(event.type == sf::Event::KeyPressed){
				if(event.key.code == sf::Keyboard::F11){
					
				}
				if(event.key.code == sf::Keyboard::Escape){
					App.close();
				}
			}
		}
		
		p1.update((1.f/60.f)/*elapsed*/, disLevel, bulletList);
		bulletList.update((1.f/60.f)/*elapsed*/);
		disLevel.updateView(p1.Sprite, (1.f/60.f)/*elapsed*/);
		App.setView(disLevel.playerView);
		App.clear();
		disLevel.drawLevel(App,p1.Sprite);
		bulletList.draw(App);
		App.draw(p1.Sprite);
		App.display();
	}	
}
Exemplo n.º 13
0
void PoolSnapshot::CreateFromCurrentState()
{
  // Get the state of all game objects in the current room.
  Level* pLevel = LevelServer::Instance()->GetCurrentLevel().GetPtr();
  int levelId = pLevel->GetId(); 
  int roomId = pLevel->GetRoomId();

  GameObjectMap& objs = Engine::Instance()->GetGameObjects(levelId, roomId);
  // Iterate through map of Game Objects.  
  for (GameObjectMap::iterator it = objs.begin(); it != objs.end(); ++it)
  {
    PPoolGameObject pGo = it->second; 
    Assert(pGo.GetPtr());

#ifdef UNDO_DEBUG
if (gameObjId == 10)
  std::cout << "** UNDO: Storing cue ball: pos is " 
    << ToString(*(pGo->GetOrientation()))
    << "\n";
#endif

    ObjInfo info;
    info.m_pGo = pGo;
    if (pGo->GetOrientation())
    {
      info.m_or = *(pGo->GetOrientation());
    }
    info.m_state = pGo->GetState();

    m_objInfo.push_back(info);
  }

  // No of ball spotted by each player
  int numPlayers = Engine::Instance()->GetGameState()->GetNumberOfPlayers();
  for (int i = 0; i < numPlayers; i++)
  {
    m_playerInfo.push_back(
      *(Engine::Instance()->GetGameState()->GetPlayerInfo(i)));
  }  

  // Store the state of the Rules - like is this a free ball, can the
  // ball be placed anywhere, etc.
  m_pRules = GetRules(pLevel)->Clone();
}
Exemplo n.º 14
0
void WorldGenerator::genLevel( Level& level, LevelGenerationRanges& ranges, uint seed, float blockDimension, XMFLOAT3& spawn )
{
    mRand.seed( seed );

    //Generate number of rooms that will exist in the level and allocate space for it
    int roomCount = ranges.roomCount.gen( mRand );
    Room* rooms = new Room[ roomCount ];

    mLevelRanges = &ranges;

    //Gen the rooms that make up the level
    genLevelBlueprint( level, rooms, (short)(roomCount) );

    //Set the first room to empty
    rooms[0].type = Room::Type::Empty;
    
    //For each room, do a pass generating the heights, furniture, containers, and walls
    //for(int i = 0; i < roomCount; i++){
        //genLevelRoomHeights( level, rooms[i] );
    //}

    //Do a pass on each room, generating each of the following
    for(int i = 0; i < roomCount; i++){    
        genLevelRoomWalls( level, rooms[i] );
        genLevelRoomFurniture( level, rooms[i], blockDimension );
        genLevelRoomContainers( level, rooms[i], blockDimension );
        genLevelRoomLights( level, rooms[i] );
    }

    LOG_INFO << "Generated Level: " << level.getWidth() << ", " << level.getDepth() << LOG_ENDL;
    LOG_INFO << "Level has " << roomCount << " rooms " << LOG_ENDL;

    //Set the spawn point
    for(int i = 0; i < ROOM_MAX_DOORS; i++){
        if( rooms[0].doors[i].essential ){
            spawn.x = static_cast<float>(rooms[0].doors[i].x) * blockDimension;
            spawn.y = 0.0f;
            spawn.z = static_cast<float>(rooms[0].doors[i].y) * blockDimension; 
        }
    }

    delete[] rooms;
    rooms = NULL;
}
Exemplo n.º 15
0
void PlayerCamera::Update( float dt, Player& player, Input& input, Level& level )
{
	int newPosX = 0,
		newPosY = 0;

	//if(input.GetMouseButtonState(4))
	//{
	//	m_zoomLevel += 1;
	//}
	//if(input.GetMouseButtonState(5))
	//{
	//	m_zoomLevel -= 1;
	//}

	// Sets the camera to always be in the center of the screen where the player is
	newPosX = player.GetPosition().x - (m_screenWidth / 2) + 
		((player.GetWidth() / 2) * (player.GetScale() * m_zoomLevel));
	newPosY = player.GetPosition().y - (m_screenHeight / 2) + 
		((player.GetHeight() / 2) * (player.GetScale() * m_zoomLevel));

	m_posX = Lerp(m_posX, newPosX, 0.07f);
	m_posY = Lerp(m_posY, newPosY, 0.07f);

	//Restrict to the level
	if(m_posX >= (level.GetMapSize()*32) - (m_screenWidth))
	{
		m_posX = (level.GetMapSize()*32) - (m_screenWidth);
	}
	if(m_posX <= 0)
	{
		m_posX = 0;
	}
	if(m_posY >= (level.GetMapSize()*32) - (m_screenHeight))
	{
		m_posY = (level.GetMapSize()*32) - (m_screenHeight);
	}
	if(m_posY <= 0)
	{
		m_posY = 0;
	}


	Camera::Update(dt);
}
Exemplo n.º 16
0
void Stairs::Update(Level& level, const sf::Time& timePassed)
{
	if(IsActive()) {
		//The beginning of the end...
		level.SetLevelTransition(nextLevel, nextSpawn);
		isActive = false;
	}

	PlayAnim("idle", timePassed);
}
Exemplo n.º 17
0
    void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage, dvector& detections) const
    {
        float detectionScore = 0.f;

        const Octave& octave = *(level.octave);

        int stBegin = octave.index * octave.weaks, stEnd = stBegin + octave.weaks;

        for(int st = stBegin; st < stEnd; ++st)
        {
            const Weak& weak = weaks[st];

            int nId = st * 3;

            // work with root node
            const Node& node = nodes[nId];
            const Feature& feature = features[node.feature];

            cv::Rect scaledRect(feature.rect);

            float threshold = level.rescale(scaledRect, node.threshold, (int)(feature.channel > 6)) * feature.rarea;
            float sum = storage.get(feature.channel, scaledRect);
            int next = (sum >= threshold)? 2 : 1;

            // leaves
            const Node& leaf = nodes[nId + next];
            const Feature& fLeaf = features[leaf.feature];

            scaledRect = fLeaf.rect;
            threshold = level.rescale(scaledRect, leaf.threshold, (int)(fLeaf.channel > 6)) * fLeaf.rarea;
            sum = storage.get(fLeaf.channel, scaledRect);

            int lShift = (next - 1) * 2 + ((sum >= threshold) ? 1 : 0);
            float impact = leaves[(st * 4) + lShift];

            detectionScore += impact;

            if (detectionScore <= weak.threshold) return;
        }

        if (detectionScore > 0)
            level.addDetection(dx, dy, detectionScore, detections);
    }
Exemplo n.º 18
0
void Player::updateLevelFromExperience(const Level& level, bool updatePoints)
{
	auto oldLevel = currentLevel;
	currentLevel = level.getLevelFromExperience(experience);
	expNextLevel = level.getExperienceFromLevel(currentLevel);
	if (updatePoints == true &&
		currentLevel > oldLevel &&
		oldLevel != 0)
	{
		lifeDamage = 0;
		manaDamage = 0;
		Number32 levelUp;
		if (getNumberByHash(ItemProp::LevelUp, {}, levelUp) == true)
		{
			points += levelUp.getUInt32() * (currentLevel - oldLevel);
			queueAction(*class_, str2int16("levelChange"));
		}
	}
}
Exemplo n.º 19
0
/**
	Wykrywanie kolizji AABB
*/
bool Entity::isAnyFieldBelowMe(Level &lvl){

	int curr_x_tile = _xOnMap / mapSpace::tileWidth;
	int curr_y_tile = _y / mapSpace::tileHeight;
    for (int x = 0; x < 2; ++x) {

        if (lvl.field(curr_x_tile + x, curr_y_tile + 1 + _upgrade) == mapSpace::none) 
            continue;

        Aabb fieldAabb = lvl.getFieldAabb(curr_x_tile + x, curr_y_tile + 1 + _upgrade);

        if (getNextVerticalAabb().isOver(fieldAabb)){
            _y = fieldAabb._minY - (tileHeight + tileHeight * _upgrade -3 );
			return true;
		}

    }
    return false;
};
void GameState_BasePlayable::SaveStuff (GameObject* entity, Level& level) {
	Level_WorldObj* plStuff = level.add_stuff();


	Level_Vector2D* plStuffPos = plStuff->mutable_pos();
	plStuffPos->set_x(entity->GetPosition().x);
	plStuffPos->set_y(entity->GetPosition().y);

	plStuff->set_type(ConvertType(entity->entityType));
}
 void ToggleCoordinatesTransferFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& fineLevel, Level& coarseLevel) const {
   const ParameterList& pL = GetParameterList();
   TEUCHOS_TEST_FOR_EXCEPTION(!pL.isParameter("Chosen P"), Exceptions::RuntimeError, "MueLu::ToggleCoordinatesTransferFactory::DeclareInput: You have to set the 'Chosen P' parameter to a factory name of type TogglePFactory. The ToggleCoordinatesTransferFactory must be used together with a TogglePFactory!");
   Input(coarseLevel,"Chosen P");
   for (std::vector<RCP<const FactoryBase> >::const_iterator it = coordFacts_.begin(); it != coordFacts_.end(); ++it) {
     coarseLevel.DeclareInput("Coordinates", (*it).get(), this);  // request/release coarse coordinates
     (*it)->CallDeclareInput(coarseLevel); // request dependencies
   }
   hasDeclaredInput_ = true;
 }
Exemplo n.º 22
0
Gravitation::Gravitation(sf::Sprite sp, Level &lev, float dx, float dy, int W, int H, float X, float Y, float t) {
	object = lev.GetAllObjects();
	dx = 0;
	dy = 0;
	sprite = sp;
	time = t;
	w = W; h = H;
	x = X; y = Y;
	sprite.setTextureRect(sf::IntRect(0, 0, w, h));
}
Exemplo n.º 23
0
Enemy::Enemy(Image &image, Level &level, float X, float Y,
             float Width, float Height):
    Subject(image, X, Y, Width, Height)
{
    obj = level.GetAllObjects();
    sprite.setTextureRect(IntRect(0, 0, width, height));
    speed = 0.08;
    speed_x = 0.08;
    stateEnemy = true;//1- right, 0-left
}
Exemplo n.º 24
0
void MedianHeuristic::call (Level &L)
{
	const HierarchyLevels &levels = L.levels();

	for (int i = 0; i <= L.high(); ++i) {
		node v = L[i];

		const Array<node> &adjNodes = L.adjNodes(v);
		const int high = adjNodes.high();

		if (high < 0) m_weight[v] = 0;
		else if (high & 1)
			m_weight[v] = levels.pos(adjNodes[high/2]) + levels.pos(adjNodes[1+high/2]);
		else
			m_weight[v] = 2*levels.pos(adjNodes[high/2]);
	}

	L.sort(m_weight,0,2*levels.adjLevel(L.index()).high());
}
Exemplo n.º 25
0
void GreedySwitchHeuristic::call (Level &L)
{
	m_crossingMatrix->init(L);
	int index;
	bool nolocalmin;

	do {
		nolocalmin = false;

		for (index = 0; index < L.size() - 1; index++)
			if ((*m_crossingMatrix)(index,index+1) > (*m_crossingMatrix)(index+1,index)) {

				nolocalmin = true;

				L.swap(index,index+1);
				m_crossingMatrix->swap(index,index+1);
			}
	} while (nolocalmin);
}
Exemplo n.º 26
0
	Bulet::Bullet(Image &image, String Name, Level &lvl,float X, float Y, int W, int H, int dir):Entity(image, Name, X, Y, W, H)//всё так же, только взяли в конце состояние игрока (int dir)
	{
		obj = lvl.GetObjects("solid");//инициализируем .получаем нужные объекты для взаимодействия пули с картой
		x = X;
		y = Y;
		direction = dir;
		speed = 0.8;
		w = h = 16;
		life = true;
	}//bullet
Exemplo n.º 27
0
//Start the ball moving using direction and power from GLUI input
void launchBall(int i){

    ballMoving = true;

    launchAngleRadians = (float) launchAngle * (PI/180);
    launchVector = normalize(vec3(sin(launchAngleRadians), 0.0, cos(launchAngleRadians)));

	Level *currentLevel = levelController->getCurrentLevel();
	Ball *ball = currentLevel->getBall();
	Physics *physics = ball->getPhysics();

	puttSFX(physics->getSpeed(), sound);

    float prevY = physics->getDirection().y;
    physics->setDirection(glm::vec3(launchVector.x, prevY, launchVector.z));

	// If new tile is flat make sure no y-component
    if(levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){
        physics->setDirection(
            glm::vec3(physics->getDirection().x, 0.0, physics->getDirection().z));
    }
    // If new tile is not flat add y-component
    else{
        glm::vec3 oldDirection = physics->getDirection();
        glm::vec3 upVector = glm::vec3(0.0,1.0,0.0);
        // Get current tile normal
        glm::vec3 tileNormal = levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0];
        glm::vec3 xVector = glm::cross(oldDirection, upVector);
        glm::vec3 newDirection = glm::normalize(glm::cross(tileNormal, xVector));
        physics->setDirection(newDirection);
    }

    physics->setSpeed(launchPower/100.1f);

	// Increment current hole score and update glui
	currentHoleScore++;
	numStrokes->set_int_val(currentHoleScore);

	angleSpinner->disable();
	powerSpinner->disable();
	fireButton->disable();
}
Exemplo n.º 28
0
bool GameOverLayer::initWithWon( bool won )
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)));

		CCString* message;
		if (won)
		{
			LevelManager::sharedInstance()->nextLevel();
			Level* curLevel = LevelManager::sharedInstance()->curLevel();
			if (curLevel)
			{
				message = CCString::createWithFormat("Get ready for level %d", curLevel->getLevelNum());
			}
			else
			{
				message = CCString::create("You Won!");
				LevelManager::sharedInstance()->reset();
			}
		}
		else
		{
			message = CCString::create("You Lose :[");
			LevelManager::sharedInstance()->reset();
		}

		CCSize winSize = CCDirector::sharedDirector()->getWinSize();
		CCLabelTTF* label = CCLabelTTF::create(message->getCString(), "Arial", 32);
		label->setColor(ccc3(0, 0, 0));
		label->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(label);

		this->runAction(CCSequence::create(CCDelayTime::create(3), 
			CCCallFunc::create(this, callfunc_selector(GameOverLayer::gameOverDone)), NULL));

		bRet = true;
	} while (false);

	return bRet;
}
void PermutationFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::DeclareInput(Level &currentLevel) const {
  Input(currentLevel, "A");

  const ParameterList & pL = GetParameterList();
  std::string mapName                        = pL.get<std::string> ("PermutationRowMapName");
  Teuchos::RCP<const FactoryBase> mapFactory = GetFactory          ("PermutationRowMapFactory");

  if(mapName.length() > 0 ) {
    currentLevel.DeclareInput(mapName,mapFactory.get(),this);
  }
}
Exemplo n.º 30
0
Game::~Game()
{
    m_timer->stop();
    QObject::disconnect(m_timer, SIGNAL(timeout()), this, SLOT(nextGameFrame()));
    delete m_timer;

    Level *level;
    while(m_levels.size())
    {
        level = m_levels.last();
        m_levels.removeLast();

        QObject::disconnect(level->player(), SIGNAL(pelletEaten()), this, SLOT(onPelletEaten()));
        QObject::disconnect(level->player(), SIGNAL(energizerEaten()), this, SLOT(onEnergizerEaten()));

        delete level;
    }

    delete m_shortSoundsPlayer;
}