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

📄 play_managefish.c

📁 凌阳32位单片机开发的小游戏
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
 *
 *     The information contained herein is the exclusive property of
 *   Sunplus Technology Co. And shall not be distributed, reproduced,
 *   or disclosed in whole in part without prior written permission.
 *
 *         (C) COPYRIGHT 2005   SUNPLUS TECHNOLOGY CO.
 *                        ALL RIGHTS RESERVED
 *
 * The entire notice above must be reproduced on all authorized copies.
 *
 *****************************************************************************/

/******************************************************************************
 *  Filename:   	Play_ManageFish.c
 *  Author:     	Robin.xjliu  (eMail: xjliu@sunplus.com)
 *  Tel:        	00885-028-87848688-5884
 *  Date:       	2005-12-03
 *  Description:	fish management function
 *  Reference:
 *  Version history:
 *-----------------------------------------------------------------------------
 *	Version   YYYY-MM-DD-INDEX   Modified By         Description
 *	1.0.0     2005-12-03           xjliu               Create
 *
 *****************************************************************************/
#include "Include/Play_ManageFish.h"
#include "../EngineLib/Include/E_Collision.h"
#include "../GameData/MotionData.h"
#include "Include/GamePlay.h"

extern U32 game_time;
extern S16	iTextCount_Y[];

U8	g_nCurrentFish0;
U8	g_nCurrentFish1;
U8	g_nCurrentFish2;
U8	g_nCurrentFish3;
U32	g_nManageFishTimer;
U32 g_nSharkTimer;
S16	g_iSharkStartX;
S16	g_iSharkStartY;
MOTION *pFish0[NUM_FISH0];
MOTION *pFish1[NUM_FISH1];
MOTION *pFish2[NUM_FISH2];
MOTION *pFish3[NUM_FISH3];
MOTION *pFish4;
MOTION *pNormal[NORMAL_NUM];


const U8 FishStep[32] = {
	0,
	1,1,1,2,2,
	2,3,3,4,4,
	5,5,6,6,7,
	8,9,10,11,12,
	13,14,15,16,17,
	18,19,20,21,22,
	23
};

const U8 aFishNum_1[3] = {20, 25, 20};	//the fish number of every Actor Level
const U8 aFishNum_2[3] = {5, 7, 5};
const U8 aFishNum_3[3] = {3, 5, 3};
const U8 aFishNum_4[3] = {35, 35, 20};	//note shark appear interval time

/**
 * Play_InitFish - .
 */
void Play_InitFish(void)
{
	U8 temp;
	U8 i;

	//Init some decorative thing
	pNormal[POPO1] = E_AllocMotion(&PoPo1_Action[0], 0, -80, 336, SP_PRIO_0);
	pNormal[POPO1]->pSprite->nCtrlFlag = 112;
	pNormal[POPO1]->pSprite->nCtrlFlag |= (496 << 16);

	pNormal[POPO3] = E_AllocMotion(&PoPo3_Action[0], 0, 195, 363, SP_PRIO_0);
	pNormal[POPO3]->pSprite->nCtrlFlag = 387;
	pNormal[POPO3]->pSprite->nCtrlFlag |= (523 << 16);
	
	pNormal[POPO4] = E_AllocMotion(&PoPo4_Action[0], 0, 456, 352, SP_PRIO_0);
	pNormal[POPO4]->pSprite->nCtrlFlag = 648;
	pNormal[POPO4]->pSprite->nCtrlFlag |= (512 << 16);
	
	pNormal[OCTOPUS] = E_AllocMotion(&Octopus_Action[0], 0, 771-192, 672-160, SP_PRIO_0);//694-192, 673-160,
	pNormal[COWRY] = E_AllocMotion(&Cowry_Action[0], 0, 192-192, 653-160, SP_PRIO_0);
	pNormal[COUNTBONE] = E_AllocMotion(&CountBone_Action[0], 0, 50, 50, SP_PRIO_15);
	pNormal[COUNTTROUGH] = E_AllocMotion(&CountTrough_Action[0], 0, 50+37, 50+15, SP_PRIO_15);

	//Init some variable
	g_nCurrentFish0 = 0;
	g_nCurrentFish1 = 0;
	g_nCurrentFish2 = 0;
	g_nCurrentFish3 = 0;
	g_nManageFishTimer = 0x00000000;
	g_nSharkTimer = 0;
	g_iSharkStartX = 0;
	g_iSharkStartY = 0;
	
	//Init some fish before game start
	//1.recruit new level1 fish
	for (i = 0; i < 8; i ++)
	{//malloc level1 fish
		temp = Sys_Random(2);
		if (Sys_Random(2))
		{
			pFish1[g_nCurrentFish1++] = E_AllocMotion(&Fish_1_2_Action[0], temp, Sys_Random(640), 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, Sys_Random(640), 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));
	}
	
	//2.recruit new level2 fish	
	for (i = 0; i < 2; i ++)
	{//malloc level2 fish
		temp = Sys_Random(2);
		if (Sys_Random(2))
		{
			pFish2[g_nCurrentFish2++] = E_AllocMotion(&Fish_2_1_Action[0], temp, Sys_Random(640), 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, Sys_Random(640), 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));
	}

	//3.recruit new level3 fish
/*	for (i = 0; i < 1; i ++)
	{//malloc level3 fish
		temp = Sys_Random(2);
		if (Sys_Random(2))
		{
			pFish3[g_nCurrentFish3++] = E_AllocMotion(&Fish_3_1_Action[0], temp, Sys_Random(640), Sys_Random(480), Sys_Random(16));
		}
		else
		{
			pFish3[g_nCurrentFish3++] = E_AllocMotion(&Fish_3_2_Action[0], temp, Sys_Random(640), Sys_Random(480), Sys_Random(16));
		}
		//set fish control flag
		SETFISH_VX(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV3+1));
		SETFISH_VY(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, Sys_Random(MAXSPEED_LEV3>>1));
		SETFISH_AX(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, temp);
		SETFISH_AY(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, Sys_Random(2));
		SETFISH_ST(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, STATE_NORMAL);
		SETFISH_LEV(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, FOEMAN_LEV3);
		SETFISH_OBJID(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, 0x1F);
		SETFISH_SELFID(pFish3[g_nCurrentFish3 - 1]->pSprite->nCtrlFlag, (g_nCurrentFish3 - 1));
	}*/

	//malloc shark(level4 fish)
	pFish4 = E_AllocMotion(&Fish_4_1_Action[0], SHARK_HIDE, 0, 100, SP_PRIO_15);
}

