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

📄 ducati.cpp

📁 这是一个用BREW和VC++开发的暴力摩托游戏,与大家一同分享.
💻 CPP
字号:
/*===========================================================================
FILE: Ducati.c
Brew Interface
===========================================================================*/
#include "Ducati.h"

/*===========================================================================
FUNCTION: AEEClsCreateInstance
Create application interface between game app and BREW
===========================================================================*/

extern "C" int AEEClsCreateInstance(AEECLSID ClsId, IShell* pIShell, IModule* pIModule, void** ppObj)
{
	*ppObj = NULL;
	
	if( ClsId == AEECLSID_DUCATIRACING )
	{
		// Create the applet and make room for the applet structure
		if( AEEApplet_New(sizeof(Ducati),
                          ClsId,
                          pIShell,
                          pIModule,
                          (IApplet**)ppObj,
						  (AEEHANDLER)Ducati::HandleEvent,
						  (PFNFREEAPPDATA)Ducati::FreeData) ) 
		{
			return(AEE_SUCCESS);
		}
    }
	return(EFAILED);
}

/*===========================================================================
METHOD Ducati::HandleEvent
Function call back for event handing function
===========================================================================*/
boolean Ducati::HandleEvent(Ducati* pDucati, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{   
	return pDucati->AppHandleEvent(eCode, wParam, dwParam);
}

/*===============================================================================
METHOD: FreeData
Function call back for freeing up the app instance
=============================================================================== */
void  Ducati::FreeData(Ducati *pDucati)
{
	pDucati->AppFreeData();
}

/*===========================================================================
METHOD Ducati::AppHandleEvent
The actual event handing function
===========================================================================*/
boolean Ducati::AppHandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  

    switch (eCode) 
	{
        case EVT_APP_START:
			m_pGameFrame = new GameFrame(this, m_pIShell);
			if(m_pGameFrame)
				return( m_pGameFrame->Init() );
			return(TRUE);
	
	

    case EVT_NEXT_FRAME:
			m_pGameFrame->GameLoop();
      return(TRUE);

		case EVT_APP_STOP:
      		return(TRUE);


        case EVT_APP_SUSPEND:
		{
			boolean bStopSnd = TRUE;
			m_pGameFrame->m_bRunning = FALSE;
			//YingZ: Need to check if we are in frontend
			if(m_pGameFrame->m_gameState == GS_RACING)
				m_pGameFrame->PauseGame(bStopSnd);
			//YingZ: just to be super safe - suspend the sound last.
			//m_pGameFrame->StopSound();
			m_pGameFrame->StopSound(true);			
      		return(TRUE);
		}


        case EVT_APP_RESUME:
			
			m_pGameFrame->m_bRunning = TRUE;
			m_pGameFrame->GameTick(FRAMETIMEMS);
			m_pGameFrame->StartSound(true);
			//m_pGameFrame->StartSound();
			//YingZ: Need to check if we are in frontend
			if(m_pGameFrame->m_gameState == GS_RACING)
				m_pGameFrame->UnpauseGame();
      		return(TRUE);

		//case EVT_APP_NO_SLEEP: 
		//	return (TRUE); 


        case EVT_APP_MESSAGE:
      		return(TRUE);


		case EVT_KEY:
			m_pGameFrame->KeyPressed(wParam);
      		return(TRUE);

		case EVT_KEY_RELEASE:
			m_pGameFrame->KeyReleased(wParam);
			return( TRUE );

        default:
            break;
   }

   return FALSE;
}

/*===============================================================================
METHOD: AppFreeData
Delete and clear up
=============================================================================== */
void Ducati::AppFreeData()
{
	if ( m_pGameFrame )
		delete m_pGameFrame;
}

/////////////////////////////////////////////////////////////////
// Overloaded new and free operators

#define HEADER_SIZE	(sizeof(int)*2)
#define FOOTER_SIZE (sizeof(int))
#define HEADER_PATTERN 0xFEEDFEED
#define FOOTER_PATTERN 0xBEEFBEEF

void* operator new( size_t size )
{
#ifdef DEBUG
	return(DebugMalloc(size));
#else
	return MALLOC(size);
#endif
}
void* operator new []( size_t size )
{
#ifdef DEBUG
	return(DebugMalloc(size));
#else
	return MALLOC(size);
#endif
}
void operator delete( void* ptr )
{
#ifdef DEBUG
	DebugFree(ptr);
#else
	FREE(ptr);
#endif
}
void operator delete [](void * ptr)
{
#ifdef DEBUG
	DebugFree(ptr);
#else
	FREE(ptr);
#endif
}

void* DebugMalloc(size_t size)
{
    void* ptr;

	ptr = MALLOC(HEADER_SIZE + size + FOOTER_SIZE);
	
	if(!ptr)
	{
		DBGPRINTF("Failed to Allocated requested memory");
		assert(0);
	}
	else
	{
		MEMSET(ptr,-1,HEADER_SIZE + size + FOOTER_SIZE);
		*((int*)ptr) = HEADER_PATTERN;
		*((int*)((char*)ptr + sizeof(int))) = (int)size;
		*((int*)((char*)ptr + HEADER_SIZE + size)) = FOOTER_PATTERN;
	}
	
	return((void*)((char*)ptr+HEADER_SIZE));
}

void DebugFree(void* ptr)
{
	if( *((int*)((char*)ptr - HEADER_SIZE)) != HEADER_PATTERN && 
		*((int*)((char*)ptr + *((int*)((char*)ptr - sizeof(int))))) != FOOTER_PATTERN )
	{
		DBGPRINTF("memory trashed!");
		assert(0);
	}
	else
	{
		FREE((void*)((char*)ptr - HEADER_SIZE));
	}

}



⌨️ 快捷键说明

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