GameTemplate.c
17.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
* Filename:
* ---------
* GameTemplate.c
*
* Project:
* --------
* Maui
*
* Description:
* ------------
* Game Template function.
*
* EX: Replace TEMPLATE with SNAKE
* Replace templae with snake
* Replace Tamplate with Snake
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
/*******************************************************************************
* Game Template Usage Description
*******************************************************************************
* (1) The Template contains three files.
* GameTemplate.C", GameTemplateDefs.h, GameTemplateProts.h
*
* (2) Change file names to Xxxxx.c XxxxxDefs.h, XxxxxxProts.h. Xxxxx is game name.
*
* (3) Simply replace the following string with your game name.
* TEMPLATE with XXXXXX (XXXX is the game name in caption)
* Template with Xxxxxx
* template with xxxxxx
*
* (4) Create NVRAM slot in NVRAMEnum.h to store game grade and current game level.
* Set those IDs in XXXXX_Enter_GFX( ) where to replace DUMMY_NVRAM_ID.
* The grade should be short and index should be byte.
*
* (5) Write generate resouce related code in RES_Game.c
*
* (6) Add entry point in Game.c
*
* (7) Add __MMI_GAME_XXXXXX__ in "MMI_features.h" if you wish to enable this game.
*
* (8) Remember to re-generate resource.
*******************************************************************************/
#ifndef _MMI_GX_TEMPLATE_C
#define _MMI_GX_TEMPLATE_C
#include "mmi_features.h"
#ifdef __MMI_GAME_TEMPLATE__
#include "GameInc.h"
#include "TemplateProts.h"
#include "TemplateResDef.h"
/*****************************************************************************
* Define
*****************************************************************************/
#define DUMMY_STR_ID (0)
#define DUMMY_IMG_ID (0)
#define DUMMY_NVRAM_ID (0)
/*****************************************************************************
* Typedef
*****************************************************************************/
/* game context */
typedef struct
{
BOOL is_gameover;
BOOL is_new_game;
U8 game_level;
S16 game_grade;
U16 timer_elapse;
} gx_template_context_struct;
/*****************************************************************************
* Local Variable
*****************************************************************************/
gx_template_context_struct g_gx_template_context =
{
FALSE, /* is_gameover */
TRUE, /* is_new_game */
0, /* game_level */
0, /* game_grade */
100 /* timer_elapse */
};
/*****************************************************************************
* Local Function
*****************************************************************************/
/* Game framework related functions */
S16 mmi_gx_template_calc_best_grade(S16 old_grade, S16 new_grade); /* descide which is best grade */
void mmi_gx_template_enter_game(void); /* entry function of the game */
void mmi_gx_template_exit_game(void); /* exit function - usually will stop timer and release buffer */
void mmi_gx_template_draw_gameover(void); /* draw gameover screen */
/* Game play functions */
void mmi_gx_template_framemove(void);
void mmi_gx_template_render(void);
void mmi_gx_template_gameover(void);
void mmi_gx_template_cyclic_timer(void);
void mmi_gx_template_init_game(void); /* draw gameover screen */
/*****************************************************************************
* FUNCTION
* mmi_gx_template_enter_gfx
* DESCRIPTION
* Set Game Framework (GFX) Parameter
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_enter_gfx(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* Game menu */
GFX.game_data.game_img_id = IMG_ID_GX_TEMPLATE_GAME_ICON; /* game icon img ID */
GFX.game_data.game_str_id = STR_ID_GX_TEMPLATE_GAME_NAME; /* game name string ID */
GFX.game_data.menu_resume_str_id = STR_ID_GX_TEMPLATE_RESUME; /* "Resume" string ID */
GFX.game_data.menu_new_str_id = STR_ID_GX_TEMPLATE_NEW; /* "New Game" string ID */
GFX.game_data.menu_level_str_id = STR_ID_GX_TEMPLATE_LEVEL; /* "Game Level" string ID */
GFX.game_data.menu_grade_str_id = STR_ID_GX_TEMPLATE_SCORE; /* "Best Grade" string ID */
GFX.game_data.menu_help_str_id = STR_ID_GX_TEMPLATE_HELP; /* "Game Help" string ID */
/* level / grade */
GFX.game_data.level_count = 3; /* how many levels */
GFX.game_data.level_str_id_list[0] = STR_ID_GX_TEMPLATE_LEVEL_EASY; /* level string ID */
GFX.game_data.level_str_id_list[1] = STR_ID_GX_TEMPLATE_LEVEL_NORMAL; /* level string ID */
GFX.game_data.level_str_id_list[2] = STR_ID_GX_TEMPLATE_LEVEL_HARD; /* level string ID */
/* add slot in NVRAMEnum.h */
GFX.game_data.grade_nvram_id_list[0] = DUMMY_NVRAM_ID; /* grade slot in NVRAM (short) */
GFX.game_data.grade_nvram_id_list[1] = DUMMY_NVRAM_ID; /* grade slot in NVRAM */
GFX.game_data.grade_nvram_id_list[2] = DUMMY_NVRAM_ID; /* grade slot in NVRAM */
GFX.game_data.level_nvram_id = DUMMY_NVRAM_ID; /* current lvl idnex in NVRAM (byte) */
/* help */
GFX.game_data.help_str_id = STR_ID_GX_TEMPLATE_HELP_DESCRIPTION; /* help desciption string id */
/* misc */
GFX.game_data.grade_value_ptr = (S16*) (&g_gx_template_context.game_grade); /* current level's grade (S16*) */
GFX.game_data.level_index_ptr = (U8*) (&g_gx_template_context.game_level); /* ptr to current level index (U8*) */
GFX.game_data.is_new_game = (BOOL*) (&g_gx_template_context.is_new_game); /* ptr to new game flag (BOOL*) */
/* function ptr */
GFX.game_data.best_grade_func_ptr = mmi_gx_template_calc_best_grade; /* function to calculate best grade */
GFX.game_data.enter_game_func_ptr = mmi_gx_template_enter_game; /* function to enter new game */
GFX.game_data.exit_game_func_ptr = mmi_gx_template_exit_game; /* function to exit game */
GFX.game_data.draw_gameover_func_ptr = mmi_gx_template_draw_gameover; /* function to draw gameover screen */
/* some flags */
GFX.game_data.is_keypad_audio_enable = FALSE; /* play keypad tone or not */
mmi_gfx_entry_menu_screen();
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_calc_best_grade
* DESCRIPTION
* Calculate new best grade [Callback required by GFX]
* PARAMETERS
* old_grade [IN]
* new_grade [IN]
* RETURNS
* void
*****************************************************************************/
S16 mmi_gx_template_calc_best_grade(S16 old_grade, S16 new_grade)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* compare the best grade and return it */
return 0;
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_draw_gameover
* DESCRIPTION
* Draw Gameover Screen [Callback required by GFX]
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_draw_gameover(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_enter_game
* DESCRIPTION
* Enter Game [Callback required by GFX]
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_enter_game(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_gx_template_context.is_new_game == TRUE)
{
mmi_gx_template_init_game(); /* is new game, otherwise resume game */
}
g_gx_template_context.is_new_game = FALSE;
g_gx_template_context.is_gameover = FALSE;
/* start game loop */
mmi_gx_template_cyclic_timer();
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_exit_game
* DESCRIPTION
* Exit Game [Callback required by GFX]
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_exit_game(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
gui_cancel_timer(mmi_gx_template_cyclic_timer); /* cancle the looping timer */
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_init_game
* DESCRIPTION
* Game initilization
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_init_game(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* init game here */
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_framemove
* DESCRIPTION
* Framemove - process the game logic
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_framemove(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* add logic code here */
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_render
* DESCRIPTION
* Render the game images
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_render(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* add drawing code here */
gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_gameover
* DESCRIPTION
* Gameover function
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_gameover(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
g_gx_template_context.is_gameover = TRUE;
g_gx_template_context.is_new_game = TRUE;
/* call this function to draw gameover screen */
mmi_gfx_entry_gameover_screen();
}
/*****************************************************************************
* FUNCTION
* mmi_gx_template_cyclic_timer
* DESCRIPTION
* Timer trigger function - looping
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void mmi_gx_template_cyclic_timer(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
gui_start_timer(g_gx_template_context.timer_elapse, mmi_gx_template_cyclic_timer);
if (g_gx_template_context.is_gameover == FALSE)
{
mmi_gx_template_framemove();
mmi_gx_template_render();
}
}
#endif /* __MMI_GAME_TEMPLATE__ */
#endif /* _MMI_GX_TEMPLATE_C */