找回密码
 注册
搜索
查看: 898|回复: 1

[讨论] MTK游戏开发结构

[复制链接]
发表于 2006-11-26 16:25:13 | 显示全部楼层 |阅读模式
MTK上开发的游戏源代码---推箱子。
MTK平台调试通过。我去掉了数据部分和内核。,留下了框架供大家学习MTK平台开发。
--------------
#include "GlobalDefs.h"
#include "HistoryGprot.h"
#include "GlobalConstants.h"
#include "MMI_features.h"
#include "PixtelDataTypes.h"
#include "Unicodexdcl.h"
#include "gui.h"
#include "Calculator.h"
#include "SettingProfile.h"
#include "ProfileGprots.h"
#include "Globaldefs.h"
#include "CustDataRes.h"
#include "gui_themes.h"
#include "wgui_categories.h"
#include "wgui_softkeys.h"
#include "HistoryGprot.h"
#include "OrganizerDef.h"
#include "GameDefs.h"
#define MTK_GUANSHU 40
#define PUSH_LCD_WIDTH  176
#define PUSH_LCD_HEIGHT 220
static const char MTK_DATA[MTK_GUANSHU][80] = { {1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,1,3,0,1,1,1,
  1,3,0,0,2,0,0,1,1,1,
  1,1,2,1,1,0,0,1,1,1,
  1,0,0,1,1,2,1,1,1,1,
  1,0,0,4,0,0,0,1,1,1,
  1,0,3,1,0,0,0,1,1,1,
  1,1,1,1,1,1,1,1,1,1}};

typedef struct{
    INT16 X;
    INT16 Y;
     }MTK_POS;

typedef struct{
     UINT8 Data1;
     UINT8 Data2;
     }  MTK_sg_PUSHBOXSTRUCT;

static MTK_sg_PUSHBOXSTRUCT g_Pushbox;
static char Config_Passs=1;
enum{
   PushSharp_Blank
, PushSharp_Bar
, PushSharp_Box  
, PushSharp_Goal
, PushSharp_Boxer
, PushSharp_Ok
}e_PushSharp;
void Game_Push_Null(void)
{
return;
}
/*Name:Calculate
  Desc: Calculate the current position of the block
  Return: no return value
  Author: helloworld
*/
static void Game_Push_Calculate( UINT8 val )
{
UINT8 row;
UINT8 col;
//kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Calculate,val=%d ]\n", val);

row = val/10;
col = val - row * 10;

kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Calculate,row=%d, col=%d  ]\n",row,col);
g_Pushbox.BoxPos.X = 15 * col + 14;
g_Pushbox.BoxPos.Y = 15 * row + 24;
}

static void UIFDrawBitmap(S32 offset_x, S32 offset_y, U16 image_id)
{
//kal_prompt_trace(MOD_MMI, "\n[Push-->UIFDrawBitmap, image_id=%d]\n", image_id);
pixtel_UI_lock_double_buffer();
//pixtel_UI_reset_clip();

pixtel_UI_show_image(offset_x,(offset_y +20),(UI_image_type)GetImage(image_id));
pixtel_UI_unlock_double_buffer();
pixtel_UI_BLT_double_buffer(0,0,PUSH_LCD_WIDTH,PUSH_LCD_HEIGHT);  
}
static short Game_Push_Itou(short *pOutStr,long InNum)
{
// 0: ox0030
char NumString[10];
short i,j;
short NumLen;// 位数

memset(NumString,'\0',10);
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Itoa, InNum=%d]\n", InNum);

if(NULL==pOutStr)
{
  return;
}
if(InNum/1000000 >0)
{// to long
  return;
}
if(InNum/100000 >0)
{
  NumLen=6;
}
else if(InNum/10000 >0)
{
  NumLen=5;
}
else if(InNum/1000 >0)
{
  NumLen=4;
}
else if(InNum/100 >0)
{
  NumLen=3;
}
else if(InNum/10 >0)
{
  NumLen=2;
}
else
{
  NumLen=1;
}
for(i=NumLen;i>0;i--)
{
  if(1==i)
  {
   NumString[0]= InNum%10 +'0';
  }
  else if(2==i)
  {
   NumString[i-1]= (InNum/10)%10 +'0';
  }
  else if(3==i)
  {
   NumString[i-1]= (InNum/100)%10 +'0';
  }
  else if(4==i)
  {
   NumString[i-1]= (InNum/1000)%10 +'0';
  }
  else if(5==i)
  {
   NumString[i-1]= (InNum/10000)%10 +'0';
  }  
  pOutStr[NumLen-i]= NumString[i-1];
  kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Itoa, =%d]\n", pOutStr[NumLen-i]);  
}

kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Itoa, len=%d]\n",NumLen);
return j;
}
const color PushTextColor   = {0,0,100,100};
static void Game_Push_DrawString(void)
{
#define REC_POS_X 1
#define REC_POS_Y 170
#define REC_POS_W 176
#define REC_POS_H 50

S32 w;
short Psss_uncode[10], Step_uncode[10];
memset(Psss_uncode,'\0',10);
memset(Step_uncode,'\0',10);
Game_Push_Itou(Psss_uncode, (long)Config_Passs);
Game_Push_Itou(Step_uncode, (long)g_Pushbox.step);
pixtel_UI_lock_double_buffer();
pixtel_UI_set_font(&MMI_medium_font);
pixtel_UI_set_text_color(PushTextColor);
pixtel_UI_reset_clip();
pixtel_UI_reset_text_clip();
pixtel_UI_move_text_cursor( 63, 185  );
pixtel_UI_print_text((UI_string_type)Psss_uncode);
UIFDrawBitmap( 145, (185 -20) ,IMG_ID_PUSH_BOX_SMALL_BKG);
UIFDrawBitmap( 155, (185 -20) ,IMG_ID_PUSH_BOX_SMALL_BKG);

pixtel_UI_move_text_cursor( 145, 185  );
pixtel_UI_print_text((UI_string_type)Step_uncode);
pixtel_UI_unlock_double_buffer();
pixtel_UI_BLT_double_buffer(REC_POS_X,     REC_POS_Y,     REC_POS_X + REC_POS_W,    REC_POS_Y + REC_POS_H);
return;
}
// service for FirstDraw and commonDraw
static void Game_Push_Draw(INT8 i )
{
Game_Push_Calculate( i );
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_Draw, drawID=%d, posX=%d, posY=%d]\n", g_Pushbox.tempbox, g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y);

switch( g_Pushbox.tempbox )
{
  case 0: //为空时根本就不用画. 让他显示背景,(不行! 还是要画)
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_BLANK);
   break;
  case 1:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_BAR);
   break;
  case 2:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_BOX);
   break;
  case 3:/*这是个傻办法, 以保证用24.. 但又不露出背景...   挖空背景后, 仍要用, 因为推走box后,要立即将其覆盖掉 */
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y,IMG_ID_PUSH_BOX_GOAL);
   break;
  case 4:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_BOXER);
   break;
  case 5:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y,IMG_ID_PUSH_BOX_OK);
   break;
  case 6:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_BOXER );
   break;
  case 7:
   UIFDrawBitmap( g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y, IMG_ID_PUSH_BOX_SMALL_BKG );
   break;
  default:
   break;
}
}

static void Game_Push_FirstDraw(void)
{
short i;
pixtel_UI_lock_double_buffer();
pixtel_UI_reset_clip();
clear_screen();

UIFDrawBitmap( 0, 0,IMG_ID_PUSH_BOX_BKG); //大背景
for( i = 0; i < 80; i++ )
{
  Game_Push_Draw( i );
}
Game_Push_DrawString();
pixtel_UI_unlock_double_buffer();
pixtel_UI_BLT_double_buffer(0,0,PUSH_LCD_WIDTH,PUSH_LCD_HEIGHT);
}
static void Game_Push_ComonDraw(void)
{
Game_Push_Draw( g_Pushbox.BeforeBoxer );
Game_Push_Draw( g_Pushbox.Boxer );
Game_Push_Draw( g_Pushbox.AfterBoxer );
}
static void Game_Push_Ini(void)
{//开局
short i;
g_Pushbox.over = FALSE;
g_Pushbox.goalnum = 0;
g_Pushbox.I = 0;
g_Pushbox.step = 0;
  
for( i = 0; i < 80; i++ )
{
  g_Pushbox.tempbox = MTK_DATA[Config_Passs - 1];
  if( ( g_Pushbox.tempbox == 3 ) || ( g_Pushbox.tempbox == 5 ) || ( g_Pushbox.tempbox == 6 ) )
  {
   g_Pushbox.goalnum++;
  }
  if( ( g_Pushbox.tempbox == 4 ) || ( g_Pushbox.tempbox == 6 ) )
  {
   g_Pushbox.Boxer = i;
  }
  
  if( g_Pushbox.tempbox == 5 )
  {
   g_Pushbox.I++;
  }
}
}
static void Game_Push_DeIni(void)
{
return;
}
//新开局
static void Game_Push_BeginNewStep(void)
{
Game_Push_Ini();
Game_Push_FirstDraw();
return;
}
void Game_Push_Begin(void);
static void Game_Push_ConfirmNewGame(void)
{
//GoBackHistory();
Game_Push_Begin();
return;
}
static void Game_Push_ConfirmExitGame(void)
{
Game_Push_DeIni();
GoBacknHistory(2);
//GoBackHistory();
return;
}
static char Game_Push_GameOverProc(void)
{
if( FALSE == g_Pushbox.over )
{
  return g_Pushbox.over;
}

Config_Passs++;
if( Config_Passs > MTK_GUANSHU )
{
  Config_Passs = 1;
}
DisplayConfirm( STR_GLOBAL_YES, IMG_GLOBAL_YES,
        STR_GLOBAL_NO, IMG_GLOBAL_NO,
        get_string(STR_GAME_RESUME),IMG_GLOBAL_QUESTION, WARNING_TONE);
SetRightSoftkeyFunction(Game_Push_ConfirmExitGame,KEY_EVENT_UP);
  SetLeftSoftkeyFunction(Game_Push_ConfirmNewGame,KEY_EVENT_UP);
  return g_Pushbox.over;
}
/*Name:MoveStep
  Desc: Move the  block
  Return: no return value
  Author: helloworld
*/
static void Game_Push_MoveStep( void)
{
//core
}

static void Game_Push_UpKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_UpKeyProc]\n");

g_Pushbox.flag = 0 - 10;
Game_Push_MoveStep();
return;
}
static void Game_Push_DownKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_DownKeyProc]\n");
g_Pushbox.flag = 10;
Game_Push_MoveStep();
return;
}
static void Game_Push_LeftKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_LeftKeyProc]\n");
g_Pushbox.flag = -1;
Game_Push_MoveStep();
return;
}
static void Game_Push_RightKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_RightKeyProc]\n");
g_Pushbox.flag = 1;
Game_Push_MoveStep();
return;
}
static void Game_Push_HashKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_HashKeyProc]\n");
Config_Passs--;
if( Config_Passs < 1 )
{
  Config_Passs = MTK_GUANSHU;
}
Game_Push_BeginNewStep();
return;
}

static void Game_Push_StarKeyProc(void)
{
kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_StarKeyProc]\n");
Config_Passs++;
if( Config_Passs > MTK_GUANSHU )
{
  Config_Passs = 1;
}
Game_Push_BeginNewStep();
return;
}
static void Game_Push_SendKeyProc(void)
{
Game_Push_BeginNewStep();
return;
}
static void Game_Push_EndKeyProc(void)
{
Game_Push_DeIni();
GoBackHistory();
return;
}

static void Game_Push_SetKeysHandle(void)
{
//kal_prompt_trace(MOD_MMI, "\n[Push-->Game_Push_SetKeysHandle]\n");
ClearAllKeyHandler();
SetKeyHandler(Game_Push_UpKeyProc,   KEY_UP_ARROW,   KEY_EVENT_DOWN);
SetKeyHandler(Game_Push_DownKeyProc, KEY_DOWN_ARROW, KEY_EVENT_DOWN);

SetKeyHandler(Game_Push_LeftKeyProc,  KEY_LEFT_ARROW,  KEY_EVENT_DOWN);
SetKeyHandler(Game_Push_RightKeyProc, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
// * #
SetKeyHandler(Game_Push_StarKeyProc, KEY_STAR,  KEY_EVENT_DOWN);
SetKeyHandler(Game_Push_HashKeyProc, KEY_POUND, KEY_EVENT_DOWN);
// send, end
SetKeyHandler(Game_Push_SendKeyProc, KEY_SEND, KEY_EVENT_DOWN);
SetKeyHandler(Game_Push_EndKeyProc,  KEY_END,  KEY_EVENT_DOWN);
// back
SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
}
static void Game_Push_Entry(void)
{
EntryNewScreen(SCR_ID_CALC_APP, NULL, Game_Push_Entry, NULL);
Game_Push_FirstDraw();
RedrawCategoryFunction=Game_Push_FirstDraw;
}

// for menu
void Game_Push_Begin(void)
{
Game_Push_Ini();
Game_Push_Entry();
Game_Push_SetKeysHandle();
return;
}
发表于 2006-11-28 22:27:38 | 显示全部楼层
大概看了楼上的代码,其中有两点比较困惑的。
一是你的代码没有一个工程化的思想,有些定义的数据结构就应该包在一个头文件中,比如专门用于游戏的。建议你去看看林锐的《搞质量C/C++编程》,你的代码很乱,MTK的MMI代码本来写的就不是很好,像你这样写代码的话,更加重了别人看你代码的负担。
二是你的代码好像没有用GameFramwork的API,在MTK上Game的MMI是和GameFramwork紧密配合的,比如说从菜单进入游戏,还有游戏的记分,游戏的排名,游戏推出的函数,这些都是GameFramwork提供的。
其实我觉得在手机里加游戏不是很难,只要游戏的核心代码写好以后,很容易就移植到MTK平台上,但是手机软件作为一个比较复杂的工程,大家尽量把自己的代码包的很干净。
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-11-23 15:11 , Processed in 0.045406 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表