Ejemplo n.º 1
0
void Satiety::setSatiety(int level)
{
    if(level <= 0) level = 0;
    if(level >= 100) level = 100;
    satietyLevel = level;
    emit changeLevel(satietyLevel);
}
Ejemplo n.º 2
0
void Satiety::reductionSatiety()
{
    satietyLevel --;
    if(satietyLevel <= 0)
        satietyLevel = 0;
    emit changeLevel(satietyLevel);
 //   qDebug() << "Satiety: " << satietyLevel << "\n";
    if(satietyLevel <= 30)
        emit satietyNow(10);
}
Ejemplo n.º 3
0
void updatePlayer(Input *input)
{
    /* On rajoute un timer au cas où notre héros mourrait
    Si le timer vaut 0, c'est que tout va bien, sinon, on le décrémente jusqu'à 0, et là,
    on réinitialise.
    C'est pour ça qu'on ne gère le joueur que si ce timer vaut 0. */
    if(player.timerMort == 0)
    {
        if(!player.touch) // S'il n'est pas touché
        {
            /* On gère le timer de l'invincibilité */
            if(player.invincibleTimer > 0) player.invincibleTimer--;

            /* On réinitialise notre vecteur de déplacement latéral (X), pour éviter que le perso
            ne fonce de plus en plus */
            player.dirX = player.dirY = player.isAttacking = 0;

            attackManagement(input, &player);

            if(player.state < ATTACK_HORIZONTAL && input->puched < 3) playerDir(input, &player);

            /* Si on n'appuie sur rien, on charge l'animation marquant l'inactivité (Idle), je n'ai pas regarder encore si je pouvais l'optimiser */
            playerIdle(input, &player);

            resetInput(input);
        }
        /* Sinon si il est touché */
        else if(player.touch)
            entityTouch();

        /* On rajoute notre fonction de détection des collisions qui va mettre à
        jour les coordonnées de notre héros. */
        mapCollision(&player);

        /* On gère le scrolling */
        centerScrollingOnPlayer();
    }



    /*Gestion de la mort. Si timerMort est différent de 0, c'est qu'il faut réinitialiser le joueur.
    On ignore alors ce qui précède et on joue cette boucle (un wait en fait) jusqu'à ce que
    timerMort == 1. A ce moment-là, on le décrémente encore -> il vaut 0 et on réinitialise
    le jeu avec notre bonne vieille fonction d'initialisation */
    if(player.timerMort > 0)
    {
        player.timerMort--;
        if(player.timerMort == 0)
        {
            changeLevel();
            initializePlayer(0);
        }
    }

}
Ejemplo n.º 4
0
int StateChangeLevel::UpdateState(){
	if(changeDone == false){
		changeLevel();
		changeDone = true;
	}

	if(finished == true){
		return GAME_FINISHED;
	}
	if(proceed){
		return GO_TO_PLAY;
	} else{
		return NO_CHANGE;
	}
}
Ejemplo n.º 5
0
void HexagonGame::update(float mFT)
{
    if(!assets.pIsLocal() && Config::isEligibleForScore())
    {
        assets.playedSeconds += mFT / 60.f;
        if(assets.playedSeconds >= 60.f)
        {
            assets.playedSeconds = 0;
            Online::trySendMinutePlayed();
        }
    }

    updateFlash(mFT);
    effectTimelineManager.update(mFT);

    if(!status.hasDied)
    {
        manager.update(mFT);
        updateEvents(mFT);
        updateTimeStop(mFT);
        updateIncrement();
        if(mustChangeSides && !manager.hasEntity(HGGroup::Wall)) sideChange(getRnd(levelStatus.sidesMin, levelStatus.sidesMax + 1));
        updateLevel(mFT);
        if(Config::getBeatPulse()) updateBeatPulse(mFT);
        if(Config::getPulse()) updatePulse(mFT);
        if(!Config::getBlackAndWhite()) styleData.update(mFT, pow(difficultyMult, 0.8f));
    }
    else levelStatus.rotationSpeed *= 0.99f;

    if(Config::get3D()) update3D(mFT);
    if(!Config::getNoRotation()) updateRotation(mFT);

    overlayCamera.update(mFT);
    backgroundCamera.update(mFT);
    for(auto& c : depthCameras) c.update(mFT);

    if(status.mustRestart)
    {
        changeLevel(restartId, restartFirstTime);
        if(!assets.pIsLocal() && Config::isEligibleForScore()) {
            Online::trySendRestart();
        }
    }
    if(!status.scoreInvalid && Config::getOfficial() && fpsWatcher.isLimitReached()) invalidateScore();

    fpsWatcher.update();
}
Ejemplo n.º 6
0
void levelChanger(void)
{
    if (score >= 100) {
		if(livello==3){
			//musica
			music.stop();
			music.openFromFile("./dati/audio/Stuck_In_Guacamole.ogg");
			music.play();
			menu_id=4;
		}
		else{
			changeLevel(UP);
			reload();
			score = 0;
		}
    }
    return;
}
Ejemplo n.º 7
0
void HexagonGame::update(FT mFT)
{
    updateText();
    updateFlash(mFT);
    effectTimelineManager.update(mFT);

    if(!status.started && (!Config::getRotateToStart() || inputImplCCW ||
                           inputImplCW || inputImplBothCWCCW))
    {
        status.started = true;
        messageText.setString("");
        assets.playSound("go.ogg");
        assets.musicPlayer.resume();
        if(Config::getOfficial()) fpsWatcher.enable();
    }

    // Naive touch controls
    for(const auto& p : window.getFingerDownPositions())
    {
        if(p.x < window.getWidth() / 2.f)
            inputImplCCW = 1;
        else
            inputImplCW = 1;
    }

    if(inputImplCW && !inputImplCCW)
        inputMovement = 1;
    else if(!inputImplCW && inputImplCCW)
        inputMovement = -1;
    else if(inputImplCW && inputImplCCW)
    {
        if(!inputImplBothCWCCW)
        {
            if(inputMovement == 1 && inputImplLastMovement == 1)
                inputMovement = -1;
            else if(inputMovement == -1 && inputImplLastMovement == -1)
                inputMovement = 1;
        }
    }
    else
        inputMovement = 0;

    if(status.started)
    {
        if(!assets.pIsLocal() && Config::isEligibleForScore())
        {
            assets.playedSeconds += ssvu::getFTToSeconds(mFT);
            if(assets.playedSeconds >= 60.f)
            {
                assets.playedSeconds = 0;
                Online::trySendMinutePlayed();
            }
        }

        if(!status.hasDied)
        {
            manager.update(mFT);
            updateEvents(mFT);
            updateTimeStop(mFT);
            updateIncrement();
            if(mustChangeSides && !manager.hasEntity(HGGroup::Wall))
                sideChange(getRndI(
                               levelStatus.sidesMin, levelStatus.sidesMax + 1));
            updateLevel(mFT);
            if(Config::getBeatPulse()) updateBeatPulse(mFT);
            if(Config::getPulse()) updatePulse(mFT);
            if(!Config::getBlackAndWhite())
                styleData.update(mFT, pow(difficultyMult, 0.8f));
        }
        else
            levelStatus.rotationSpeed *= 0.99f;

        if(Config::get3D()) update3D(mFT);
        if(!Config::getNoRotation()) updateRotation(mFT);
    }

    overlayCamera.update(mFT);
    backgroundCamera.update(mFT);

    if(status.started)
    {
        if(status.mustRestart)
        {
            fpsWatcher.disable();
            changeLevel(restartId, restartFirstTime);
            if(!assets.pIsLocal() && Config::isEligibleForScore())
            {
                Online::trySendRestart();
            }
        }
        if(!status.scoreInvalid && Config::getOfficial() &&
                fpsWatcher.isLimitReached())
            invalidateScore();

        fpsWatcher.update();
    }
}
Ejemplo n.º 8
0
        bool Tela::playGame() {
		    Ponto p1 = {-1, -1}, p2 = {-1, -1}, pDica = {-1, -1};
		    bool quit = false, execute = true;
		    showGame();
            if(testMove() == false) quit = true;
			float frame = 0;
    		Uint32 start = SDL_GetTicks();
			SDL_Rect rect0[20], rect1[20], rect2[20], rect3[20], rect4[20], rect5[20], rect6[20];
		    setrects(rect0, 60, 0);
		    setrects(rect1, 62, 70);
		    setrects(rect2, 58, 140);
		    setrects(rect3, 58, 210);
		    setrects(rect4, 60, 280);
		    setrects(rect5, 64, 350);
		    setrects(rect6, 64, 420);

		    while( execute ) {
		    	changeLevel();
                if( level == 5 ) {
                    execute = false;
                    return execute;
                }

		        if( SDL_PollEvent( &event ) ) {

		            Ponto tmp;

		            //Botão esquerdo do mouse pressionado
		            if( event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
	                    tmp.x = event.button.x;
	                    tmp.y = event.button.y;
                        if((tmp.x >= 135 && tmp.x <= 250) && (tmp.y >= 480 && tmp.y <= 595)) {
                            undoPlay();
                            SDL_Flip( screen );
	                    } else if((tmp.x >= 45 && tmp.x <= 160) && (tmp.y >= 395 && tmp.y <= 505)){
	                    	pDica = getDica();
	        				apply_surface(pDica.x, pDica.y, gems_dica, screen);
        					SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h);
	                    } else if((tmp.x >= 30 && tmp.x <= 115) && (tmp.y >= 525 && tmp.y <= 605)){
                            if(showConfScreen()) {
                                quit = true;
                                return quit;
                            } else {
                                showGame();
                            }
                        } else if((tmp.x >= 175 && tmp.x <= 265) && (tmp.y >= 380 && tmp.y <= 465)){
                            if(showInstrucoes()) {
                                quit = true;
                                return quit;
                            } else {
                                showGame();
                            }
                        } else if((tmp.x >= MAT_INITIAL_POINT_X && tmp.x <= MAT_INITIAL_POINT_X + 480) && (tmp.y >= MAT_INITIAL_POINT_Y && tmp.y <= MAT_INITIAL_POINT_Y + 480)) {
	                    	if(pDica.x >= 0) {
		        				apply_surface(pDica.x, pDica.y, gems, screen);
	        					SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h);
	                    	}
		                    tmp.x = (tmp.x - MAT_INITIAL_POINT_X) / 60;
		                    tmp.y = (tmp.y - MAT_INITIAL_POINT_Y) / 60;
			                if(p1.x < 0) {
			                    p1.x = tmp.y;
			                    p1.y = tmp.x;
			                    //Destaca a nova joia selecionada
			                } else if(p2.x < 0) {
			                	if(saoAdjacentes(p1.x, p1.y, tmp.y, tmp.x)) {
				                    p2.x = tmp.y;
				                    p2.y = tmp.x;
			                	} else {
			                		//Ignora selecao
			                		//Tira o destaque da joia que tinha sido selecionada
			        				apply_surface(p1.x, p1.y, gems, screen);
                					SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
			                		p1.x = tmp.y;
					                p1.y = tmp.x;
			                	}
			                }
	                    }
	                //Se o usuario fechar a janela
		            } else if( (event.type == SDL_QUIT) ) {
		                //Encerra o programa
		                quit = true;
                        return quit;
                    //Se o usuario teclar ESC
	            	} else if ( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) ) {
                        level = 5; /* Show Game Over */
                    } else if( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) ) {
	            		if(audio == true) {
							//Pausa a musica
							Mix_PauseMusic();
	            			audio = false;
	            		} else {
							//Toca a musica novamente
							Mix_ResumeMusic();
	            			audio = true;
	            		}
	            	}
		    	}
	            SDL_Rect offset;
	            offset.x = matriz[p1.x][p1.y].celula.x;
	            offset.y = matriz[p1.x][p1.y].celula.y;
	            switch(getElement(p1.x, p1.y)) {
	            	case 1:
						SDL_BlitSurface( gems, &rect0[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 2:
						SDL_BlitSurface( gems, &rect1[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 3:
						SDL_BlitSurface( gems, &rect2[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 4:
						SDL_BlitSurface( gems, &rect3[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 5:
						SDL_BlitSurface( gems, &rect4[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 6:
						SDL_BlitSurface( gems, &rect5[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 7:
						SDL_BlitSurface( gems, &rect6[static_cast<int>(frame)], screen, &offset );
	            		break;
	            }
				SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
				//Velocidade de transição entre frames
				frame += 0.5;
		 
		        if(frame > 7) {
		        	frame = 0;
		        }
		 
				if(1000/FPS > SDL_GetTicks()-start) 
				{
					SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
				}
            	if((p1.x >= 0) && (p2.x >= 0)) {
		            checkSwitch(p1.x, p1.y, p2.x, p2.y);
		            contrastItem(p1.x, p1.y, matriz[p1.x][p1.y].elemento);
			        apply_surface(p1.x, p1.y, gems, screen);
                	SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
	                p1.x = -1;
	                p1.y = -1;
	                p2.x = -1;
	                p2.y = -1;
		            if(testMove() == false) 
                        level = 5;
		        }
			}
            return execute;
		}
Ejemplo n.º 9
0
void HexagonGame::executeEvents(Json::Value& mRoot, float mTime)
{
    for (Json::Value& eventRoot : mRoot)
    {
        if(eventRoot["time"].asFloat() >  mTime) continue;
        if(eventRoot["executed"].asBool()) continue;
        eventRoot["executed"] = true;
        string type{eventRoot["type"].asString()};
        float duration{eventRoot["duration"].asFloat()};
        string valueName{eventRoot["value_name"].asString()};
        float value{eventRoot["value"].asFloat()};
        string message{eventRoot["message"].asString()};
        string id{eventRoot["id"].asString()};

        if 		(type == "level_change")			changeLevel(id);
        else if (type == "menu") 					goToMenu();
        else if (type == "message_add")				{
            if(getShowMessages()) addMessage(message, duration);
        }
        else if (type == "message_clear") 			clearMessages();
        else if (type == "time_stop")				timeStop = duration;
        else if (type == "timeline_wait") 			timeline.add(new Wait(duration));
        else if (type == "timeline_clear") 			clearAndResetTimeline(timeline);
        else if (type == "value_float_set") 		levelData.setValueFloat(valueName, value);
        else if (type == "value_float_add") 		levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) + value);
        else if (type == "value_float_subtract") 	levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) - value);
        else if (type == "value_float_multiply") 	levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) * value);
        else if (type == "value_float_divide") 		levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) / value);
        else if (type == "value_int_set") 			levelData.setValueInt(valueName, value);
        else if (type == "value_int_add") 			levelData.setValueInt(valueName, levelData.getValueFloat(valueName) + value);
        else if (type == "value_int_subtract")		levelData.setValueInt(valueName, levelData.getValueFloat(valueName) - value);
        else if (type == "value_int_multiply") 		levelData.setValueInt(valueName, levelData.getValueFloat(valueName) * value);
        else if (type == "value_int_divide") 		levelData.setValueInt(valueName, levelData.getValueFloat(valueName) / value);
        else if (type == "music_set")				{
            if(getChangeMusic()) {
                stopLevelMusic();
                musicData = getMusicData(id);
                musicData.playRandomSegment(musicPtr);
            }
        }
        else if (type == "music_set_segment")		{
            if(getChangeMusic()) {
                stopLevelMusic();
                musicData = getMusicData(id);
                musicData.playSegment(musicPtr, eventRoot["segment_index"].asInt());
            }
        }
        else if (type == "music_set_seconds")		{
            if(getChangeMusic()) {
                stopLevelMusic();
                musicData = getMusicData(id);
                musicData.playSeconds(musicPtr, eventRoot["seconds"].asInt());
            }
        }
        else if (type == "style_set")				{
            if(getChangeStyles()) styleData = getStyleData(id);
        }
        else if (type == "side_changing_stop")		randomSideChangesEnabled = false;
        else if (type == "side_changing_start")		randomSideChangesEnabled = true;
        else if (type == "increment_stop")			incrementEnabled = false;
        else if (type == "increment_start")			incrementEnabled = true;
        else if (type == "pulse_max_set")			maxPulse = value;
        else if (type == "pulse_min_set")			minPulse = value;
        else if (type == "pulse_speed_set")			pulseSpeed = value;
        else if (type == "pulse_speed_b_set")		pulseSpeedBackwards = value;
        else if (type == "script_exec")				scripts.push_back(getScriptData(id, this));
        else if (type == "script_queue")			queueScript(getScriptData(id, this));
        else										log("unknown script command: " + type);
    }
}
void Snake::doMoveSnake()
{//Move the snack by 1 step
    hasMoved=true;
    QString str_x = QString::number(pre_x);
    QString str_y = QString::number(pre_y);
    QString position = str_x + "," + str_y;

    setlabel->setText(position);

    //Sequence 0 is the present coordinate value and sequence 1 is the last coordinate value
    seq_x[1] = seq_x[0];
    seq_y[1] = seq_y[0];
    seq_x[0] = pre_x;
    seq_y[0] = pre_y;

    //Decide when to make a turn
    if(seq_x[0] - seq_x[1] > 12 && pre_x > 60)
    {
        //Turn left;
        if(Dir!=2&&Dir!=3)
        {
            Dir=3;
            hasMoved=false;
        }
    }
    else if(seq_x[0] - seq_x[1] < -12 && pre_x < 40)
    {
        //Turn right;
        if(Dir!=2&&Dir!=3)
        {
            Dir=2;
            hasMoved=false;
        }
    }
    else if(seq_y[0] - seq_y[1] < -12 && pre_y < 40)
    {
        //Turn Up
        if(Dir!=0&&Dir!=1)
        {
             Dir=0;
             hasMoved=false;
        }
    }
    else if(seq_y[0] - seq_y[1] > 12 && pre_y > 60)
    {
        //Turn Down
        if(Dir!=0&&Dir!=1)
        {
             Dir=1;
             hasMoved=false;
        }
    }


    if(isGameOver())
    {//Game over
        QMessageBox::information(this,"GameOver","Game is Over");
        iniGame();
    }
    header_Index=(header_Index-1+Max)%Max;
    SnakeBody[header_Index][0]=tempx;
    SnakeBody[header_Index][1]=tempy;
    if(isEating())
    {
        changeScore();
        changeLevel();
        while(true)
        {//Random the position of food, not covered by the snake
            eat_X=qrand()%(map_col);
            eat_Y=qrand()%(map_row);
            int i;
            for(i=header_Index;i!= tail_Index;i=(i+1)%Max)
                if(eat_X==SnakeBody[i][0]&&eat_Y==SnakeBody[i][1])
                    break;
            if(i==tail_Index) break;
        }
    }
    else tail_Index=(tail_Index-1+Max)%Max;
    update();
}
Ejemplo n.º 11
0
void PloughMill::setLevel(int level)
{
	_level = level;
	changeLevel();
}