📄 boxman.c
字号:
break;
default:
pApp->m_ManY++;
return TRUE;
}
}
else if(0 == (first_point & ~DEST) )
{
pApp->m_pMap[pApp->m_ManY*MAP_WIDTH+pApp->m_ManX] |= MAN;
Boxman_DrawMan(pApp,pApp->m_ManX,pApp->m_ManY);
}
else
{
pApp->m_ManY++;
return TRUE;
}
/* draw the map */
pApp->m_pMap[(pApp->m_ManY+1)*MAP_WIDTH+pApp->m_ManX] &= ~MAN;
switch(pApp->m_pMap[(pApp->m_ManY+1)*MAP_WIDTH+pApp->m_ManX])
{
case DEST:
Boxman_DrawDest(pApp,pApp->m_ManX,(S16)(pApp->m_ManY+1));
break;
default:
Boxman_DrawBG(pApp,pApp->m_ManX,(S16)(pApp->m_ManY+1));
break;
}
Boxman_CheckScreen(pApp);
break;
case AVK_DOWN:
pApp->m_ManY++;
first_point = pApp->m_pMap[pApp->m_ManY*MAP_WIDTH+pApp->m_ManX];
if(first_point & BOX) /* a box on the left side of the man*/
{
if(first_point & MAN)
{
pApp->m_ManY--;
return TRUE;
}
second_point = pApp->m_pMap[(pApp->m_ManY+1)*MAP_WIDTH+pApp->m_ManX];
switch(second_point)
{
case DEST:
if(!(first_point & DEST)) //box not on the dest
{
pApp->m_Arrived++;
}
second_point |= BOX;
pApp->m_pMap[(pApp->m_ManY+1)*MAP_WIDTH+pApp->m_ManX] = second_point;
Boxman_DrawBox(pApp,pApp->m_ManX,(S16)(pApp->m_ManY+1));
first_point = (first_point & ~BOX) | MAN;
pApp->m_pMap[pApp->m_ManY*MAP_WIDTH+pApp->m_ManX] = first_point;
Boxman_DrawMan(pApp,pApp->m_ManX,pApp->m_ManY);
break;
case BKGR:
if(first_point & DEST) //box on the dest
{
pApp->m_Arrived--;
}
second_point |= BOX;
pApp->m_pMap[(pApp->m_ManY+1)*MAP_WIDTH+pApp->m_ManX] = second_point;
Boxman_DrawBox(pApp,pApp->m_ManX,(S16)(pApp->m_ManY+1));
first_point = (first_point & ~BOX) | MAN;
pApp->m_pMap[pApp->m_ManY*MAP_WIDTH+pApp->m_ManX] = first_point;
Boxman_DrawMan(pApp,pApp->m_ManX,pApp->m_ManY);
break;
default:
pApp->m_ManY--;
return TRUE;
}
}
else if(0 == (first_point & ~DEST) )
{
pApp->m_pMap[pApp->m_ManY*MAP_WIDTH+pApp->m_ManX] |= MAN;
Boxman_DrawMan(pApp,pApp->m_ManX,pApp->m_ManY);
}
else
{
pApp->m_ManY--;
return TRUE;
}
/* draw the map */
pApp->m_pMap[(pApp->m_ManY-1)*MAP_WIDTH+pApp->m_ManX] &= ~MAN;
switch(pApp->m_pMap[(pApp->m_ManY-1)*MAP_WIDTH+pApp->m_ManX])
{
case DEST:
Boxman_DrawDest(pApp,pApp->m_ManX,(S16)(pApp->m_ManY-1));
break;
default:
Boxman_DrawBG(pApp,pApp->m_ManX,(S16)(pApp->m_ManY-1));
break;
}
Boxman_CheckScreen(pApp);
break;
default:
return FALSE;
}
if(pApp->m_BoxNum == pApp->m_Arrived)
Boxman_DisplaySuccess(pApp);
return TRUE;
}
/* DevBitBlt
*
* Renders Image piece to device
*/
static void DevBitBlt(CBoxman* pApp,
S16 destX, S16 destY,
S16 width, S16 height,
S16 srcX, S16 srcY,
const unsigned char * imageData, S32 imageLen)
{
IDIB *pdib=NULL;
U8 flag;
if(!(kUPCBMPSig0==*(imageData+kUPCBMPSigOffset0) && kUPCBMPSig1==*(imageData+kUPCBMPSigOffset1)) ) return;
if(SUCCESS!=IDISPLAY_CreateDIBitmap(pApp->a.m_pIDisplay,
(IDIB **)&pdib,
(uint8)*(imageData+kUPCBMPColorDepthOffset),
0,
0
))
return ;
pdib->cx = UPCBMPGetU16(imageData+kUPCBMPImageWidthOffset);
pdib->cy = UPCBMPGetU16(imageData+kUPCBMPImageHeightOffset);
pdib->nDepth = *(imageData+kUPCBMPColorDepthOffset);
pdib->nPitch = UPCBMPGetU16(imageData+kUPCBMPRowBytesOffset);
pdib->pBmp = (U8 *)(imageData+kUPCBMPHeaderSize);
pdib->pRGB = 0;
pdib->ncTransparent = UPCBMPGetU32(imageData+kUPCBMPTransparentColorOffset);
pdib->cntRGB = 0;
if(8 == pdib->nDepth)
{
pdib->nColorScheme = IDIB_COLORSCHEME_332;
}
else if(16 == pdib->nDepth)
{
pdib->nColorScheme = IDIB_COLORSCHEME_565;
}
else
{
pdib->nColorScheme = IDIB_COLORSCHEME_888;
}
flag = *(imageData+kUPCBMPFlagsOffset);
flag = flag&0x02;
IDISPLAY_BitBlt( pApp->a.m_pIDisplay,
destX,
destY,
width,
height,
IDIB_TO_IBITMAP(pdib),
srcX,
srcY,
flag?AEE_RO_TRANSPARENT:AEE_RO_COPY );
IDIB_Release(pdib);
}
static void Boxman_DrawMan(CBoxman* pApp,S16 x,S16 y)
{
DevBitBlt(pApp,(S16)(x*6),(S16)(y*6),6,6,0, 0,manbmp,0);
}
static void Boxman_DrawWall(CBoxman* pApp,S16 x,S16 y)
{
DevBitBlt(pApp,(S16)(x*6),(S16)(y*6),6,6,0, 0,wallbmp,0);
}
static void Boxman_DrawBG(CBoxman* pApp,S16 x,S16 y)
{
DevBitBlt(pApp,(S16)(x*6),(S16)(y*6),6,6,0, 0,bgbmp,0);
}
static void Boxman_DrawBox(CBoxman* pApp,S16 x,S16 y)
{
DevBitBlt(pApp,(S16)(x*6),(S16)(y*6),6,6,0, 0,boxbmp,0);
}
static void Boxman_DrawDest(CBoxman* pApp,S16 x,S16 y)
{
DevBitBlt(pApp,(S16)(x*6),(S16)(y*6),6,6,0, 0,destbmp,0);
}
/* Display Success Prompt */
static boolean Boxman_DisplaySuccess(CBoxman * pApp)
{
AECHAR szText[64];
(void) ISHELL_LoadResString(pApp->a.m_pIShell,
BOXMAN_RES_FILE,
IDS_SUCCESSPROMPT,
szText,
sizeof(szText));
DevDrawDialog(pApp,(const AECHAR *)szText);
pApp->m_nState = STATE_SUCCESS;
return TRUE;
}
static boolean Boxman_SuccessHandleKey(CBoxman * pApp,
uint16 wParam,
uint32 dwParam)
{
switch(wParam)
{
case AVK_CLR:
Boxman_ReadMap(pApp,pApp->m_nCurMap);
return Boxman_GameStart(pApp);
case AVK_SELECT:
pApp->m_nCurMap ++;
if(FALSE == Boxman_ReadMap(pApp,pApp->m_nCurMap))
{
pApp->m_nCurMap --;
Boxman_ReadMap(pApp,pApp->m_nCurMap);
}
return Boxman_GameStart(pApp);
default:
return FALSE;
}
}
/* Display Quit Prompt */
static boolean Boxman_DisplayQuit(CBoxman * pApp)
{
AECHAR szText[64];
(void) ISHELL_LoadResString(pApp->a.m_pIShell,
BOXMAN_RES_FILE,
IDS_QUITPROMPT,
szText,
sizeof(szText));
DevDrawDialog(pApp,(const AECHAR *)szText);
pApp->m_nState = STATE_QUIT;
return TRUE;
}
static boolean Boxman_QuitHandleKey(CBoxman * pApp,
uint16 wParam,
uint32 dwParam)
{
switch(wParam)
{
case AVK_CLR:
Boxman_ReadMap(pApp,pApp->m_nCurMap);
return Boxman_GameStart(pApp);
case AVK_SELECT:
pApp->m_nState = NULL;
ISHELL_CloseApplet(pApp->a.m_pIShell,TRUE);
return TRUE;
default:
return FALSE;
}
}
/* Select Stage */
static boolean Boxman_SelectStage(CBoxman * pApp)
{
ITextCtl *pITextCtl = NULL;
AEERect nTextRect;
if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_TEXTCTL, (void**)(&pApp->m_pObj)) != SUCCESS)
{
return FALSE;
}
pITextCtl = (ITextCtl*)pApp->m_pObj;
/* Set the neccessary properiety */
SETAEERECT(&nTextRect,
pApp->m_nClntAreaRect.x,
(pApp->m_nClntAreaRect.dy-pApp->m_nLargeLineHeight*3)/2,
pApp->m_nClntAreaRect.dx,
pApp->m_nLargeLineHeight*3) ;
ITEXTCTL_SetRect(pITextCtl, &nTextRect);
ITEXTCTL_SetProperties(pITextCtl, TP_FRAME);
ITEXTCTL_SetMaxSize(pITextCtl, 2);
ITEXTCTL_SetTitle(pITextCtl, BOXMAN_RES_FILE, IDS_STAGENUM, NULL);
/* Set the Text entry mode into PY mode */
ITEXTCTL_SetInputMode(pITextCtl, AEE_TM_NUMBERS);
ITEXTCTL_SetActive(pITextCtl, TRUE);
pApp->m_nState = STATE_SELSTAGE;
return TRUE;
}
static boolean Boxman_SelectStageHandleKey(CBoxman * pApp,
uint16 wParam,
uint32 dwParam)
{
ITextCtl *pITextCtl = NULL;
AECHAR * buffer =NULL;
int result =0;
pITextCtl = (ITextCtl *)pApp->m_pObj;
buffer = ITEXTCTL_GetTextPtr(pITextCtl);
switch(wParam)
{
case AVK_CLR:
if(2>WSTRLEN(buffer))
{
Boxman_ReleaseObj( (void **)&pApp->m_pObj);
Boxman_ReadMap(pApp,pApp->m_nCurMap);
return Boxman_GameStart(pApp);
}
else
{
return ITEXTCTL_HandleEvent(pITextCtl,EVT_KEY,wParam,dwParam);
}
case AVK_SELECT:
{
while(0 != *buffer)
{
result = result *10 + *buffer - 0x30;
buffer ++;
}
if(result <= 58 && result >0)
pApp->m_nCurMap = result;
else
return FALSE;
}
Boxman_ReleaseObj( (void **)&pApp->m_pObj);
Boxman_ReadMap(pApp,pApp->m_nCurMap);
return Boxman_GameStart(pApp);
default:
return ITEXTCTL_HandleEvent(pITextCtl,EVT_KEY,wParam,dwParam);
}
}
static boolean Boxman_ReadMap(CBoxman * pApp,U8 mapId)
{
IFileMgr *pIFileMgr=NULL;
IFile *pIFile = NULL;
char *filename = NULL;
S32 length=0;
if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_FILEMGR, (void**)(&pIFileMgr)) != SUCCESS)
{
return FALSE;
}
filename = (char *)MALLOC(kMaxFileNameLength);
if(NULL == filename)
{
FREE(filename);
Boxman_ReleaseObj( (void **)&pIFileMgr );
return FALSE;
}
MEMSET(filename,0,kMaxFileNameLength);
Boxman_makePathnameFromID(filename, mapId);
pIFile = IFILEMGR_OpenFile(pIFileMgr,(const char *)filename,_OFM_READ);
if(NULL == pIFile)
{
FREE(filename);
Boxman_ReleaseObj( (void **)&pIFileMgr );
return FALSE;
}
FREE(filename);
length = MAP_WIDTH * MAP_HEIGHT;
if(SUCCESS != IFILE_Seek(pIFile,_SEEK_START,0))
{
IFILE_Release(pIFile);
Boxman_ReleaseObj( (void **)&pIFileMgr );
return FALSE;
}
if(length != IFILE_Read(pIFile,pApp->m_pMap,length))
{
IFILE_Release(pIFile);
Boxman_ReleaseObj( (void **)&pIFileMgr );
return FALSE;
}
IFILE_Release(pIFile);
Boxman_ReleaseObj( (void **)&pIFileMgr );
return TRUE;
}
static void Boxman_makePathnameFromID(char* filename, U8 mapId)
{
/*
Given the five-digit id nnnnn, put the string
"map/mapn" in the filename buffer.
Use this function when you need an absolute path
to the permanent storage location.
*/
STRCPY(filename, kMAPPath"/" kFilePrefix);
Boxman_Itoa(filename+STRLEN(filename), (S32)mapId);
}
/*translate an integer into decimal string
and return the length of string.
*/
static U32 Boxman_Itoa(U8* buffer, S32 eger)
{
U32 len, ueger;
boolean minusP;
minusP = (eger < 0);
if(minusP)
{
if(buffer)
{
*(buffer++) = '-';
}
ueger = (U32)(0 - eger);
}
else
{
ueger = (U32)eger;
}
{
U32 tmp;
tmp = ueger;
len = 1;
while ( (tmp /= 10) ) len += 1;
}
{
U32 pt;
pt = len;
if (buffer) buffer[pt] = 0;
while(pt--)
{
if (buffer)
{
buffer[pt] = (char)('0' + (ueger % 10));
}
ueger /= 10;
}
}
return (len + 1 + minusP);
}
static void DevDrawDialog(CBoxman * pApp,const AECHAR *szText)
{
const AECHAR *p;
AEERect nRect;
int nFits = 0;
int width = 0;
int height = pApp->m_nLineHeight;
int length = 0;
int max_width = pApp->m_nClntAreaRect.dx - 10;
#define DIALOG_BORDER_WIDTH 1
p = szText;
/* calculate the height */
while(*p)
{
width = IDISPLAY_MeasureTextEx(pApp->a.m_pIDisplay,
AEE_FONT_NORMAL,
p,
-1,
max_width,
&nFits);
height += pApp->m_nLineHeight;
p+=nFits;
}
/* more that one line */
if(height > pApp->m_nLineHeight + pApp->m_nLineHeight)
width = max_width;
/* set the display area and fill it */
SETAEERECT(&nRect,(pApp->m_nClntAreaRect.dx-width)/2-DIALOG_BORDER_WIDTH,(pApp->m_nClntAreaRect.dy-height)/2,width+DIALOG_BORDER_WIDTH,height);
IDISPLAY_DrawRect(pApp->a.m_pIDisplay,&nRect,kColorClearDialogBox,kColorClearDialogBackground,IDF_RECT_FRAME|IDF_RECT_FILL);
/* draw text*/
nRect.x += DIALOG_BORDER_WIDTH;
nRect.dx -= DIALOG_BORDER_WIDTH;
p = szText;
height = nRect.y+pApp->m_nLineHeight/2;
while(*p)
{
width = IDISPLAY_MeasureTextEx(pApp->a.m_pIDisplay,
AEE_FONT_NORMAL,
p,
-1,
max_width,
&nFits);
IDISPLAY_DrawText(pApp->a.m_pIDisplay,
AEE_FONT_NORMAL,
p,
nFits,
nRect.x,
height,
&nRect,
IDF_TEXT_TRANSPARENT);
p+=nFits;
height +=pApp->m_nLineHeight;
}
Boxman_CheckScreen(pApp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -