Example #1
0
// End of round - Called when the round is over (when game timer runs out)
void Game::endOfRound()
{
    // Show end of round info
    char round[8];
    char score[16];
    snprintf(round, 32, "%d", currentRound);
    snprintf(score, 32, "%d", currentRoundScore);
    std::string title = "Round ";
    title += round;
    std::string msg = "Score: ";
    msg += score;
    if (currentRoundScore >= targetRoundScore)
    {
        title += " Complete";
        showInfoPanel(title.c_str(), msg.c_str());
        g_pAudio->PlaySound("audio/round_won.wav");
        // Move to next round number
        currentRound++;
    }
    else
    {
        title += " Failed";
        showInfoPanel(title.c_str(), msg.c_str());
        g_pAudio->PlaySound("audio/round_lost.wav");
    }

    // Change to round over game state
    changeGameState(roundOver);
}
Example #2
0
void Application::enterWorld(int worldNum)
{
	ASSERT(worldNum>=0 && worldNum<3,
    "Parameter \'worldNum\' is invalid: " + itoa(worldNum));

	ASSERT(worldNum<=unlockedWorld,
    "Parameter \'worldNum\' specifies a world that is currently locked: #"
    + itoa(worldNum) + " while only worlds #0 through #"
    + itoa(unlockedWorld) + "are unlocked.");

	const string worlds[] =
	{
		"data/zones/World1.xml",
		"data/zones/World2.xml",
		"data/zones/World3.xml"
	};

	const string &worldFileName = worlds[worldNum];

	if(world)
	{
		TRACE("Deleting the old World");
		delete world;
	}

	TRACE("Allocating a new World");
	world = new World;

	TRACE("Starting the game from file: " + worldFileName);
	world->loadFromFile(worldFileName);

	TRACE("Continuing game now");
	changeGameState(GAME_STATE_RUN);
}
void VictoryState::handleInput() {
	sf::Event event;
	while (window->pollEvent(event)) {
		switch (event.type) {
		case sf::Event::Closed:
			changeGameState(Game::end);
			break;
		case sf::Event::KeyPressed:
			if (event.key.code == sf::Keyboard::Z)
			{
				changeGameState(Game::menu);
			}
			break;
		default:
			break;
		}
	}
}
Example #4
0
void menuLoop()
{
    bool redraw = true;
    al_start_timer(timer);

    al_attach_audio_stream_to_mixer(music, al_get_default_mixer());
    al_set_audio_stream_playing(music, true);
    al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP);

    while (!menuDone) {
        ALLEGRO_EVENT event;
        al_wait_for_event(eventMenuQueue, &event);

         if (event.type == ALLEGRO_EVENT_TIMER) {
            redraw = true;
            //update_logic();
        }
        else if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
                menuDone = true;
            }
            if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) {
                changeGameState(Game);
            }
            if (event.keyboard.keycode == ALLEGRO_KEY_UP){
                changeGameState(Menu);
            }
            //get_user_input();
        }

        if (redraw && al_is_event_queue_empty(eventMenuQueue)) {
            redraw = false;
            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_tinted_bitmap(background, al_map_rgba(255, 255, 255, 255), 0, 0, 0);
            al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "BREGA HERO");
            //update_graphics();
            al_flip_display();
        }
    }
}
Example #5
0
void BlobGame::beginGame(){
	m_Camera->moveTo(0,0);
	m_GameObjects = new std::vector<GameObject*>();
	m_Level = loadLevel(m_LevelToLoad,false,m_GameObjects,&createUnit);
	if(!m_Level){
		changeGameState((void*)MainMenu);
		return;
	}
	for(int i = 0;i < m_GameObjects->size();i++){
		if((*m_GameObjects)[i]->getType() != "GameObject"){
				Unit* unit = (Unit*)(*m_GameObjects)[i];
				unit->setLevel(m_Level);
		}
		if((*m_GameObjects)[i]->getType() == "Enemy"){
			Enemy* enemy = (Enemy*)(*m_GameObjects)[i];
			enemy->search();
		}
	}
}
Example #6
0
// Initialise a round
void Game::initRound()
{
    // Hide info panel if its visible
    hideInfoPanel();

    // Remove all timers and tweens
    m_Tweener.Clear();
    m_Timers.Clear();

    // Release any explosions that are in progress
    g_pExplosionManager->ReleaseAll();

    // Regenrate grid
    gemsGrid->regenerate();

    // Reset round score
    currentRoundScore = 0;

    // Calculate target round score
    targetRoundScore = START_TARGET_SCORE + currentRound * TARGET_SCORE_STEP;

    // Calculate round time
    currentRoundTime = (float)startRoundTime + currentRound * ROUND_TIME_STEP;

    // Set up labels
    char str[32];
    snprintf(str, 32, "%d", currentRoundScore);
    scoreLabel->m_Text = str;
    snprintf(str, 32, "%d", targetRoundScore);
    targetScoreLabel->m_Text = str;
    snprintf(str, 32, "%d", currentRound);
    roundLabel->m_Text = str;
    snprintf(str, 32, "%d", (int)currentRoundTime);
    timerLabel->m_Text = str;

    // Create target gem timer (changes the target gem every 10 seconds)
    m_Timers.Add(new Timer(10.0f, 0, &Game::chooseTargetGem, (void*)this));

    // Set the game going
    changeGameState(waitingFirstGem);
}
Example #7
0
void Game::Update(float deltaTime, float alphaMul)
{
    if (!m_IsActive)
        return;

    // Update base scene
    Scene::Update(deltaTime, alphaMul);

    // Update falling gems in grid
    if (gameState == gemsFalling)
        gemsGrid->gemsFalling(deltaTime);

    // Update round timer
    if (gameState != roundOver && gameState != paused)
    {
        if ((int)currentRoundTime != (int)(currentRoundTime - deltaTime))
        {
            char str[32];
            snprintf(str, 32, "%d", (int)currentRoundTime);
            timerLabel->m_Text = str;
        }
        currentRoundTime -= deltaTime;
        if (currentRoundTime <= 0)
        {
            currentRoundTime = 0;
            // Allow last played move to finish
            if (gameState == waitingFirstGem || gameState == waitingSecondGem)
                endOfRound();
        }
    }

    // Detect screen tap
    if (m_IsInputActive && m_Manager->GetCurrent() == this && !g_pInput->m_Touched && g_pInput->m_PrevTouched)
    {
        g_pInput->Reset();
        if (gameState == roundOver)
        {
            if (infoPanel->HitTest(g_pInput->m_X, g_pInput->m_Y))
                initRound();
        }
        else
        {
            if (g_pInput->m_Y >= gemsGrid->getGridOriginY())
            {
                int grid_x, grid_y;
                gemsGrid->screenToGrid(g_pInput->m_X, g_pInput->m_Y, grid_x, grid_y);
                if (gameState == waitingFirstGem)
                {
                    // In waiting for first gem state we place a selector over the first selected gem
                    gridTouchesX[0] = grid_x;
                    gridTouchesY[0] = grid_y;
                    changeGameState(waitingSecondGem);
                }
                else
                if (gameState == waitingSecondGem)
                {
                    gridTouchesX[1] = grid_x;
                    gridTouchesY[1] = grid_y;
                    int dx = gridTouchesX[1] - gridTouchesX[0];
                    int dy = gridTouchesY[1] - gridTouchesY[0];
                    if ((dx == 0 && (dy == -1 || dy == 1)) || (dy == 0 && (dx == -1 || dx == 1)))
                    {
                        // Second gem is swappable so switch to thinking state
                        changeGameState(thinking);
                        g_pAudio->PlaySound("audio/gem_swap.wav");
                    }
                    else
                    {
                        // Second gem is too far or the same gem, so reset
                        changeGameState(waitingFirstGem);
                        g_pAudio->PlaySound("audio/gem_wrong.wav");
                    }
                }
            }
            else
            {
                if (pauseSprite->HitTest(g_pInput->m_X, g_pInput->m_Y))
                {
                    // Enter pause menu
                    pauseGame();
                }
            }
        }
    }
}
void MenuState_MainMenu::OnClick_menu_main_editor () {
	changeGameState(new GameState_Editor(""));
}
Example #9
0
void GameManager::start()
{
    changeGameState(EGameState::NONE);
}
Example #10
0
bool GameManager::init()
{
    changeGameState(EGameState::NONE);
    setLoginDelegate(nullptr);
    return true;
}
Example #11
0
void CGameManager::resume()
{
    changeGameState(EGameState::RESUME);
}
Example #12
0
void CGameManager::pause()
{
    changeGameState(EGameState::PAUSE);
}
Example #13
0
void CGameManager::start()
{
    deGameManager->setsceneflag(0);
    changeGameState(EGameState::NONE);
}
Example #14
0
void BlobGame::handleMessage(const Message& msg){
	switch(msg.type){
	case 2:{
		Unit* unit = (Unit*)msg.extraInfo;
		for(int i = 0;i < m_GameObjects->size();i++){
			if((*m_GameObjects)[i] == unit){
				m_GameObjects->erase(m_GameObjects->begin()+i);
				SafePtrRelease(unit);
				return;
			}
		}
		break;
	}
	case PISTOL_ATTACK:{
			Unit* unit;
			Tile* tile = (Tile*)msg.extraInfo;
			if((unit = unitOnTile(tile))){
				unit->hit(PISTOL_DAMAGE);
				MessageHandler::Instance()->deleteMessage(msg.name);
			}
		break;
	}
	case REMOVE_TILE_EFFECT:{
		Tile* tile = (Tile*)msg.extraInfo;
		unsigned int tileStatuses = tile->getTileTypes();
		if(msg.name == "Fire"){
			if(ContainsFlags(tile->getTileTypes(),Fire)){
				RemoveFlag(&tileStatuses,Fire);
				tile->setTileTypes(tileStatuses);
			}
		}
		else if(msg.name == "Posion"){
			if(ContainsFlags(tile->getTileTypes(),Posion)){
				RemoveFlag(&tileStatuses,Posion);
				tile->setTileTypes(tileStatuses);
			}
		}
		else if(msg.name == "Slime"){
			if(ContainsFlags(tile->getTileTypes(),Slime)){
				RemoveFlag(&tileStatuses,Slime);
				tile->setTileTypes(tileStatuses);
			}
		}
		for(int i = 0;i < m_Effects->size();i++){
			if((*m_Effects)[i]->getName() == 
				(msg.name + "_" + tile->getName())){
					Sprite2d* sprite = (*m_Effects)[i];
					m_Effects->erase(m_Effects->begin()+i);
					SpriteManager::instance()->deleteSprite(sprite);
			}
		}
	}
	case 5:{
		for(int i = 0;i < m_GameObjects->size();i++){
			if((*m_GameObjects)[i]->getName() == msg.name){
				Enemy* enemy = (Enemy*)(*m_GameObjects)[i];
				enemy->hold();
				return;
			}
		}
		break;
	}
	case 6:{
		for(int i = 0;i < m_GameObjects->size();i++){
			if((*m_GameObjects)[i]->getName() == msg.name){
				Unit* unit = (Unit*)(*m_GameObjects)[i];
				unit->hit(unit->getHealth());
				return;
			}
		}
		break;
	}
	case REMOVE_UNIT_STATUS:{
		Unit* unit = (Unit*)msg.extraInfo;
		unsigned int unitStatuses = unit->getStatus();
		if(msg.name == "Fire"){
			if(ContainsFlags(unit->getStatus(),OnFire)){
				RemoveFlag(&unitStatuses,OnFire);
				unit->setStatus(unitStatuses);
			}
		}
		else if(msg.name == "Posioned"){
			if(ContainsFlags(unit->getStatus(),Posioned)){
				RemoveFlag(&unitStatuses,Posioned);
				unit->setStatus(unitStatuses);
			}
		}
		else if(msg.name == "Slowed"){
			if(ContainsFlags(unit->getStatus(),Slowed)){
				RemoveFlag(&unitStatuses,Slowed);
				unit->setStatus(unitStatuses);
			}
		}
		break;
	}
	case CHANGE_STATE:{
		int s  = (int)msg.extraInfo;
		changeState((BlobGameStates)s);
		break;
	}
	case LOAD_LEVEL_EDITOR:{
		if(m_CurrentState == Editor){
			int level = (int)msg.extraInfo - 1;
			if(level < 0){
				int tileTypes[MAX_HORIZONTAL_TILES*MAX_VERTICAL_TILES];
				for(int i = 0;i < (MAX_HORIZONTAL_TILES*MAX_VERTICAL_TILES);i++){
					tileTypes[i] = Empty;
				}
				Level* newLevel  = new Level(MAX_HORIZONTAL_TILES,MAX_VERTICAL_TILES,
												TILE_SIZE,tileTypes,NULL,NULL);
				m_Editor = new LevelEditor(newLevel,m_Camera);
				m_Editing = true;
				SafePtrRelease(m_LevelSelect);
				if(m_GameObjects != NULL){
					SafeVectorDelete((*m_GameObjects));
					SafePtrRelease(m_GameObjects);
				}
				return;
			}
			else{
				DIR* dir;
				struct stat fileStat;
				struct dirent* dirp;
				std::string levelName;
				std::string filePath;
				unsigned int width;
				unsigned int height;
				int i = 0;
				dir = opendir("levels");
				if(dir == NULL){
					std::cout << "Levels not found!" << std::endl;
					return;
				}
				while(i <= level && (dirp = readdir(dir))){
					filePath = "levels/" + std::string(dirp->d_name);

					if(stat(filePath.c_str(),&fileStat)){continue;}
					if(S_ISDIR(fileStat.st_mode)){continue;}

					if(loadPreview(&levelName,&width,&height,filePath)){
						if(i == level){
							m_Editing = true;
							m_Editor = new LevelEditor(NULL,m_Camera);
							m_Editor->loadLevelToEditor(filePath);
							SafePtrRelease(dir);
							SafePtrRelease(m_LevelSelect);
							if(m_GameObjects != NULL){
								SafeVectorDelete((*m_GameObjects));
								SafePtrRelease(m_GameObjects);
							}
							return;
						}
						else{
							i++;
						}
					}
				}
			}
			break;
		}
	}
	case LOAD_LEVEL:{
		if(m_CurrentState == LevelSelect){
			int level = (int)msg.extraInfo;
			if(level >= 0){
				DIR* dir;
				struct stat fileStat;
				struct dirent* dirp;
				std::string levelName;
				std::string filePath;
				unsigned int width;
				unsigned int height;
				int i = 0;
				dir = opendir("levels");
				if(dir == NULL){
					std::cout << "Levels not found!" << std::endl;
					return;
				}
				while(i <= level && (dirp = readdir(dir))){
					filePath = "levels/" + std::string(dirp->d_name);

					if(stat(filePath.c_str(),&fileStat)){continue;}
					if(S_ISDIR(fileStat.st_mode)){continue;}

					if(loadPreview(&levelName,&width,&height,filePath)){
						if(i == level){
							SafePtrRelease(dir);
							changeGameState((void*)GamePlay);
							m_LevelToLoad = filePath;
							return;
						}
						else{
							i++;
						}
					}
				}
			}
			break;
		}
	}
	default:
		break;
	}
}
Example #15
0
int main ( int argc, char* args[] )
{
	init();

	srand(time(NULL));

	int FPS = 0;

	///////GLOBAL LOADING
	tex_spikes = loadTexture("data/gfx/Spikes.png");
	tex_block1 = loadTexture("data/gfx/block1.png");
	tex_menu = loadTexture("data/gfx/menu.png");
	tex_playgame = loadTexture("data/gfx/playgame.png");
	tex_selectlevel = loadTexture("data/gfx/selectlevel.png");
	tex_editor = loadTexture("data/gfx/editor.png");
	tex_exit = loadTexture("data/gfx/exitmenu.png");
	tex_player1 = loadTexture("data/gfx/player.png");
	tex_door = loadTexture("data/gfx/door.png");
	tex_font = loadTexture("data/gfx/font.png");
	tex_done = loadTexture("data/gfx/ok.png");
	tex_gold = loadTexture("data/gfx/gold.png");
	tex_silver = loadTexture("data/gfx/silver.png");
	tex_bronze = loadTexture("data/gfx/bronze.png");
	tex_eyes = loadTexture("data/gfx/playgame.png");
	tex_arrow = loadTexture("data/gfx/arrow.png");
	tex_info = loadTexture("data/gfx/info.png");


	///////soundsss
	sample_playerJump = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/jump.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerJump, -1,100,-1,-1);
	sample_playerHit = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/hit.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerHit, -1,100,-1,-1);
	sample_playerForce = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/force.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerForce, -1,100,-1,-1);

	song2 = FSOUND_Stream_Open( "data/music/Random-SitgesSavepoint.mp3",FSOUND_LOOP_NORMAL,0,0);

	FSOUND_Stream_Play( 1, song2 );
	FSOUND_Stream_SetLoopCount(song2,-1);

	//FSOUND_SetVolume(1,80);

	std::ifstream file ("data/levels/score.lvl");

	while ( !file.eof() )
	{
		o_scores.push_back(new Score());

		file >> o_scores.back()->i_number;
		file >> o_scores.back()->b_unlocked;
		file >> o_scores.back()->i_highScore;
		file >> o_scores.back()->i_B;
		file >> o_scores.back()->i_S;
		file >> o_scores.back()->i_G;

	}

	file.close();

	//o_scores.pop_back();


	gameState = new StateMenu();
	currentGameState = STATE_MENU;



/*
	for ( int n = 0; n < 100; n++ )
	{
		o_scores.push_back( new Score () );
		o_scores.back()->b_unlocked = true;
		o_scores.back()->i_highScore = 0;
		o_scores.back()->i_B = 0;
		o_scores.back()->i_G = 0;
		o_scores.back()->i_S = 0;
	}*/

	//saving

	FPSA = SDL_GetTicks();

	while ( nextGameState != STATE_EXIT )
	{

		FPS = SDL_GetTicks();

		gameState->handleEvents();

		gameState->logic();

		FPSA = SDL_GetTicks();

		gameState->render();

		changeGameState();



		////////////////////////////
		if ( (SDL_GetTicks() - FPS) < 1000/60 )
		{
			//SDL_Delay( ( 1000/60) - (SDL_GetTicks() - FPS) );
		}
		SDL_Delay(2);

	}

    FSOUND_Stream_Close(song2);
	FSOUND_Close();

	return 0;
}