📄 games_fallball.c
字号:
#ifdef __cplusplus
extern "C" {
#endif
/*==================================================================================================
MODULE NAME : GAMES_Fallball.c
GENERAL DESCRIPTION
Input Short Message content.
SEF Confidential Proprietary
(c) Copyright 2002 by TECHFAITH Corp. All Rights Reserved.
====================================================================================================
Revision History
Modification Tracking
Date Author Number Description of changes
---------- -------------- --------- -----------------------------------------------------------------------------------
04/06/2004 lixingbo crxxxxx Initail creation
04/24/2004 lixingbo p005089 Modify some bugs.
04/27/2004 lixingbo p005153 Modify a bug.
05/24/2004 lixingbo p005556 Modify some bug for dolphin.
06/04/2004 caoyanqing p005953 modify a bug for odin.
06/09/2004 lixingbo p006042 Modify some bugs for dolphin.
06/12/2004 lixingbo p006139 Modify the bug that wrong score when start.
06/25/2004 lixingbo p006416 Modify the bug that wrong score when start.
07/01/2004 lixingbo p006599 Modify some bugs about the balls' move.
07/06/2004 lixingbo p006763 Modify the bug that balls don't dispear when sys added.
07/29/2004 lixingbo p007367 Modify a bug that array flow.
07/22/2004 caoyanqing p007164 Modify a bug of refreshing the screen.
08/25/2004 lixingbo p007925 when call come and reject,the pen lost sometimes.
08/31/204 Simba Lee p008037 the cust paint function is wrong.
Self-documenting Code
Describe/explain low-level design of this module and/or group of funtions and/or specific
funtion that are hard to understand by reading code and thus requires detail description.
Free format !
====================================================================================================
INCLUDE FILES
==================================================================================================*/
#include "APP_include.h"
#include "TP_Operator.h"
#include "MENU_main.h"
#include "MENU_item.h"
#include "GAMES_main.h"
#include "GAMES_fallball_path.h"
#ifdef GAMES_FALLBALL
#include <stdlib.h>
#include "uhapi.h"
#include "SP_volume.h"
#include "SP_audio.h"
#include "Ds_lcd.h"
#include "EDITOR_type.h"
#include "GAMES_fallball.h"
#include "product.h"
/* The layout of the game fallball.*/
#define SQUARELENGTH 16
/* define five kinds of balls and the floor .*/
#define FLOOR 0
#define COLOR1 1
#define COLOR2 2
#define COLOR3 3
#define COLOR4 4
#define COLOR5 5
#define BALL_NUM 5
/* one color ,there are two squares ,the distance of these two squares about
storage is one. */
#define OFFSET 1
#define MAX_STRING_LENGTH 100
/*==================================================================================================
GLOBAL VARIABLES
==================================================================================================*/
/* The globle variable that defined in GAMES_main.c */
extern APP_GAMES_STRUCTURE_NAME_T gamesApp_data;
extern APP_SUBSTATE_STRUCTURE_NAME_T games_substate;
extern PathElem FallballPath[MAX_LINE*MAX_COLUMN];
extern OP_INT8 FallballCurPath;
/*==================================================================================================
GLOBAL FUNCTION DEFINITIONS
==================================================================================================*/
void APP_Fallball_entry(void);
void APP_Fallball_exit(void);
void APP_Fallball_handler(OPUS_EVENT_ENUM_TYPE event,void *pMess,OP_BOOLEAN *handle);
/*==================================================================================================
LOCAL FUNCTION DEFINITIONS
==================================================================================================*/
static void CountScore(OP_INT16 *score,OP_INT16 DelBallNumber);
static OP_BOOLEAN DeleteBall(OP_INT16 x,OP_INT16 y);
static void DeleteOneBall(OP_INT16 x,OP_INT16 y);
static void DrawSquare(OP_INT16 x,OP_INT16 y,OP_INT16 ball_type);
static void FallballPenProcess(OP_INT16 x,OP_INT16 y);
static void FallNewBall();
static void GetRandomNumber(OP_INT16 *number1,OP_INT16 *number2,OP_INT16 *number3);
static void InitCurrentBox();
static void InitFallball();
static OP_INT16 JudgeGameOver(OP_INT16 current_empty_box_number);
static void MoveBall(OP_INT16 x,OP_INT16 y);
static void MoveOneStep(OP_INT16 x,OP_INT16 y);
static void OnTwingklingTimer();
static void Repaint();
static void RouteMove(PathElem FallballPath[MAX_LINE*MAX_COLUMN]);
static void ShowScore(void);
static void drawDigit(OP_INT16 wInteger,OP_INT16 x, OP_INT16 y);
extern OP_BOOLEAN SearchBallRoute(PosType start,PosType end);
/* The variable that records the number of the position that is empty. */
static OP_INT16 reserved_position = MAX_LINE*MAX_COLUMN;
/* The array that records the whole map's state. */
static OP_INT16 cur_box[MAX_LINE][MAX_COLUMN]={FLOOR};
/* The current focus position. */
static OP_INT16 selected_pos = -1;
/* The current score.*/
static OP_INT16 score = 0;
/* The current focus ball's state ,it may be big or small ,that is for twinkling.*/
static OP_INT16 state = 1;
/* When move a ball ,it may need several steps.*/
static OP_INT16 pathstep = 0;
/* The current x and y for position. */
static OP_INT16 cur_x = -1,cur_y = -1;
static RM_SOUND_ID_T sound_list[]=
{
RES_SOUND_0010, /* Cargador opening song */
RES_SOUND_0013, /* balls are deleted */
RES_SOUND_0014, /* ball isn't moved */
RES_SOUND_0010, /* game over */
};
/*==================================================================================================
LOCAL FUNCTIONS
==================================================================================================*/
/*==================================================================================================
FUNCTION: GetBox
DESCRIPTION:
The function for external use to get the current box that express the current position of the map.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_INT16 *GetBox(void)
{
return (OP_INT16 *)cur_box;
}
/*==================================================================================================
FUNCTION: InitCurrentBox
DESCRIPTION:
Initialize all the data .
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void InitCurrentBox()
{
OP_INT16 i,j;
OP_INT16 temp_num;
OP_INT16 ball_type;
OP_INT16 pos1,pos2,pos3;
op_debug(DEBUG_MED,"InitCurrentBox();\n");
GetRandomNumber(&pos1,&pos2,&pos3);
for(i=0;i<MAX_LINE;i++)
for(j=0;j<MAX_COLUMN;j++)
{
temp_num = i*MAX_COLUMN+j;
if(temp_num == pos1 || temp_num == pos2 || temp_num == pos3)
{
ball_type = rand()%BALL_NUM;
cur_box[i][j] = ball_type+1;
}
else
{
cur_box[i][j] = FLOOR;
}
}
}
/*==================================================================================================
FUNCTION: InitFallball
DESCRIPTION:
draw all the balls in the image.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void InitFallball()
{
OP_INT16 i,j;
op_debug(DEBUG_MED,"InitFallball:entrance!");
state = 1;
selected_pos = -1;
op_memset(cur_box, 0x00,sizeof(cur_box));
FallballCurPath = (OP_INT8)(MAX_LINE*MAX_COLUMN);
reserved_position = MAX_LINE*MAX_COLUMN;
score = 0;
srand(op_get_cur_tod());
InitCurrentBox();
ds_draw_bitmap_image_rm_forward(0,0,BMP_BALL_BACKGROUND);
op_debug(DEBUG_MED,"InitFallball(): BMP_BALL_BACKGROUND has been drawn!\n");
for(i=0;i<MAX_LINE;i++)
{
for(j=0;j<MAX_COLUMN;j++)
{
if(cur_box[i][j]!=FLOOR)
{
DrawSquare(j,i,cur_box[i][j]*2);
op_debug(DEBUG_MED,"InitFall():cur_box[%d][%d] has been drawn!\n",i,j);
}
}
}
ShowScore();
ds_set_softkeys_rm( PMPT_SKEY_RESTART,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
ds_refresh();
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[0], gamesApp_data.volume, OP_FALSE);
}
op_debug(DEBUG_MED,"InitFallball:exit!");
}
/*==================================================================================================
FUNCTION: GetRandomNumber
DESCRIPTION:
Get the random number . The random number shoud be in the empty currency box.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void GetRandomNumber(OP_INT16 *number1,OP_INT16 *number2,OP_INT16 *number3)
{
OP_UINT8 i,j,k;
OP_INT16 num_temp[3];
OP_UINT8 index=0;
OP_INT16 num[3]={-1,-1,-1};
op_debug(DEBUG_MED,"GetRandNumber():\n");
for(i=0;i<3;i++)
{
OP_BOOLEAN end_loop = OP_FALSE;
if(reserved_position == 0)
{
break;
}
num_temp[i] = rand()%reserved_position;
index = 0;
for(j=0;j<MAX_LINE;j++)
{
for(k=0;k<MAX_COLUMN;k++)
{
if(cur_box[j][k] == FLOOR)
{
if(index == num_temp[i])
{
cur_box[j][k] = 1;
num[i] = j*MAX_COLUMN + k;
end_loop = OP_TRUE;
reserved_position--;
break;
}
index++;
}
}
if(end_loop == OP_TRUE)
{
break;
}
}
}
*number1 = num[0];
*number2 = num[1];
*number3 = num[2];
}
/*==================================================================================================
FUNCTION: CountScore
DESCRIPTION:
when the balls have been deleted ,add the score.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void CountScore(OP_INT16 *score,OP_INT16 DelBallNumber)
{
OP_INT16 score_temp = DelBallNumber;
op_debug(DEBUG_MED,"CountScore():\n");
if(DelBallNumber > 5)
{
score_temp += (DelBallNumber - 5);
if(DelBallNumber >= 9)
{
score_temp += 5;
}
}
*score += score_temp;
}
/*==================================================================================================
FUNCTION: JudgeGameOver
DESCRIPTION:
If no empty position ,the game will over.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_INT16 JudgeGameOver(OP_INT16 current_empty_box_number)
{
op_debug(DEBUG_MED,"JudegGameOver():\n");
if(current_empty_box_number == 0)
{
return 1;
}
return 0;
}
/*==================================================================================================
FUNCTION: MoveBall
DESCRIPTION:
Move the ball from the original position to the current position.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void MoveBall(OP_INT16 x,OP_INT16 y)
{
PosType start,end;
OP_INT16 step_x,step_y;
op_debug(DEBUG_MED,"MoveBall:entrance!\n");
start.x = cur_x;
start.y = cur_y;
end.x = x;
end.y = y;
pathstep = 1;
SearchBallRoute(start,end);
if(pathstep+2 <= FallballCurPath)
{
step_x = FallballPath[pathstep].seat.x;
step_y = FallballPath[pathstep].seat.y;
MoveOneStep(step_x,step_y);
OPUS_Start_Timer(OPUS_TIMER_GAME_PEN,30,0,ONE_SHOT);
}
else
{
FallballCurPath = (OP_INT8)(MAX_LINE*MAX_COLUMN);
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[2], gamesApp_data.volume, OP_FALSE);
}
}
op_debug(DEBUG_MED,"MoveBall:exit!\n");
}
/*==================================================================================================
FUNCTION: RouteMove
DESCRIPTION:
when move a ball ,if it need several steps,each step ,use this function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void RouteMove(PathElem FallballPath[MAX_LINE*MAX_COLUMN])
{
OP_INT16 next_x,next_y;
if(FallballCurPath == (OP_INT8)(MAX_LINE*MAX_COLUMN))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -