📄 game.c
字号:
/*===========================================================================
FILE: game.c
===========================================================================*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*
可扩展性:1,可以添加小鱼一共有几条命。 (已实现)
2,增加关数,可以提高被吃小鱼的速度 大鱼的速度和大鱼的出现频率
3,可以添加特殊食物 吃掉后小鱼有特殊技能效果。例如在30秒之内速度变快2倍,或者直接变大
4,吃到一定分数加一条命
5,过到一定关数可以变换玩家控制的小鱼
6,当小鱼长成大鱼时出现炸弹
7,增加大鱼吃小鱼的动作 (已实现)
8,增加可控小鱼吃鱼的动作 (已实现)
9,当可控小鱼长大时,增加可控小鱼吃鱼的动作 (已实现)
*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*-----------------------------东软嵌入式加强2班,第三小组------------------------------*/
/*--------------组长:王建翔 组员:金毅,崔任东,李常宾,吴鹏--------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEESprite.h"
#include "game.bid"
#include "AEEMenu.h"
#include "AEEDisp.h"
#include "AEEStdlib.h" //助手函数
#include "AEEGraphics.h"
#include "gamee.brh"
#include "AEESoundPlayer.h"
#include "sorse.brh"
AEETileMap m_Maps[2];
AEESpriteCmd m_Sprite[2];
static const uint16 map[]=
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,5,1,1,1,1,1,1,1,1,1,1,5,1,1,
6,2,2,2,11,2,2,2,10,2,2,2,2,2,2,10,
7,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
8,4,4,4,4,9,4,4,4,4,9,4,4,4,4,4
};
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _game {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
IDisplay *pIDisplay; // give a standard way to access the Display interface
IShell *pIShell; // give a standard way to access the Shell interface
ISprite *pISprite;
AEECallback cbtime;
int score; //记录玩家分数
int EachLevelScore; //记录每一关的分数,已控制小鱼是否长大
char show_score[50];
// int * pshow_score; //指向show_score的指针
AEETileMap m_Maps[2]; //地图
AEESpriteCmd m_Sprite[10]; //精灵
IImage *pIImage;
//IGraphics *pGra;
ISoundPlayer *pISoundPlayer;
AEESoundPlayerInfo info;
IMenuCtl *pIMenuCtl;
int fishtime;
int fish1_x,fish1_y,fish2_x,fish2_y,fish3_x,fish3_y,bigfish_x,bigfish_y;//非玩家控制精灵的坐标
int flag;
int derection; //方向按键的标志位
int level; //游戏关数
int life; //设置小鱼有几条命
int IsNewLife; //标志位 设置小鱼是否是被吃掉后 产生的新命
int BigFishWalkDistance;//设置大鱼运行轨迹长度,其大小决定大鱼出现的频率
// int EachLevelScore; //每关开始后小鱼都处于刚出生状态,当EachLevelScore大于50时小鱼长大
// add your own variables here...
} game;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean game_HandleEvent(game* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean game_InitAppData(game* pMe);
void game_FreeAppData(game* pMe);
void ExSprite_loadResource(game * pMe); //函数声明,载入资源
void ExSprite_Init(game * pMe); //初始化
void ballup(game *pMe); //回调函数 计时器
void menu(game * pMe); //软菜单
void file(game *pMe); //文本
void BigFishTraval(game *pMe); //大鱼游动轨迹
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;
if( ClsId == AEECLSID_GAME )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(game),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)game_HandleEvent,
(PFNFREEAPPDATA)game_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
{
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(game_InitAppData((game*)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean game_HandleEvent(game* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
AEEImageInfo imageInfo;
/*AEERect rect;
rect.x = 0;
rect.y = 0;
rect.dx = pMe->DeviceInfo.cxScreen;
rect.dy = pMe->DeviceInfo.cyScreen;*/
// App is told it is starting up
case EVT_APP_START:
{
// Add your code here...
pMe->level=0;
pMe->IsNewLife=0;
pMe->pIImage=ISHELL_LoadImage(pMe->pIShell,"jiemian1.bmp");
IIMAGE_GetInfo(pMe->pIImage,&imageInfo);
IIMAGE_Draw(pMe->pIImage,0,0);
menu(pMe);
IDISPLAY_Update(pMe->pIDisplay);
IIMAGE_Release(pMe->pIImage);
return(TRUE);
}
case EVT_COMMAND:
/*if(pMe->pISoundPlayer!=NULL)
{
ISOUNDPLAYER_Stop(pMe->pISoundPlayer);
ISOUNDPLAYER_Release(pMe->pISoundPlayer);
pMe->pISoundPlayer = NULL;
}*/
if(pMe->pIMenuCtl)
{
IMENUCTL_SetActive(pMe->pIMenuCtl,FALSE);
}
switch(wParam)
{
case IDS_STRING_1001: //新游戏
{
pMe->score=0;
pMe->life=3;
ISHELL_CreateInstance(pMe->pIShell,AEECLSID_SOUNDPLAYER,(void**)&pMe->pISoundPlayer); //
pMe->info.eInput=SDT_FILE;
pMe->info.pData="sea.mp3";
ISOUNDPLAYER_SetInfo(pMe->pISoundPlayer,&pMe->info);
ISOUNDPLAYER_Play(pMe->pISoundPlayer);
ISHELL_CreateInstance(pMe->pIShell,AEECLSID_SPRITE,(void**)&pMe->pISprite);
ExSprite_loadResource(pMe);
ExSprite_Init(pMe);
CALLBACK_Init(&pMe->cbtime,ballup,pMe); //通知上下文
ISHELL_SetTimerEx(pMe->pIShell,100,&pMe->cbtime);
//DBGPRINTF("fdgdfgdf");
}
//计时器;
case IDS_STRING_1002:
{
IDISPLAY_ClearScreen(pMe->pIDisplay);
pMe->pIImage=ISHELL_LoadImage(pMe->pIShell,"beijing2.bmp");
IIMAGE_GetInfo(pMe->pIImage,&imageInfo);
IIMAGE_Draw(pMe->pIImage,0,0);
IDISPLAY_Update(pMe->pIDisplay);
IIMAGE_Release(pMe->pIImage);
file(pMe);
return(TRUE);
}
case IDS_STRING_1003:
{
if ( pMe->pIMenuCtl != NULL ) // check for NULL first
{
IMENUCTL_Release(pMe->pIMenuCtl); // release the interface
pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
}
if ( pMe->pIImage != NULL ) // check for NULL first
{
IIMAGE_Release(pMe->pIImage); // release the interface
pMe->pIImage = NULL; // set to NULL so no problems trying to free later
}
if ( pMe->pISprite != NULL ) // check for NULL first
{
ISPRITE_Release(pMe->pISprite); // release the interface
pMe->pISprite = NULL; // set to NULL so no problems trying to free later
}
if ( pMe->pISoundPlayer != NULL ) // check for NULL first
{
ISOUNDPLAYER_Release(pMe->pISoundPlayer); // release the interface
pMe->pISoundPlayer = NULL; // set to NULL so no problems trying to free later
}
if ( pMe->pIMenuCtl != NULL ) // check for NULL first
{
IMENUCTL_Release(pMe->pIMenuCtl); // release the interface
pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
}
if ( pMe->pIMenuCtl != NULL ) // check for NULL first
{
IMENUCTL_Release(pMe->pIMenuCtl); // release the interface
pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
}
ISHELL_CloseApplet(pMe->a.m_pIShell,FALSE);
return(TRUE);
}
break;
}
break;
// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...
return(TRUE);
// App is being suspended
case EVT_APP_SUSPEND:
// Add your code here...
return(TRUE);
// App is being resumed
case EVT_APP_RESUME:
if(pMe->pIMenuCtl)
{
IMENUCTL_SetActive(pMe->pIMenuCtl,TRUE);
}
return(TRUE);
// An SMS message has arrived for this app. Message is in the dwParam above as (char *)
// sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
// Add your code here...
return(TRUE);
// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
case EVT_KEY:
if(pMe->pIMenuCtl)
{
if(IMENUCTL_HandleEvent(pMe->pIMenuCtl,eCode,wParam,dwParam))
{
return TRUE;
}
}
{
if(wParam==AVK_UP && pMe->m_Sprite[0].y>13)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -