📄 play_managefish.c
字号:
case FOEMAN_LEV2:
break;
case FOEMAN_LEV3:
break;
}
}
//temp = GETFISH_OBJID(pMotion->pSprite->nCtrlFlag);
if ( GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) < 8 )
{//keep chase state
//keep counter ++
SETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag, (GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) + 1));
//chase object fish
_Chase(pMotion);
}
else
{//chase state end
//change state to normal
SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
//reset object fish's ObjID
SETFISH_OBJID(pFish1[GETFISH_OBJID(pMotion->pSprite->nCtrlFlag)]->pSprite->nCtrlFlag, 0x1F);
SETFISH_ST(pFish1[GETFISH_OBJID(pMotion->pSprite->nCtrlFlag)]->pSprite->nCtrlFlag, STATE_NORMAL );
//reset own object fish index
SETFISH_OBJID(pMotion->pSprite->nCtrlFlag, 0x1F);
}
}
void _Dodge(MOTION *pMotion)
{
//add speed for dodging
//if ( GETFISH_VX(pMotion->pSprite->nCtrlFlag) < MAXSPEED_LEV1 )
{
SETFISH_VX(pMotion->pSprite->nCtrlFlag, MAXSPEED_LEV1);//(GETFISH_VX(pMotion->pSprite->nCtrlFlag) + 1));
}
//if ( GETFISH_VY(pMotion->pSprite->nCtrlFlag) < (MAXSPEED_LEV1 >> 1) )
{
SETFISH_VY(pMotion->pSprite->nCtrlFlag, (MAXSPEED_LEV1>>1) );//(GETFISH_VY(pMotion->pSprite->nCtrlFlag) + 1));
}
}
void _StateProc_Dodge(MOTION *pMotion)
{
U8 i;
if ( GETFISH_OBJID(pMotion->pSprite->nCtrlFlag) == 0x1F )
{
SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
return;
}
if ( GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) < 8 )
{//keep chase state
//keep counter ++
SETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag, (GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) + 1));
//dodge object fish
_Dodge(pMotion);
}
else
{//chase state end
//change state to normal
SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
}
}
*/
void Play_LimitSpeed(MOTION *pMotion)
{
switch( GETFISH_LEV(pMotion->pSprite->nCtrlFlag) )
{
case FOEMAN_LEV1:
if ( GETFISH_VX(pMotion->pSprite->nCtrlFlag) > MAXSPEED_LEV1 )
{
SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) - 1) );
}
if ( GETFISH_VY(pMotion->pSprite->nCtrlFlag) > (MAXSPEED_LEV1>>1) )
{
SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) - 1) );
}
break;
case FOEMAN_LEV2:
if ( GETFISH_VX(pMotion->pSprite->nCtrlFlag) > MAXSPEED_LEV2 )
{
SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) - 1) );
}
if ( GETFISH_VY(pMotion->pSprite->nCtrlFlag) > (MAXSPEED_LEV2/3) )
{
SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) - 1) );
}
break;
case FOEMAN_LEV3:
if ( GETFISH_VX(pMotion->pSprite->nCtrlFlag) > MAXSPEED_LEV3 )
{
SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) - 1) );
}
if ( GETFISH_VY(pMotion->pSprite->nCtrlFlag) > (MAXSPEED_LEV3/3) )
{
SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) - 1) );
}
break;
}
}
void ProcFish1(MOTION *pMotion)
{
//check fish state change or not
if ( Sys_Random(10) > 3
&& (GETFISH_ST(pMotion->pSprite->nCtrlFlag) == STATE_NORMAL) )
{//change fish state(this state is not action) by 60% odds
SETFISH_ST(pMotion->pSprite->nCtrlFlag, Sys_Random(STATE_MAXNUM) );
SETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag, 0);
}
//keep state
switch( GETFISH_ST(pMotion->pSprite->nCtrlFlag) )
{
case STATE_CHANGEWAY:
_StateProc_ChangeWay(pMotion);
break;
case STATE_ADDSPEED:
_StateProc_AddSpeed(pMotion);
break;
case STATE_SUBSPEED:
_StateProc_SubSpeed(pMotion);
break;
case STATE_CHASE:
SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL );
//_StateProc_Chase(pMotion);
break;
case STATE_DODGE:
SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL );
//_StateProc_Dodge(pMotion);
break;
}
//move fish by screen step
_SpFollowScreen(pMotion);
//move fish by speed
if ( GETFISH_AX(pMotion->pSprite->nCtrlFlag) )
{
pMotion->pSprite->stPos.x += FishStep[GETFISH_VX(pMotion->pSprite->nCtrlFlag)];
if (pMotion->pSprite->stPos.x > SCREEN_WIDTH + 256)
{//return to screen
SETFISH_AX(pMotion->pSprite->nCtrlFlag, TO_LEFT);
E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));
}
}
else
{
pMotion->pSprite->stPos.x -= FishStep[GETFISH_VX(pMotion->pSprite->nCtrlFlag)];
if (pMotion->pSprite->stPos.x + pMotion->pSprite->pFrame->stSize.width < -256)
{//return to screen
SETFISH_AX(pMotion->pSprite->nCtrlFlag, TO_RIGHT);
E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));
}
}
if ( GETFISH_AY(pMotion->pSprite->nCtrlFlag) )
{
pMotion->pSprite->stPos.y += FishStep[GETFISH_VY(pMotion->pSprite->nCtrlFlag)];
if (pMotion->pSprite->stPos.y > SCREEN_HEIGHT + 256)
{//return to screen
SETFISH_AY(pMotion->pSprite->nCtrlFlag, TO_UP);
}
}
else
{
pMotion->pSprite->stPos.y -= FishStep[GETFISH_VY(pMotion->pSprite->nCtrlFlag)];
if (pMotion->pSprite->stPos.y + pMotion->pSprite->pFrame->stSize.height < -256)
{//return to screen
SETFISH_AY(pMotion->pSprite->nCtrlFlag, TO_DOWN);
}
}
//control fish speed < maxspeed
Play_LimitSpeed(pMotion);
}
/**
* FoemanLevel_1 - manage level1 foeman fish.
* @PlayerLevel: player's level
*/
void FoemanLevel_1(U8 PlayerLevel)
{
U8 i = 0;
U8 temp;
S16 startX;
//recruit new level1 fish
for (i = 0; i < g_nCurrentFish1; i ++)
{
if ( pFish1[i] == NULL )
{
break;
}
}
if ( i < g_nCurrentFish1 )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 64);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(128);
}
if (Sys_Random(2))
{
pFish1[i] = E_AllocMotion(&Fish_1_2_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish1[i]->pSprite->nCtrlFlag, 0);
}
else
{
pFish1[i] = E_AllocMotion(&Fish_1_3_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish1[i]->pSprite->nCtrlFlag, 1);
}
//set fish control flag
SETFISH_VX(pFish1[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV1+1));
SETFISH_VY(pFish1[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV1>>1));
SETFISH_AX(pFish1[i]->pSprite->nCtrlFlag, temp);
SETFISH_AY(pFish1[i]->pSprite->nCtrlFlag, Sys_Random(2));
SETFISH_ST(pFish1[i]->pSprite->nCtrlFlag, STATE_NORMAL);
SETFISH_LEV(pFish1[i]->pSprite->nCtrlFlag, FOEMAN_LEV1);
SETFISH_OBJID(pFish1[i]->pSprite->nCtrlFlag, 0x1F);
SETFISH_SELFID(pFish1[i]->pSprite->nCtrlFlag, (i));
return;
}
if ( g_nCurrentFish1 < aFishNum_1[PlayerLevel] )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 64);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(128);
}
if (Sys_Random(2))
{
pFish1[g_nCurrentFish1++] = E_AllocMotion(&Fish_1_2_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, 0);
}
else
{
pFish1[g_nCurrentFish1++] = E_AllocMotion(&Fish_1_3_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, 1);
}
//set fish control flag
SETFISH_VX(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV1+1));
SETFISH_VY(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV1>>1));
SETFISH_AX(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, temp);
SETFISH_AY(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, Sys_Random(2));
SETFISH_ST(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, STATE_NORMAL);
SETFISH_LEV(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, FOEMAN_LEV1);
SETFISH_OBJID(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, 0x1F);
SETFISH_SELFID(pFish1[g_nCurrentFish1-1]->pSprite->nCtrlFlag, (g_nCurrentFish1-1));
}
}
/**
* FoemanLevel_2 - manage level2 foeman fish.
* @PlayerLevel: player's level
*/
void FoemanLevel_2(U8 PlayerLevel)
{
U8 i = 0;
U8 temp;
S16 startX;
//recruit new level2 fish
for (i = 0; i < g_nCurrentFish2; i ++)
{
if ( pFish2[i] == NULL )
{
break;
}
}
if ( i < g_nCurrentFish2 )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 128);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(192);
}
if (Sys_Random(2))
{
pFish2[i] = E_AllocMotion(&Fish_2_1_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish2[i]->pSprite->nCtrlFlag, 0);
}
else
{
pFish2[i] = E_AllocMotion(&Fish_2_2_Action[0], 0, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish2[i]->pSprite->nCtrlFlag, 1);
}
//set fish control flag
SETFISH_VX(pFish2[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV2+1));
SETFISH_VY(pFish2[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV2>>1));
SETFISH_AX(pFish2[i]->pSprite->nCtrlFlag, temp);
SETFISH_AY(pFish2[i]->pSprite->nCtrlFlag, Sys_Random(2));
SETFISH_ST(pFish2[i]->pSprite->nCtrlFlag, STATE_NORMAL);
SETFISH_LEV(pFish2[i]->pSprite->nCtrlFlag, FOEMAN_LEV2);
SETFISH_OBJID(pFish2[i]->pSprite->nCtrlFlag, 0x1F);
SETFISH_SELFID(pFish2[i]->pSprite->nCtrlFlag, (i));
return;
}
if ( g_nCurrentFish2 < aFishNum_2[PlayerLevel] )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 128);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(192);
}
if (Sys_Random(2))
{
pFish2[g_nCurrentFish2++] = E_AllocMotion(&Fish_2_1_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, 0);
}
else
{
pFish2[g_nCurrentFish2++] = E_AllocMotion(&Fish_2_2_Action[0], 0, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, 1);
}
//set fish control flag
SETFISH_VX(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV2+1));
SETFISH_VY(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV2>>1));
SETFISH_AX(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, temp);
SETFISH_AY(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, Sys_Random(2));
SETFISH_ST(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, STATE_NORMAL);
SETFISH_LEV(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, FOEMAN_LEV2);
SETFISH_OBJID(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, 0x1F);
SETFISH_SELFID(pFish2[g_nCurrentFish2 - 1]->pSprite->nCtrlFlag, (g_nCurrentFish2 - 1));
}
}
/**
* FoemanLevel_3 - manage level3 foeman fish.
* @PlayerLevel: player's level
*/
void FoemanLevel_3(U8 PlayerLevel)
{
U8 i;
U8 temp;
S16 startX;
//recruit new level3 fish
for (i = 0; i < g_nCurrentFish3; i ++)
{
if ( pFish3[i] == NULL )
{
break;
}
}
if ( i < g_nCurrentFish3 )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 192);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(256);
}
if (Sys_Random(2))
{
pFish3[i] = E_AllocMotion(&Fish_3_1_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish3[i]->pSprite->nCtrlFlag, 0);
}
else
{
pFish3[i] = E_AllocMotion(&Fish_3_2_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish3[i]->pSprite->nCtrlFlag, 1);
}
//set fish control flag
SETFISH_VX(pFish3[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV3+1));
SETFISH_VY(pFish3[i]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV3>>1));
SETFISH_AX(pFish3[i]->pSprite->nCtrlFlag, temp);
SETFISH_AY(pFish3[i]->pSprite->nCtrlFlag, Sys_Random(2));
SETFISH_ST(pFish3[i]->pSprite->nCtrlFlag, STATE_NORMAL);
SETFISH_LEV(pFish3[i]->pSprite->nCtrlFlag, FOEMAN_LEV3);
SETFISH_OBJID(pFish3[i]->pSprite->nCtrlFlag, 0x1F);
SETFISH_SELFID(pFish3[i]->pSprite->nCtrlFlag, (i));
return;
}
if ( g_nCurrentFish3 < aFishNum_3[PlayerLevel] )
{//malloc fish
temp = Sys_Random(2);
if ( temp )
{//right
startX = -(Sys_Random(64) + 192);
}
else
{//left
startX = SCREEN_WIDTH + Sys_Random(256);
}
if (Sys_Random(2))
{
pFish3[g_nCurrentFish3++] = E_AllocMotion(&Fish_3_1_Action[0], temp, startX, Sys_Random(480), Sys_Random(16));
SETFISH_KIND(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, 0);
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -