MTK游戏开发结构(转)

  IT /malonely 
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[i], g_Pushbox.BoxPos.X, g_Pushbox.BoxPos.Y);

{
  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[i] = MTK_DATA[Config_Passs - 1][i];
  if( ( g_Pushbox.tempbox[i] == 3 ) || ( g_Pushbox.tempbox[i] == 5 ) || ( g_Pushbox.tempbox[i] == 6 ) )
  {
   g_Pushbox.goalnum++;
  }
  if( ( g_Pushbox.tempbox[i] == 4 ) || ( g_Pushbox.tempbox[i] == 6 ) )
  {
   g_Pushbox.Boxer = i;
  }
  
  if( g_Pushbox.tempbox[i] == 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;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值