⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbavi.cpp

📁 网页游戏赤壁
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////
//	CBAvi.cpp		:	v0010
//	Written by		:	Li Haijun
//	Compiler		:	Microsoft Visual C++ 4.0 & DirectX
//	Library			:	No .Lib
//	Copyright (C)	:	1997 WayAhead Corporation 
//	v0010			:	Apr.14.1997
/////////////
// to manage the all AVI ( send message , play, stop )
//////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Assert.h"
#include "DDCompo.h"
#include "VCMApi.h"
#include "Mciapi.h"
#include "cbgame.h"
#include "CBData.h"
#include "Tbnbase.h"

#include "cbavi.h"
#include "interfac.h"
#include "DDButton.h"

// to define a global veriable to store the id of current AVI that is playing
extern struct GAME_STRUCT	GAME;
//extern	WAVEDYNAMIC	waveBack;
//////////////////////////////////////
// this is the main palettes in play state
extern	class CDDPalette	pal, palMain;
// get the current cursor
extern class CDDCursor *CURSOR_Get();

extern	MAIN_bMMX;
int		nCurrentVideoID = -1;
int		FACE_AVI_FLAG = TRUE;

// 是否全屏播放AVI, defined in CBMain.cpp
extern BOOL MAIN_AVI_bFullScreen;

extern	BOOL MAIN_InitOthers();
int bMoviePlaying = FALSE;
// 播放AVI
void	FACE_Avi_Play(LPSTR lpszAviFilename, int nCommandState /*=COMMAND_STATE_AVI_MISSION*/ )
{
	FACE_SetProgramState(PROGRAM_STATE_AVI) ;
	// to erase the whole screen to black
	DD_EraseFrontScreen();

//	WriteLogFile( "sound.log","AAAAA\n" );
	if( GAME_nDisk == 0 )
	{
		// stop playing music
		DATA_WAVE_MusicStop();
	}
	// close the sound first
	DS_QuitSound() ;
//	WriteLogFile( "sound.log","BBBBB\n" );

	CDDCursor * pCurrentCursor;
	// to get the current cursor and hide it
	pCurrentCursor = CURSOR_Get();
	if(pCurrentCursor != NULL)
	{
		// to hide current cursor if it is exist
		pCurrentCursor->Show(FALSE);
		// to erase the whole screen to black
		DD_EraseFrontScreen();
	}
	// to set all button's state to disable
	FACE_SetAllButtonState( BUTTON_DISABLE );

	if( FACE_AVI_FLAG == FALSE)
	{
		FACE_SetCommandState( nCommandState );
		PostMessage( hwndGame, MM_MCINOTIFY, 0, 0 );
		return;
	}
//	WriteLogFile( "sound.log","CCCCC\n" );
	if( MAIN_bMMX == TRUE )
	{
		Assert( bMoviePlaying == FALSE );
		MovieInitialize( hwndGame );
		while( MovieFileOpen (hwndGame, lpszAviFilename ) == FALSE )
		{
			// Aug 11, 1997, Liu Gang
			// if no avi, quit
			ErrorMessageNoQuit( hwndGame, 1011, "Insert game CD please!\n" );
//			PostMessage( hwndGame, WM_QUIT, 0, 65535 );
//			return;
		}
		MoviePause( hwndGame );
		MovieSetOptionsBitdepth (hwndGame, ID_OPTIONS_BITDEPTH_CLUT8);
		MovieSetOptionsResolution (hwndGame, ID_OPTIONS_RESOLUTION_ZOOMBY2);
		//MovieSetOptionsResolution (hwndGame, ID_OPTIONS_RESOLUTION_NATIVE);
		MoviePlay ( hwndGame );
		nCurrentVideoID = MovieGetHandle();
		bMoviePlaying = TRUE;
	}
	else
	{
		RECT rect={160, 120, 480, 360 };
		Assert( nCurrentVideoID == -1 );
		nCurrentVideoID = MCI_AVI_Open( hwndGame, lpszAviFilename, &rect );
		while( nCurrentVideoID == -1 )
		{
			// Aug 11, 1997, Liu Gang
			// if no avi, quit
			ErrorMessageNoQuit( hwndGame, 1011, "Insert game CD please!\n" );
//			PostMessage( hwndGame, WM_QUIT, 0, 65535 );
			nCurrentVideoID = MCI_AVI_Open( hwndGame, lpszAviFilename, &rect );
//			return;
		}
		Assert( nCurrentVideoID != -1 );
		if( MAIN_AVI_bFullScreen == TRUE )
			MCI_AVI_Play( hwndGame, nCurrentVideoID, MCI_NOTIFY|MCI_MCIAVI_PLAY_FULLSCREEN );
		else
			MCI_AVI_Play( hwndGame, nCurrentVideoID );
		Sleep(100);
	}

	// CD Audio only, Nov.8.1997
	if( GAME_nDisk != 0 )
	{
		// stop playing music
		DATA_WAVE_MusicStop();
	}
//	WriteLogFile( "sound.log","DDDDD\n" );
	FACE_SetCommandState( nCommandState );

}
//  to play the single fight avi
void	FACE_Avi_Play_Single_Fight( int nCommandState /*=COMMAND_STATE_AVI_MISSION*/ )
{
	// to erase the whole screen to black
	DD_EraseFrontScreen();

//	WriteLogFile( "avi.log","AAAAA\n" );

	if( GAME_nDisk == 0 )
	{
		// stop playing music
		DATA_WAVE_MusicStop();
	}

	// close the sound first
	DS_QuitSound() ;
//	WriteLogFile( "sound.log","BBBBB\n" );

	CDDCursor * pCurrentCursor;
	// to get the current cursor and hide it
	pCurrentCursor = CURSOR_Get();
	if(pCurrentCursor != NULL)
	{
		// to hide current cursor if it is exist
		pCurrentCursor->Show(FALSE);
		// to erase the whole screen to black
		DD_EraseFrontScreen();
	}
	// to set all button's state to disable
	FACE_SetAllButtonState( BUTTON_DISABLE );
	FACE_SetProgramState( PROGRAM_STATE_AVI ) ;
	FACE_SetCommandState( COMMAND_STATE_AVI_SINGLE ) ;

	if( FACE_AVI_FLAG == FALSE )
	{
		FACE_SetCommandState( nCommandState );
		PostMessage( hwndGame, MM_MCINOTIFY, 0, 0 );
		return;
	}

	RECT rect={160, 120, 480, 360 };
	Assert( nCurrentVideoID == -1 );
	char avifile[_MAX_FNAME];
	strcpy( avifile, GAME_strSetupDirectory );
	strcat( avifile, "\\avi\\ldan.avi" );
	nCurrentVideoID = MCI_AVI_Open( hwndGame, avifile, &rect );
	if( nCurrentVideoID == -1 )
	{
		PostMessage( hwndGame, MM_MCINOTIFY, 0, 0 );
		return;
	}
	Assert( nCurrentVideoID != -1 );

	int	random ;
	int Begin, End ;

	random = getrandom(0,17) ;
//	random = 0;

	Begin = 90 * random ;	// every single fight avi include 90 frames
	End = Begin + 90 ;

	char tm[32];
	itoa( random, tm, 10 );
//	MCI_AVI_Play( hwndGame, nCurrentVideoID, MCI_NOTIFY|MCI_MCIAVI_PLAY_FULLSCREEN, Begin, End );
	MCI_AVI_Play( hwndGame, nCurrentVideoID, MCI_NOTIFY, Begin, End );

	// CD Audio only, Nov.8.1997
	if( GAME_nDisk != 0 )
	{
		// stop playing music
		DATA_WAVE_MusicStop();
	}
}

