void partition( const uint32_t depthToCreateTo, const uint32_t level ) {
        uint32_t leftWidth( boundary_.dimensions.w / 2 );
        uint32_t rightWidth( boundary_.dimensions.w - leftWidth );
        uint32_t bottomHeight( boundary_.dimensions.h / 2 );
        uint32_t topHeight( boundary_.dimensions.h - bottomHeight );
        uint32_t newLevel( level + 1 );

        uint32_t rightStartX( boundary_.ex - rightWidth );
        uint32_t topStartY( boundary_.ey - topHeight );

        leftBottomNode_ = make_unique<QuadTreeNode>( QuadTreeNode( depthToCreateTo,
                                                                   newLevel,
                                                                   vec4uint32 { boundary_.dimensions.x, boundary_.dimensions.y, leftWidth, bottomHeight } ) );

        rightBottomNode_ = make_unique<QuadTreeNode>( QuadTreeNode( depthToCreateTo,
                                                                    newLevel,
                                                                    vec4uint32 { rightStartX, boundary_.dimensions.y, rightWidth, bottomHeight } ) );

        leftTopNode_ = make_unique<QuadTreeNode>( QuadTreeNode( depthToCreateTo,
                                                                    newLevel,
                                                                    vec4uint32 { boundary_.dimensions.x, topStartY, leftWidth, topHeight } ) );

        rightTopNode_ = make_unique<QuadTreeNode>( QuadTreeNode( depthToCreateTo,
                                                                     newLevel,
                                                                     vec4uint32 { rightStartX, topStartY, rightWidth, topHeight } ) );
    }
Example #2
0
void KBounceGameWidget::mouseReleaseEvent( QMouseEvent* event )
{
    if ( event->button() & Qt::RightButton )
    {
        m_vertical = !m_vertical;
        setCursor( m_vertical ? Qt::SizeVerCursor : Qt::SizeHorCursor );
    }

    if ( event->button() & Qt::LeftButton )
    {
        if ( m_state == Running )
        {
            QPoint pos( event->pos().x() - m_board->pos().x(), event->pos().y() - m_board->pos().y() );
            m_board->buildWall( pos, m_vertical );
        }
        else if ( m_state == BetweenLevels )
        {
            newLevel();
        }
        else if ( m_state == BeforeFirstGame || m_state == GameOver )
        {
            newGame();
        }
    }
}
Example #3
0
void Environment::init(){

    std::cout << "Environment Initialisation" << std::endl;

    waitStart = true;
    //Load the level data
    dataLoader.loadLevelData(QString("Data/level")
                             + QString::number(level)
                             + QString(".data"));

    emit sendTotalTime(convertTime(dataLoader.getBestTime()));


    Fly* mouche = new Fly("Fly",7,dataLoader.getInitPos().first,dataLoader.getInitPos().second,15,15,1);

    entityMap.insert(mouche->getID(),mouche);

    flyID = mouche->getID();

    DM.setEM(entityMap);
    emit sendDM(DM);

    emit newLevel(level);

    connect(&timer,SIGNAL(timeout()),this,SLOT(run()));
    timer.start();

}
Example #4
0
void main(void) {
	// Clear Screen
	cpct_memset(SCR_VMEM, 0, 0x4000);
	initCPC();
	gameScene=CALIVGAMESSCREEN;
	//gameScene=MENUSCREEN;
	// Loop forever
	while (1) {
		switch (gameScene) {
		    case CALIVGAMESSCREEN: calivGames();
				break;
			case MENUSCREEN: mainMenu();
				break;
			case PLAYGAMESCREEN: infinityMode();
				break;
    		case NEXTLEVELSCREEN: newLevel();
	    		break;
			case CONTROLSSCREEN: controls();
				break;
		    case GAMEOVERSCREEN: gameOver();
				break;
			case CREDITSSCEENE: credits();
				break;
		}
	};
}
Example #5
0
Level::Level(int width, int height) {
	loadTextures();
	screenWidth = width;
	screenHeight = height;
	levelNo = 0;
	newLevel(levelNo);
	level = (void*) this;
}
Example #6
0
void Game::update(double aDelta)
{
  //Check to see if we need a new game level.
  if(newLevel() == true)
   {
	  //If we do increment the current game level.
      m_CurrentGameLevel++;
        
      //If it' set to the max level, set it to level 1.
      if (m_CurrentGameLevel > GAME_MAX_LEVEL)
      {
          ScreenManager::getInstance()->switchScreen(WIN_MENU_NAME);
           m_CurrentGameLevel = GAME_DEFAULT_LEVEL;
      }

	  //Reset the game.
      reset();
  }
    
  //If the GameOver Timer is greater that zero, countdown
  if(m_GameOverTimer > 0.0)
  {
    m_GameOverTimer -= aDelta;
    if(m_GameOverTimer < 0.0)
    {
      m_GameOverTimer = 0.0;
	  ScreenManager::getInstance()->switchScreen(GAME_OVER_MENU_NAME);
    }
    return;
  }

  //Cycle through all the game objects update them and check their collision detection
  for(int i = 0; i < m_GameObjects.size(); i++)
  {
    //Make sure the GameObject is active
    if(m_GameObjects.at(i)->getIsActive() == true)
    {
		//If AI is toggled, make the paddle follow the current active ball.
        if(m_AI)
        {
            m_Paddle->setX(m_ActiveBall->getX() - GAME_BRICK_BALL_OFFSET);
        }
        
      //Update the GameObject
      m_GameObjects.at(i)->update(aDelta);
      
      //Check collision detection against the ball
      if(m_GameObjects.at(i) != m_ActiveBall)
      {
          GameObject* gameObject = m_GameObjects.at(i);
          m_ActiveBall->checkCollision(gameObject);
      }
    }
  }
}
Example #7
0
void Game::levelUp(void) 
{
	level++;
	if(level % 5 == 0) {
		pacman->lives++;
	}
	if(speed > 100) {
		speed -= 20;
	}
	newLevel();
}
Example #8
0
void BScene::nextLevel()
{
    removeChild(levelLayer);
    removeChild(playerLayer);
    curLevel++;
    
    if (curLevel < menuLayer->getLevelCount())  //if there are no more levels
        newLevel(menuLayer->getLevelPath(curLevel));
    else
        addChild(menuLayer, 2);
}
Example #9
0
void KBounceGameWidget::newGame()
{
    closeGame();
    setCursor( m_vertical ? Qt::SizeVerCursor : Qt::SizeHorCursor );
    m_level = 1;
    m_score = 0;

    emit levelChanged( m_level );
    emit scoreChanged( m_score );
    
    newLevel();
}
Example #10
0
void MainWindow::nextLevel(){
	if(pauseMe == 20){
		// after a bit of time, start the new level
		timer2->stop();
		nextWave->hide();
		newLevel(++level);
		pauseMe = 0;
	}
	else{
		pauseMe++;
	}
}
Example #11
0
Game::Game(void)
{
	wallmanager = new Wallmanager();
	dot = new Dot();
	powerup = new Powerup();
	pacman = new Pacman();
	ambusher = new Ambusher();
	chaser = new Chaser();
	fickle = new Fickle();
	stupid = new Stupid();
	speed = 200;
	level = 1;
	score = 0;
	paused = false;
	initHeaders();
	newLevel();
}
Example #12
0
GameScreen::GameScreen(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GameScreen)
{
    ui->setupUi(this);
    tmp = new QMainWindow(this);
    paddleIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/paddle.png");
    ballIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/white_ball.png");
    gameOverIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/gameover.png");
    gameOverlay = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/background.jpg");
    gameWonIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/youwin.jpg");
    overlayLbl = new QLabel(this);
    overlayLbl->setPixmap(*gameOverlay);
    overlayLbl->setGeometry(0, ui->menuBar->height(), this->width() - (this->width() - ui->rightLine->pos().x()), this->height() - (this->height() - ui->bottomLine->pos().y()));

    connect(this, SIGNAL(eventTriggered(QString)), this, SLOT(writeEvent(QString)));
    connect(this, SIGNAL(gameEnded()), this, SLOT(gameOver()));

    diff = EASY;
    level = 1;
    newLevel(level);
    createActions();
    createMenus();
    createPaddle();
    createBall();
    numLives = 3;

    time = new Timer(this, "time");
    connect(time, SIGNAL(timeout()), this, SLOT(decrementTimer()));
    cheatModeActive = false;
    spacePressed = false;
    score = 0;
    createBlocks();
    eventLogFullSizePos = new QPoint(310, 10);
    eventLogHalfSizePos = new QPoint(310, 200);
    hideCheatMode();
    setLivesText(numLives);
    setTimeText(timeLeft);
    setLevelText(level);
    setScoreText(score);
}
Example #13
0
bool loadLevelFromFile(const char* filename)
{
	FILE* file = fopen(filename, "rt");

	unsigned int version;
	unsigned int crc32;

	sgLevel.filename = filename;

	if (!file)
	{
		if (between(sgLevel.size.x, 1, MAX_LEVEL_SIZE)
				&& between(sgLevel.size.y, 1, MAX_LEVEL_SIZE))
		{
			newLevel();
			return true;
		}
		else
		{
			fprintf(stderr, "can not open file: %s\n", filename);
			return false;
		}
	}

	/* version number */
	if (fscanf(file, "v%u", &version) != 1 || version > THIS_CGM_VERSION)
	{
		fprintf(stderr, "incompatible version number: %u\n", version);
		fclose(file);
		return false;
	}

	resetCRC32();

	/* read attributes */
	readFieldCoord(file, sgLevel.start);
	readFieldCoord(file, sgLevel.finish);
	readFieldCoord(file, sgLevel.size);

	if (version >= 4)
	{
		readString(file, sgLevel.author);
	}

	initLevel();

	/* reading data */
	if (version >= 4)
	{
		int countBlocks = readInt(file);

		for (int i = 0; i < countBlocks; ++i)
		{
			KdCell::Range range;
			int x;
			int y;

			{
				Block b;

				readFieldBlock(file, b);
				b.dirty = true;

				x = b.x;
				y = b.y;

				range.start = sgLevel.blocks.insert(b);
			}
			range.end = range.start + 1;

			sgLevel.kdLevelTree->get(x, y) = range;
		}
	}
	else
	{
		for (int x = 0; x < sgLevel.size.x; x++)
		{
			for (int y = 0; y < sgLevel.size.y; y++)
			{
				KdCell::Range& range = sgLevel.kdLevelTree->get(x, y);

				{
					Block b;

					b.x = x;
					b.y = y;
					readFieldBlockV3(file, b);
					b.dirty = true;

					range.start = sgLevel.blocks.insert(b);
				}
				range.end = range.start + 1;
			}
		}
	}

	sgLevel.crc32 = getCRC32();

	initCommon();

	if (version >= 2)
	{
		if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32())
		{
			fprintf(stderr, "1st checksum mismatch: %s\n", filename);
			fclose(file);
			return false;
		}

		{
			int cntSubLightMaps = sgAtlas->getCntAllocatedSubLightMaps();

			int index = 0;

			if (version >= 3)
			{
				while (index < cntSubLightMaps)
				{
					int dataInt[SIZEOF_LIGHT_MAP];

					readRLE(file, dataInt);

					toLightMap(index, false, dataInt);

					index++;
				}
			}
			else
			{
				importLightmapV2(file);
			}

			if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32())
			{
				fprintf(stderr, "2st checksum mismatch: %s\n", filename);
				fclose(file);
				return false;
			}
		}
	}
	else
	{
		updateLightMap();
	}

	fclose(file);

	if (!loadHighscoreFromFile())
	{
		sgLevel.cntScoreCols = 0;
	}

	sgLevel.saved = true;

	return true;
}
Example #14
0
void BScene::loadLevel(const int idx)
{
    removeChild(menuLayer);
    curLevel = idx;
    newLevel(menuLayer->getLevelPath(idx));
}
void GameLayer::update (float dt) {
    
    if (_gameState == kGameStatePlay) {
        
		//if running game logic
		if (_running) {
            
            
            _manager->update(dt);
            dt *= DT_RATE;
            
			//update elements
            _moon->update(dt);
            if (_sun->isVisible()) {
                _sun->update(dt);
                if (_sun->checkCollisionWithMoon(_moon)) {
                    SimpleAudioEngine::sharedEngine()->playEffect("sun_hit.wav");
                }
            }
            
			
			//check collision with lines, update, draw
			Line * line;
            int len = _manager->getLines()->count();
            bool collisionDetected = false;
			
			for (int i = len-1; i >= 0; i--) {
                
				line = (Line *) _manager->getLines()->objectAtIndex(i);
                
				if (!collisionDetected && line->getActive()) {
					if (line->collidesWithMoon(_moon)) {
						collisionDetected = true;
                        SimpleAudioEngine::sharedEngine()->playEffect("line_hit.wav");
                        _lineHitParticles->setPosition(line->getCollisionPoint());
                        _lineHitParticles->resetSystem();
					}
				}
                
				if (line->getTrashme()) {
                    _manager->getLines()->removeObjectAtIndex(i);
				} else {
                    line->update(dt);
                }
			}
            _moon->place();
            
            //if moon off screen to the top, make screen darker as moons gets farther and farther away
            if (_moon->getPositionY() > _screenSize.height) {
                if (!_sun->isVisible()) {
                    float opacity = fabs((255 * (_moon->getPositionY() - _screenSize.height))/_screenSize.height);
                    if (opacity > 200) opacity = 200;
                    if (!_sun->isVisible()) _bgDark->setOpacity ( 255 - opacity );
                }
            } else {
                if (!_sun->isVisible()) {
                    if (_bgDark->getOpacity() != 255) _bgDark->setOpacity ( 255 );
                }
            }
        
            
			//track collision with MOON and STAR (usign grid logic)
            float range = _moon->getRadius();
            float posX = _moon->getPositionX();
            float posY = _moon->getPositionY();
            
			//I decided to check 9 cells for precision sake
            clearStarAt(ccp(posX, posY));
            clearStarAt(ccp(posX, posY + range));
            clearStarAt(ccp(posX, posY - range));
            clearStarAt(ccp(posX + range, posY));
            clearStarAt(ccp(posX + range, posY + range));
            clearStarAt(ccp(posX + range, posY - range));
            clearStarAt(ccp(posX - range, posY));
            clearStarAt(ccp(posX - range, posY - range));
            clearStarAt(ccp(posX - range, posY + range));
            
            
            //update bars
            
            
            
			//check timer
			if (_manager->getTime()  <= 0.65f && !_sun->isVisible()) {
				SimpleAudioEngine::sharedEngine()->playEffect("sun_rise.wav");
                _sun->setVisible(true);
				_sun->setHasRisen(false);
			} else if (_manager->getTime() <= 0.25f && _sun->isVisible() && !_sun->getHasGrown()) {
                SimpleAudioEngine::sharedEngine()->playEffect("sun_grow.wav");
                _sun->highNoon();
            } else if (_manager->getTime() <= 0.0f) {
                //if you want game over once time runs out.
                //game;
            }
            
            if (_sun->isVisible()) {
                if (!_bgLight->isVisible()) {
                    _bgLight->setVisible(true);
                }
                //when sun is added to screen, fade out dark bg
                if (_bgLight->getOpacity() + 5  < 255) {
                    _bgLight->setOpacity(_bgLight->getOpacity() + 5 );
                    _bgDark->setOpacity (_bgDark->getOpacity() - 5);
                } else {
                    _bgDark->setVisible(false);
                    _bgDark->setOpacity(255);
                   _bgLight->setOpacity(255);
                }
                _sun->place();
			}
            
            //check power
            if (_manager->getLineEnergy() <= 0) {
                if (!_moon->getIsOff()) {
                    _moon->turnOnOff(false);
                }
            }
			
			//track collision between Moon and Moon's perch
			if (_starsCollected) {
                if (pow (_moonStartPoint.x - _moon->getPositionX(), 2) +
                    pow (_moonStartPoint.y - _moon->getPositionY(), 2) < _moon->getSquaredRadius()) {
					_moon->setPosition(_moonStartPoint);
                    _moon->setNextPosition(_moonStartPoint);
                    _moon->setActive(false);
					newLevel();					
				}
			}
            
            if (_moon->getPositionY() < _moon->getRadius() && _moon->getActive()) {
                _groundHitParticles->setPosition(_moon->getPosition());
                _groundHitParticles->resetSystem();
                SimpleAudioEngine::sharedEngine()->playEffect("ground_hit.wav");
                _moon->setActive(false);
                gameOver();
            }
            
            //make stars blink
            if (!_sun->isVisible()) {
                _starsUpdateTimer += dt;
                int stars_count = _numStars;
                if (_starsUpdateTimer > _starsUpdateInterval) {
                    
                    if (stars_count - _starsUpdateIndex < _starsUpdateRange) {
                        _starsUpdateIndex = 0;
                    } else if (_starsUpdateIndex + _starsUpdateRange > stars_count - 1) {
                        _starsUpdateIndex += stars_count - _starsUpdateIndex - 1;
                    } else {
                        _starsUpdateIndex += _starsUpdateRange;
                    }
                    
                    _starsUpdateTimer = 0;
                    _starsUpdateInterval = ((float)rand() / RAND_MAX) * 5;
                }
                
                //update stars within update range
                Star * star;
                for (int i = _starsUpdateIndex; i < _starsUpdateIndex + _starsUpdateRange; i++) {
                    if (i < stars_count) {
                        CCPoint point = _manager->starPosition(i);
                        int index = point.y * _manager->getColumns() + point.x;
                        if (index >= STARS_IN_POOL) index = STARS_IN_POOL - 1;
                        
                        //identify cell in array
                        star = _manager->starFromPool(index);
                        if (star->isVisible() && !star->getIsBoost()) star->update(dt);
                    }
                    
                }
            }
            
		}
	}
}
Example #16
0
 /*--------------------------------------------------------------------------------
     Function    : Level::addLevel
     Description : Adds a new level of the given tileset to the level list.
     Inputs      : Name of a tileset
     Outputs     : None
     Return      : void
 --------------------------------------------------------------------------------*/
 void Level::addLevel(const string& tilesetName)
 {
     LevelPtr newLevel(new Level(tilesetName));
     Level::levels.push_back(newLevel);
 }
Example #17
0
void Level::finished() {
	delete cellList;
	delete enemies;
	delete friendlies;
	newLevel(levelNo + 1);
}
void Editor::keypress( SDL_KeyboardEvent &key )
{
	switch( key.keysym.sym )
	{
	case SDLK_h:
		m_showHelp = !m_showHelp;		
		break;
	case SDLK_F2:
		if (m_level) m_level->saveLevel( "_editorLevel.xml" );
		break;

	case SDLK_F3:
		delete m_level;
		m_level = new Cavern();
		m_level->loadLevel( "_editorLevel.xml", m_shapes );
		break;

	case SDLK_f:
		{
			if (!m_level) return;
			frameView();
		}
		break;
	case SDLK_TAB:
		 m_useEditView = !m_useEditView;
		 break;

	case SDLK_1:
		//newLevel( vec2f( 2400, 3000 ) );		
		newLevel( vec2f( 800, 1200 ) );		
		break;

	case SDLK_2:
		newLevel( vec2f( 4800, 6000 ) );		
		break;

	case SDLK_3:
		newLevel( vec2f( 9600, 12000 ) );		
		break;

	case SDLK_8:
		if (currSegType == SegType_COLLIDE) currSegType = SegType_KILL;
		else currSegType--;
		break;
	
	case SDLK_9:
		if (currSegType == SegType_KILL) currSegType = SegType_COLLIDE;
		else currSegType++;
		break;

	case SDLK_a:
		m_sort += 10;
		break;

	case SDLK_z:
		m_sort -= 10;
		break;

	case SDLK_s:
		m_sort += 1;
		break;

	case SDLK_x:
		m_sort -= 1;
		break;

	case SDLK_0:
		if (m_level) 
		{
			m_level->m_spawnPoint = m_mousePos;
			//printf("Spawn Pos: %f %f\n", 
			//	m_level->m_spawnPoint.x,
			//	m_level->m_spawnPoint.y );
		}
		break;

	case SDLK_COMMA:
		{
			delete m_activeShape;

			if (m_actShapeIndex > 0 ) m_actShapeIndex--;
			else m_actShapeIndex = m_shapes.size()-1;						

			Shape *newShape = new Shape();
			*newShape = *m_shapes[ m_actShapeIndex ];
			//printf("Current shape: %d %s\n", m_actShapeIndex, newShape->name.c_str() );

			m_activeShape = newShape;
		}
		break;
	
	case SDLK_PERIOD:
		{
			delete m_activeShape;
			
			if (m_actShapeIndex < m_shapes.size()-1 ) m_actShapeIndex++;
			else m_actShapeIndex = 0;
			
			Shape *newShape = new Shape();
			*newShape = *m_shapes[ m_actShapeIndex ];
			//printf("Current shape: %d %s\n", m_actShapeIndex, newShape->name.c_str() );
			m_activeShape = newShape;
		}
		break;	
	case SDLK_SPACE:
		stampActiveShape();		
		break;	
	
	case SDLK_RIGHTBRACKET:		
		m_activeShape->m_size *= 2.0;
		break;

	case SDLK_LEFTBRACKET:
		m_activeShape->m_size *= 0.5;
		break;

	case SDLK_o:
		m_activeShape->m_size *= 0.9;
		break;

	case SDLK_p:		
		m_activeShape->m_size *= 1.1;
		break;

	case SDLK_k:
		m_viewsize *= 0.75;
		break;

	case SDLK_l:
		m_viewsize *= 1.25;
		break;

	}
}
Example #19
0
void GameScreen::nextLevel()
{
    level++;
    newLevel(level);
}