Ejemplo n.º 1
0
void PasPlay::Update(){
// 更新処理
	int i;
	for(i=0;i<MaxSE;i++){ mSE[i]->Initialize(); }
	mBackground->Update();					// 背景

	if(flgStart)	{ UpdateStart();	}	// ミッションスタート
	if(flgClear)	{ UpdateClear();	}	// ミッションクリア
	if(flgGameOver)	{ UpdateGameOver(); }	// ゲームオーバー
	if(flgResult)	{ UpdateResult();	}	// リザルト
	if(flgWarning)	{ UpdateWarning();	}	// ワーニング

	if(!flgStart && !flgClear && !flgResult){				// スタート且つクリアフラグが立っていなければ
		/*== 更新 ================*/
		mUnitAdmin->Update();								// ゲームオブジェクト
		mStage->HiScoreUpdate(mUnitAdmin->GetScore());		// ハイスコア更新
		mStage->HiDestroyUpdate(mUnitAdmin->GetDestroy());	// 破壊数記録更新

		if(!flgGameOver && FlagGameOver()){					// 失敗条件を満たしてしまうとクリアしててもゲームオーバー
			GoToGameOver();
		}
		if(!flgGameOver && !flgClear && FlagClear()){		// ゲームオーバーではなく、クリア条件を満たしているとクリア
			//GoToClear();
		}
		if(!flgWarning && mUnitAdmin->GetBossReadyFlag()){ GoToWarning(); }// ボスの条件が整ったか否か
		if(flgBoss){										// ボスフラグが立っている状態で
			if(!mUnitAdmin->GetBossFlg()){					// ボスが消えると
				GoToClear();								// クリア
				flgBoss = false;
			}
		}
	} //if(!flgStart && !flgClear && !flgResult)

	for(i=0;i<MaxSE;i++){ mSE[i]->Update();	}				// 再生するオーディオを再生
}
Ejemplo n.º 2
0
void GameApp::Update(float timestep){
	button_movement_counter += timestep;
	audio->update(timestep);
	switch (state){
	case MAIN_MENU:
		UpdateMainMenu(timestep);
		break;
	case GAMEPLAY:
		UpdateGamePlay(timestep);
		break;
	case GAME_OVER:
		UpdateGameOver(timestep);
		break;
	case PAUSE:
		UpdatePause(timestep);
		break;
	}
}
Ejemplo n.º 3
0
/**
* Logic for Gameplay Screen.
*/
void ScreenGameplayLogic()
{
    /* Make sure input isn't affected by the timer. */
    Input();

    UpdateTimers();
    
    /* If the player hasnt lost, do stuff. */
    if(!game_over)
    {
        /* If left key is tapped, see if moving piece left is ok... */
        if(move_left && !new_brick)
        {
            bool move_ok = true;
            
            /* Iterate through game board... */
            int i, j;
            for(i = 0; i < GAMEBOARD_H; i++)
                for(j = 0; j < GAMEBOARD_W; j++)
                    if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                    {
                        /* Out of bounds. */
                        if(j-1 < 0)
                            move_ok = false;
                        else 
                        {
                            /* If a brick is found. */
                            if(gameboard[i][j-1] == 1 || gameboard[i][j-1] == 2 || gameboard[i][j-1] == 3)
                                move_ok = false;
                        }
                    }
            
            if(move_ok) /* If detection is OK then move the brick. */
            {
                PlaySound(sounds[SOUND_BRICKMOVE]);
                
                /* Iterate through game board. */
                int i, j;
                for(i = 0; i < GAMEBOARD_H; i++)
                    for(j = 0; j < GAMEBOARD_W; j++)
                        if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            int temp = gameboard[i][j];    
                            gameboard[i][j] = 0;
                            gameboard[i][j-1] = temp;
                        }
                        
                /* Decrement the brick X coordinate. */
                brick_x -= 1;
            }
            
        }
        
        /* If right key is tapped, see if moving piece right is ok. */
        if(move_right && !new_brick)
        {
            bool move_ok = true;
            
            /* Iterate through game board. */
            int i, j;
            for(i = GAMEBOARD_H-1; i >= 0; i--)
                for(j = GAMEBOARD_W-1; j >= 0; j--)
                    if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                    {
                        /* If out of bounds. */
                        if(j+1 > GAMEBOARD_W-1)
                            move_ok = false;
                        else 
                        {
                            /* If a brick is there. */
                            if(gameboard[i][j+1] == 1 || gameboard[i][j+1] == 2 || gameboard[i][j+1] == 3)
                                move_ok = false;
                        }
                    }
            
            if(move_ok) /* If detection is OK then move the brick. */
            {
                PlaySound(sounds[SOUND_BRICKMOVE]);
                
                /* Iterate through game board. */
                int i, j;
                for(i = GAMEBOARD_H-1; i >= 0; i--)
                    for(j = GAMEBOARD_W-1; j >= 0; j--)
                        if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            int temp = gameboard[i][j];
                            gameboard[i][j] = 0;
                            gameboard[i][j+1] = temp;
                        }
                        
                /* Increment the bricks x coordinate. */
                brick_x += 1;
            }
            
        }
     
        /* If "flip brick" key is tapped, see if moving piece right is ok. */
        if(flip_brick && !new_brick)
        {
            bool move_ok = true;
            /* Find brick type rotation to change to. */
            int rotation_wanted = brick_type_rotation + 1;
            if(rotation_wanted > 3)
                rotation_wanted = 0;
    
            int i, j;
            /* Iterate through wanted brick rotation. */ 
            /* See if brick fits on the gameboard at the brick_x, brick_y location. */
            for(i = 0; i < 4; i++)
                for(j = 0; j < 4; j++)
                    if(ScanBrick(brick_type_current, rotation_wanted, i, j) == 1)
                    {
                        int check_brick_y = i + brick_y;
                        int check_brick_x = j + brick_x;
                        
                        /* Check if out of bounds. */
                        if(check_brick_y > GAMEBOARD_H-1 || check_brick_y < 0 || check_brick_x > GAMEBOARD_W-1 || check_brick_x < 0)
                        {
                            move_ok = false;
                        }
                        else
                        {
                            /* Check if it collides with something in the gameboard. */
                            if(gameboard[check_brick_y][check_brick_x] == 1 || gameboard[check_brick_y][check_brick_x] == 2 || gameboard[check_brick_y][check_brick_x] == 3)
                            {    
                                move_ok = false;
                            }
                        }
                    }
                    
            if(move_ok)
            {
                PlaySound(sounds[SOUND_BRICKMOVE]);
                
                /* If successful, increment shape_type_rotation, and make sure it loops around to 0 when needed. */
                brick_type_rotation += 1;
                if(brick_type_rotation > 3)
                    brick_type_rotation = 0;
                
                /* Remember color when rotating. */
                int color;
                
                /* Clear the gameboard of movables. */
                for(i = GAMEBOARD_H-1; i >= 0; i--)
                    for(j = GAMEBOARD_W-1; j >= 0; j--)
                        if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            color = gameboard[i][j];
                            gameboard[i][j] = 0;
                        }
                        
                /* Iterate through wanted brick. */
                /* Place on the gameboard at the brick_x, brick_y location. */
                for(i = 0; i < 4; i++)
                    for(j = 0; j < 4; j++)
                        if(ScanBrick(brick_type_current, brick_type_rotation, i, j))
                        {
                            int check_brick_y = i + brick_y;
                            int check_brick_x = j + brick_x;
                            
                            gameboard[check_brick_y][check_brick_x] = color;
                        }
            }
        }

        /* If down key is tapped, see if moving piece down is ok. */
        if(move_down && secondary_timer <= 0 && !new_brick)
        {
            /* Reset secondary timer so you cant drop the brick too fast. */
            secondary_timer = 8;
            bool move_ok = true;
    
            /* Iterate through game board. */
            int i, j;
            for(i = GAMEBOARD_H-1; i >= 0; i--)
                for(j = GAMEBOARD_W-1; j >= 0; j--)
                    if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                    {
                        /* If out of bounds. */
                        if(i+1 > GAMEBOARD_H-1)
                            move_ok = false;
                        else 
                        {
                            /* If a brick is there. */
                            if(gameboard[i+1][j] == 1 || gameboard[i+1][j] == 2 || gameboard[i+1][j] == 3)
                                move_ok = false;
                        }
                    }
                    
            if(move_ok) /* If detection is OK then move the brick. */
            {
                /* Iterate through game board. */
                int i, j;
                for(i = GAMEBOARD_H-1; i >= 0; i--)
                    for(j = GAMEBOARD_W-1; j >= 0; j--)
                        if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            int temp = gameboard[i][j];
                            gameboard[i][j] = 0;
                            gameboard[i+1][j] = temp;
                        }
                        
                /* Increment the bricks y coordinate. */
                brick_y += 1;
                brick_move_timer = brick_move_difficulty;
            }
        }
        
     
        /* brick_move_timer hits zero. game can now move bricks, spawn bricks etc. */
        if(brick_move_timer <= 0) 
        {
            /* Reset the brick_move_timer. */
            brick_move_timer = brick_move_difficulty;
    
    
            /* Spawn a new brick if one is needed! */
            if(new_brick)
            {
                brick_type_current = brick_type_next;
                brick_color_current = brick_color_next;
                
                /* Randomize next brick. */
                brick_type_next = (rand() % MAX_BRICK_TYPES);
                
                /* If its the same as last time, try one more time so two in a row is less likely. */
                if(brick_type_current == brick_type_next)
                    brick_type_next = (rand() % MAX_BRICK_TYPES);
    
    
                /* Randomize next brick color. +4 to get in the movable brick color range (4-6). */
                brick_color_next = (rand() % MAX_BRICK_COLORS) + 4;
                
                /* If its the same as last time, keep trying until its different. */
                while(brick_color_current == brick_color_next)
                    brick_color_next = (rand() % MAX_BRICK_COLORS) + 4;
                    
                /* Reset the brick rotation and location. */
                brick_type_rotation = 0;
                brick_x = 3;
                brick_y = 0;
                
                /* Place new brick on board. */
                int i, j;
                for(i = 0; i < 4; i++)
                    for(j = 3; j < 7; j++)
                    {
                        /* Width needs -3 to keep in the 4x4 brick array (j = 3 when calling ScanBrick, need to compensate). */
                        if(ScanBrick(brick_type_current, brick_type_rotation, i, j-3))
                        {
                            /* If hit an already placed brick. */
                            if(gameboard[i][j] == 1 || gameboard[i][j] == 2 || gameboard[i][j] == 3)
                            {
                                MuteAllSound();
                                PlaySound(sounds[SOUND_GAMEOVER]);
                                game_over = true;
                            }
                                
                            gameboard[i][j] = brick_color_current;  
                        }
                    }
                        
                /* No more need for a new brick, turn flag off. */                     
                new_brick = false; 
            }
    
            /* See if moving pieces have hit a brick or bottom. */
            bool brick_landed = false;
            int i, j;

            /* Iterate through game board. */
            for(i = GAMEBOARD_H-1; i >= 0; i--) 
                for(j = GAMEBOARD_W-1; j >= 0; j--)
                    if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                    {
                        /* If at bottom, or hit a brick, brickify the moving piece. */
                        if(i+1 >= GAMEBOARD_H || gameboard[i+1][j] == 1 || gameboard[i+1][j] == 2 || gameboard[i+1][j] == 3)
                        {
                            /* Iterate through game board and brickify moving pieces. */
                            int k, l;
                            for(k = GAMEBOARD_H-1; k >= 0; k--)
                                for(l = GAMEBOARD_W-1; l >= 0; l--)
                                    if(gameboard[k][l] == 4 || gameboard[k][l] == 5 || gameboard[k][l] == 6)
                                        gameboard[k][l] = gameboard[k][l]-3;
                                        
                            /* Request new brick. */
                            new_brick = true;
                            brick_landed = true;
                        }
                    }
                    
            /* If a brick was placed, add score. */
            if(brick_landed)
                score += level*10;
                
            /* Move bricks down (only if a brick is falling). */
            if(!new_brick && !move_down)
            {
                /* Iterate through game board. */
                for(i = GAMEBOARD_H-1; i >= 0; i--) 
                    for(j = GAMEBOARD_W-1; j >= 0; j--)
                        if(gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            int temp = gameboard[i][j];
                            gameboard[i][j] = 0;
                            gameboard[i+1][j] = temp;
                        }
                        
                /* Increment the bricks y coordinate from moving. */
                brick_y += 1;
            }
            
            /* Check if row should be scored. */
            int score_multiplier = 0;
            bool check_repeat = true;
            while(check_repeat)
            {
                /* Set multiplier to zero. */
                check_repeat = false;
                
                /* Iterate through game board. */
                for(i = GAMEBOARD_H-1; i >= 0; i--)
                {
                    bool row_clear = true;
                    
                    for(j = GAMEBOARD_W-1; j >= 0; j--)
                        if(gameboard[i][j] == 0 || gameboard[i][j] == 4 || gameboard[i][j] == 5 || gameboard[i][j] == 6)
                        {
                            /* If row has empty spot, or active brick, do not clear row. */
                            row_clear = false;
                        }
                    
                    /* Clear row if it passes check. */
                    if(row_clear && i > 0)
                    {
                        int k, l;
                        for(k = i; k > 0; k--)
                            for(l = GAMEBOARD_W-1; l >= 0; l--)
                                gameboard[k][l] = gameboard[k-1][l];
                                
                        /* There was a row clear this check, so repeat the process after this one is done to clear multiple rows at one time. */
                        check_repeat = true;
                        /* Increment score multiplier to multiply score and repeat score check processes for mega points. */
                        if(!score_multiplier)
                            score_multiplier = 1; /* Set initial value if multiplier == 0 */
                        score_multiplier *= 2; /* Increase the multiplier. */
                    }
                }
            }
            
            /* Set the score glow according to how many rows were eliminated. */
            if(score_multiplier >= 2)
                score_glow = 0.4f;
                
            if(score_multiplier >= 4)
                score_glow = 0.5f;
                
            if(score_multiplier >= 8)
                score_glow = 0.6f;
                
            if(score_multiplier >= 16)
                score_glow = 0.8f;
            
            /* If a row was cleared, add score. big points for multi rows. */
            if(score_multiplier > 0)
                score += 40*level*score_multiplier;
        }
    } /* if(!game_over) */
    
    /* *** Update other general logic *** */

    /* Decrement the brick_move_timer for timed game stuff */
    brick_move_timer -= time_delta * 0.1;
    /* Animation theta as well. */
    theta += time_delta * 0.01;
    /* Secondary timer for move_down input so you cant drop a brick too fast! */
    if(secondary_timer > 0)
        secondary_timer -= time_delta * 0.1;
        
    /* Update scoring glow. */
    if(score_glow > GLOW_MIN)
        score_glow -= time_delta * 0.001;
    if(score_glow < GLOW_MIN)
        score_glow = GLOW_MIN;
        
    /* Update others... */
    UpdateStarRank();
    UpdateSkillLevel();
    
    /* If the player lost, perform "game over" effects on screen. */
    if(game_over)
        UpdateGameOver();  
}