/**
 *
 */
void _StateProc_ChangeWay(MOTION *pMotion)
{
	U8 temp;

	if (pMotion->nMtnInfo.B.MTN_ActionID > 1)
	{
		SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
		return;
	}

	temp = Sys_Random(10);
	if ( temp < 2)
	{//change Ay	20%
		ChangeBit(11, pMotion->pSprite->nCtrlFlag);
	}
	else
	{
		//some fish will not change Way
		if ( GETFISH_SELFID(pMotion->pSprite->nCtrlFlag) % 2 )
		{
			//change state to normal
			SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
			return;
		}
		
		if (temp > 6)
		{//change Ax and Ay		30%
			ChangeBit(10, pMotion->pSprite->nCtrlFlag);
			//E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));
			ChangeBit(11, pMotion->pSprite->nCtrlFlag);
		}
		else
		{//change Ax	50%
			ChangeBit(10, pMotion->pSprite->nCtrlFlag);
			//E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));	
		}
		E_ChangeAction(pMotion, pMotion->nMtnInfo.B.MTN_ActionID+2);
	}
	//change state to normal
	SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);	
}

void _StateProc_AddSpeed(MOTION *pMotion)
{
	if ( GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) < 4 )
	{//keep add speed state
		//keep counter ++
		SETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag, (GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) + 1));
		//add speed index
		switch( Sys_Random(3) )
		{
		case 1:
			//add Vx
			SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) + 1));
			break;
		case 0:
			//add Vy
			if ( Sys_Random(10) < 4 )
			{
				SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) + 1));
			}
			break;
		case 2:
			//add Vx and Vy
			SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) + 1));
			SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) + 1));
			break;
		}			
	}
	else
	{//add speed end
		//change state to normal
		SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
	}
}

void _StateProc_SubSpeed(MOTION *pMotion)
{
	if ( GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) < 4 )
	{//keep sub speed state
		//keep counter ++
		SETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag, (GETFISH_KEEPCNT(pMotion->pSprite->nCtrlFlag) + 1));
		//sub speed index
		switch( Sys_Random(3) )
		{
		case 1:
			//sub Vx
			if (GETFISH_VX(pMotion->pSprite->nCtrlFlag) > 2)
			{
				SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) - 1));
			}
			break;
		case 0:
			//sub Vy
			if (GETFISH_VY(pMotion->pSprite->nCtrlFlag) > 2 )
			{
				SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) - 1));
			}
			break;
		case 2:
			//sub Vx and Vy
			if (GETFISH_VX(pMotion->pSprite->nCtrlFlag) > 2)
			{
				SETFISH_VX(pMotion->pSprite->nCtrlFlag, (GETFISH_VX(pMotion->pSprite->nCtrlFlag) - 1));
			}
			if (GETFISH_VY(pMotion->pSprite->nCtrlFlag) > 2)
			{
				SETFISH_VY(pMotion->pSprite->nCtrlFlag, (GETFISH_VY(pMotion->pSprite->nCtrlFlag) - 1));
			}	
			break;
		}		
	}
	else
	{//sub speed end
		//change state to normal
		SETFISH_ST(pMotion->pSprite->nCtrlFlag, STATE_NORMAL);
	}
}

void _SpFollowScreen(MOTION *pMotion)
{
	if ( g_nPlayerAx )
	{
		pMotion->pSprite->stPos.x -= g_nScreenStep_X;
	}
	else
	{
		pMotion->pSprite->stPos.x += g_nScreenStep_X;
	}
	if ( g_nPlayerAy )
	{
		pMotion->pSprite->stPos.y -= g_nScreenStep_Y;
	}
	else
	{
		pMotion->pSprite->stPos.y += g_nScreenStep_Y;
	}
}

/*
void _Chase(MOTION *pMotion)
{
	U8	nObjFishID;
	S16	iObjPointX, iObjPointY;

	nObjFishID = GETFISH_OBJID(pMotion->pSprite->nCtrlFlag);

	switch( GETFISH_LEV(pMotion->pSprite->nCtrlFlag) )
	{
	case FOEMAN_LEV1:
		//get object point to chase
		if ( GETFISH_AX(pFish1[nObjFishID]->pSprite->nCtrlFlag) )
		{//object fish move to right
			iObjPointX = pFish1[nObjFishID]->pSprite->stPos.x;
		}
		else
		{//object fish move to left
			iObjPointX = pFish1[nObjFishID]->pSprite->stPos.x + pFish1[nObjFishID]->pSprite->pFrame->stSize.width;	
		}
		iObjPointY = pFish1[nObjFishID]->pSprite->stPos.y + pFish1[nObjFishID]->pSprite->pFrame->stSize.height;

		//change Ax
		if ( GETFISH_AX(pMotion->pSprite->nCtrlFlag) )
		{//right
			if ( pMotion->pSprite->stPos.x + pMotion->pSprite->pFrame->stSize.width > iObjPointX )
			{
				ChangeBit(10, pMotion->pSprite->nCtrlFlag);
				E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));					
			}
		}
		else
		{//left
			if ( pMotion->pSprite->stPos.x < iObjPointX )
			{
				ChangeBit(10, pMotion->pSprite->nCtrlFlag);
				E_ChangeAction(pMotion, GETFISH_AX(pMotion->pSprite->nCtrlFlag));					
			}
		}
		
		//change Ay
		if ( pMotion->pSprite->stPos.y + 
			(pMotion->pSprite->pFrame->stSize.height >> 1) > iObjPointY)
		{
			SETFISH_AY(pMotion->pSprite->nCtrlFlag, TO_UP);
		}
		else
		{
			SETFISH_AY(pMotion->pSprite->nCtrlFlag, TO_DOWN);
		}
		
		//add speed for chasing
		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:
		break;
	case FOEMAN_LEV3:
		break;
	}
}

void _StateProc_Chase(MOTION *pMotion)
{
	//U16 temp;
	U8	i;
	
	if ( GETFISH_OBJID(pMotion->pSprite->nCtrlFlag) == 0x1F 
		&& GETFISH_SELFID(pMotion->pSprite->nCtrlFlag) < 0x1F )
	{//no object fish, so search an object fish. available to level1 ~ level 3 foeman
		switch( GETFISH_LEV(pMotion->pSprite->nCtrlFlag) )
		{
		case FOEMAN_LEV1:
			for (i = 0; i < g_nCurrentFish1; i ++)
			{//FOEMAN_LEV1
				if ( E_PreDetect(pMotion, pFish1[i], (pMotion->pSprite->pFrame->stSize.width) ) 
					&& i < 0x1F
					&& GETFISH_OBJID(pFish1[i]->pSprite->nCtrlFlag) == 0x1F )
				{
					SETFISH_OBJID(pMotion->pSprite->nCtrlFlag, i);//get object fish index
					SETFISH_OBJID(pFish1[i]->pSprite->nCtrlFlag, 
						(GETFISH_SELFID(pMotion->pSprite->nCtrlFlag)));//set self index to object fish

		SETFISH_ST(pFish1[i]->pSprite->nCtrlFlag, STATE_DODGE );
		SETFISH_KEEPCNT(pFish1[i]->pSprite->nCtrlFlag, 0);
					break;
				}				
			}
			break;

⌨️ 快捷键说明

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