//	to restore the program state and close the avi file when receive the MM_MCINOTIFY
extern BOOL MAIN_bFirst;	// defined in CBMain.cpp
BOOL	FACE_Avi_Close()
{

	if( (FACE_GetCommandState() == COMMAND_STATE_AVI_BEGIN ) ||
		(FACE_GetCommandState() == COMMAND_STATE_AVI_END ) ||
		(FACE_GetCommandState() == COMMAND_STATE_AVI_MISSION ) ||
		(FACE_GetCommandState() == COMMAND_STATE_AVI_REALTIME ) ||
		(FACE_GetCommandState() == COMMAND_STATE_AVI_SINGLE ) ||
		(FACE_GetCommandState() == COMMAND_STATE_AVI_HISTORY ) 
	  )
	{	// 会接收到两次消息
		// to erase the whole screen to black
		DD_EraseFrontScreen();

		// to do the next thing by the current program state
		int		nCommandState;

		nCommandState = FACE_GetCommandState();
		if( GAME_nDisk != 0 )
		{
			if( MAIN_bMMX == TRUE 
			&& FACE_GetCommandState() != COMMAND_STATE_AVI_SINGLE )
			{
				MovieStop( hwndGame );
			}
			else
			{
				MCI_AVI_Stop( hwndGame, nCurrentVideoID );
			}
			if( nCommandState == COMMAND_STATE_AVI_BEGIN )
			{
				char wavfile[_MAX_FNAME];
				strcpy( wavfile, GAME_strSetupDirectory );
				strcat( wavfile, "\\sound\\Start.wav" );
				DATA_WAVE_MusicPlayS( wavfile );
				strcpy( GAME.strStartWAV, wavfile );
			}
			else if( nCommandState == COMMAND_STATE_AVI_END )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );
			}
			else if( nCommandState == COMMAND_STATE_AVI_MISSION )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );
			}
			else if( nCommandState == COMMAND_STATE_AVI_REALTIME )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );
			}
			else if( nCommandState == COMMAND_STATE_AVI_SINGLE )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );
			}
			else if( nCommandState == COMMAND_STATE_AVI_HISTORY )
			{
				char wavfile[_MAX_FNAME];
				strcpy( wavfile, GAME_strSetupDirectory );
				strcat( wavfile, "\\sound\\Start.wav" );
				DATA_WAVE_MusicPlayS( wavfile );
			}
		}


		if( FACE_AVI_FLAG == FALSE )
		{
		}
		else if( MAIN_bMMX == TRUE 
			&& FACE_GetCommandState() != COMMAND_STATE_AVI_SINGLE )
		{
			Assert( bMoviePlaying == TRUE );
			if( GAME_nDisk == 0 )
			{
				MovieStop( hwndGame );
			}
			MovieFileClose( hwndGame );
			MovieTerminate( hwndGame );
			nCurrentVideoID = -1;
			bMoviePlaying = FALSE;
		}
		else
		{
			Assert( nCurrentVideoID != -1 );
			if( GAME_nDisk == 0 )
			{
				MCI_AVI_Stop( hwndGame, nCurrentVideoID );
			}
			MCI_AVI_Close( nCurrentVideoID );
			nCurrentVideoID = -1;
		}

		// to get the sound device 
		DS_InitSound( hwndGame ) ;

		// what are you going to do after play the begin AVI
		if( nCommandState == COMMAND_STATE_AVI_BEGIN )
		{
			DD_EraseFrontScreen();
			MAIN_InitOthers();

			//to play the sound 
			//DATA_WAVE_MusicPlay( GAME.nMusicID );

			if( GAME_nDisk == 0 )
			{
				char wavfile[_MAX_FNAME];
				strcpy( wavfile, GAME_strSetupDirectory );
				strcat( wavfile, "\\sound\\Start.wav" );
				DATA_WAVE_MusicPlayS( wavfile );
				strcpy( GAME.strStartWAV, wavfile );
			}
			
			GAME.nID = 0;
			FACE_SetProgramState( PROGRAM_STATE_PLAY );
			FACE_SetCommandState( COMMAND_STATE_PLAY );
			SendMessage(hwndGame, WM_COMMAND, SHOW_MAIN_MENU, 0);
			// to restore all button's state
			FACE_RestoreAllButtonState();
		}
		// what are you going to do after play the end AVI
		else if( nCommandState == COMMAND_STATE_AVI_END )
		{
			//to play the sound 
			if( GAME_nDisk == 0 )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );
			}
			//DATA_WAVE_MusicPlay(0) ;
//			WriteLogFile( "sound.log","IIIII\n" );
			// to restore all button's state
			FACE_RestoreAllButtonState();
		}
		// what are you going to do after play the mission AVI
		else if( nCommandState == COMMAND_STATE_AVI_MISSION )
		{
			// to restore the palette
			palMain.ReloadPalette();
			//--fade in
			DD_FadeClear( palMain.GetPalette() );
			palMain.SetPalette();
			//--fade in

			// to get current cursor and show it
			CURSOR_Get()->Show(TRUE);
//			FACE_SetProgramState( FACE_GetPreProgramState() );
			FACE_SetProgramState( PROGRAM_STATE_PLAY );
			FACE_SetCommandState( COMMAND_STATE_MENU );

			//to play the sound 
			if( GAME_nDisk == 0 )
			{
				DATA_WAVE_MusicPlay( GAME.nMusicID );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -