📄 shoot.c
字号:
//----------------------------------------------------------
// english shoot game
//----------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include "newtypes.h"
#include "globals.h"
#include "display.h"
#include "string.h"
#include "fs.h"
#include "userapi.h"
#include "input.h"
#include "learn.h"
#include "sysdata.h"
#include "ctype.h"
#include "cursor.h"
#include "debug.h"
//#define _MYDEBUG
#define SHOOT_TIME 6
#define SHOOT_WORDX 82
static code RECT c_rectShootSetButtons[]=
{
{ 95+1, 2+1, 124, 16 },
{ 83+1, 59+1, 96, 74 }, { 137+1, 59+1, 150, 74 },
};
void ShootResultDisp(BYTE result,BYTE flag);
void GetWord(void);
void ShootGameResult(void);
void Shoot_Init_Disp(void);
bit isalpha(char ch);
void shoot_display_word(void);
void X_Store_UserSettings(void);
void shoot_setting_book_disp(void);
uint16 DrawTextNew(uint8 font, RECT *rc, const char *str, uint16 len, uint16 options);
uint8 Help(void);
code BYTE GunBmp[] =
{0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0xFE, 0xFE, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00,
0x3C, 0x24, 0xE2, 0xE1, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xE1, 0xE2, 0x24, 0x3C, 0x00, };
code BYTE ResultBmp[] =
{0x00, 0x02, 0x84, 0x98, 0x20, 0xC0, 0xA0, 0x6E, 0x50, 0x90, 0x48, 0x28, 0x1C, 0x04, 0x02, 0x00,
0x81, 0x41, 0x30, 0x08, 0x04, 0x03, 0x02, 0x7C, 0x04, 0x0A, 0x09, 0x11, 0x21, 0x21, 0x40, 0x00, };
void shoot_display_word(void)
{
BYTE len,i,x,y,k;
BYTE str[20];
y = 2;
x = SHOOT_WORDX;
k = 0;
len = strlen(g_study.pszSpelling);
//DebugDump(g_study.pszSpelling,len);
for(i=0;i<=len;i++,k++)
{
if(g_study.pszSpelling[i]=='\n'||g_study.pszSpelling[i]=='\r')
{
str[k] = 0;
x = DrawSingleLine(FONT16, SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y +=16;
k = 0;
}
else if(g_study.pszSpelling[i]==0)
{
str[k] = 0;
x = DrawSingleLine(FONT16, SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y += 16;
k = 0;
break;
}
else
{
if(k == 9 || (k == 8&& g_study.pszSpelling[i]>=0x80))
{
str[k] = 0;
x = DrawSingleLine(FONT16,SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y += 16;
k = 0;
}
str[k] = g_study.pszSpelling[i];
}
}
len = strlen(g_study.pszExplain);
k = 0;
for(i=0;i<=len;i++)
{
if(g_study.pszExplain[i]=='\n'||g_study.pszExplain[i]=='\r'||g_study.pszExplain[i]==0x0d)
{
str[k] = 0;
x = DrawSingleLine(FONT16, SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y +=16;
k = 0;
str[k] = 0;
}
else if(g_study.pszExplain[i]==0)
{
str[k] = 0;
x = DrawSingleLine(FONT16, SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y += 16;
k = 0;
str[k] = 0;
break;
}
else
{
if((k == 9) || ((k == 8)&&(g_study.pszExplain[i]<0)))
{
str[k] = 0;
x = DrawSingleLine(FONT16,SHOOT_WORDX, y, str, k);
if ( x < CXSCR-2 )
ClearRect(x, y, CXSCR-2-x, 16);
y += 16;
k = 0;
str[k] = 0;
}
if(g_study.pszExplain[i]<0)
{
str[k++] = g_study.pszExplain[i++];
str[k++] = g_study.pszExplain[i];
}
else
str[k++] = g_study.pszExplain[i];
}
if(y>112)
break;
}
if(y<144)
ClearRect(SHOOT_WORDX, y, CXSCR-2-SHOOT_WORDX,114-y );
}
void Shoot_Display(void)
{
BYTE i;
BYTE GunBmpPosX,GunBmpPosY;
if(g_shootinfo.reflash&0x01)
{
if(g_shootinfo.StartY>8)
ClearRect(1,g_shootinfo.StartY-8,SHOOT_WORDX-4,16); //clear letter
if(g_shootinfo.BootX&&g_shootinfo.BootY<136)
ClearRect(g_shootinfo.BootX,g_shootinfo.BootY+8,4,4); //clear boot
if(g_shootinfo.BootY>8&&g_shootinfo.BootX)
FillRect(g_shootinfo.BootX,g_shootinfo.BootY,4,4); //display boot
}
for(i=0;i<4;i++) // display letter
{
if(g_shootinfo.StartY+8<136)
DrawChar(g_shootinfo.StartX[i],g_shootinfo.StartY,g_shootinfo.TypeSel[i]);
}
if(g_shootinfo.reflash&0x02)
{
ClearRect(g_shootinfo.GunOldX,141,16,16); //clear gun
}
GunBmpPosX = g_shootinfo.GunNewX;
DrawImage(GunBmpPosX,141,IMAGE_GUN_START);
if((g_shootinfo.flag == GAME_TRUE ||g_shootinfo.flag == GAME_FALSE)&&(g_shootinfo.BootX!=0))
{
// GunBmpPosX = g_shootinfo.StartX[(g_shootinfo.BootX-5-g_shootinfo.WordNum*8)/16];
GunBmpPosX = g_shootinfo.BootX;
GunBmpPosY = g_shootinfo.StartY;
/* if(GunBmpPosX>100&&g_shootinfo.flag == GAME_FALSE)
GunBmpPosX-=8;
else if(GunBmpPosX == 0)
{
if(g_shootinfo.BootX>100)
GunBmpPosX = 100;
else
GunBmpPosX = g_shootinfo.BootX;
} */
if(g_shootinfo.BootX>SHOOT_WORDX-6)
GunBmpPosX = SHOOT_WORDX-6;
DrawImage(GunBmpPosX,GunBmpPosY,IMAGE_RESULT_START);
}
if(g_shootinfo.reflash)
g_shootinfo.reflash = 0;
}
BYTE DoGameShoot(BYTE nKey)
{
if(g_shootinfo.flag!=GAME_PAUSE)
ResetOffTimer();
if(g_SyncDiffTimeCounter==1&&g_shootinfo.flag!=GAME_PAUSE)
{
g_shootinfo.state = GAME_DISPLAY;
if(g_shootinfo.StartY+8<LAST_GAME_Y)
g_shootinfo.StartY +=8;
else
{
g_shootinfo.state = GAME_RESULT;
ShootGameResult();
}
if(g_shootinfo.BootY&&(g_shootinfo.BootY-8)>8)
g_shootinfo.BootY -= 8;
g_shootinfo.reflash |= 1;
g_SyncDiffTimeCounter = SHOOT_TIME;
}
{
switch(nKey)
{
case KEY_LEFT:
if(g_shootinfo.GunNewX>=8&&g_shootinfo.flag!=GAME_PAUSE)
{
g_shootinfo.GunOldX = g_shootinfo.GunNewX;
g_shootinfo.GunNewX -= 8;
g_shootinfo.state = GAME_DISPLAY;
g_shootinfo.reflash |= 0x02;
}
break;
case KEY_RIGHT:
if(g_shootinfo.GunNewX<60&&g_shootinfo.flag!=GAME_PAUSE)
{
g_shootinfo.GunOldX = g_shootinfo.GunNewX;
g_shootinfo.GunNewX += 8;
g_shootinfo.state = GAME_DISPLAY;
g_shootinfo.reflash |= 0x02;
}
break;
case KEY_ENTER:
if(!g_shootinfo.BootX&&!g_shootinfo.BootY&&g_shootinfo.flag!=GAME_PAUSE)
{
g_shootinfo.BootX = g_shootinfo.GunNewX+6;
g_shootinfo.BootY = 136;
FillRect(g_shootinfo.BootX,g_shootinfo.BootY,4,4); //display boot
g_shootinfo.state = GAME_DISPLAY;
}
break;
case KEY_HELP:
nKey=Help();
if ( !IsFuncKey(nKey))
{
ClearScreen();
g_shootinfo.reflash =1;
Shoot_Init_Disp();
Shoot_Display();
shoot_display_word();
ShootResultDisp(g_shootinfo.WringNum,GAME_TRUE);
ShootResultDisp(g_shootinfo.WrongNum,GAME_FALSE);
}
break;
case KEY_EXIT:
g_shootinfo.state = GAME_OVER;
break;
}
}
if((g_shootinfo.BootY == g_shootinfo.StartY)||(g_shootinfo.BootY==g_shootinfo.StartY+8))
{
g_shootinfo.state = GAME_RESULT;
ShootGameResult();
}
return nKey;
}
bool StudyLoadSet(void);
bool StudyOpenFile(void);
void StudySaveSet(void);
bool StudySetFile(void);
uint8 StudyAutoLoadSet(void);
void StudyLoadUnit(void);
BYTE shoot_setting(uint8 sign)
{
uint8 nButton;
memset(&g_study, 0, sizeof(g_study));
StudyLoadSet();
if ( !StudyOpenFile() )
{
memset(&g_study.set, 0, sizeof(g_study.set));
g_study.handle = FS_ERROR_HANDLE;
}
shoot_setting_book_disp();
nButton = 0xFF;
while(1)
{
g_nKey = GetKey();
if ( KEY_ESCAPE == g_nKey )
{ StudySaveSet();
break;
}
if (KEY_ENTER == g_nKey )
{
if ( strlen(g_study.set.szPath) <3)
return KEY_ESCAPE;
StudySaveSet();
if(!sign) break;
memset(&(g_shootinfo.WringNum),0,26);
Shoot_Init_Disp(); //draw some no change
DrawTextChar(FONT12,112,128,'0');
DrawTextChar(FONT12,112,144,'0');
g_study.nWordIndex = g_study.nUnitWordStart;
GetWord();
g_shootinfo.GunNewX = 36;
g_shootinfo.GunOldX = 36;
g_shootinfo.state = GAME_DISPLAY;
break;
}
if ( PEN_DOWN == g_nKey || PEN_MOVE == g_nKey || PEN_UP == g_nKey )
{
if ( PenSelectButtons(g_nKey, &nButton, c_rectShootSetButtons, g_study.set.szPath[0]?9:1) )
{
switch(nButton)
{
case 0:
FileListInit(FILELIST_WORD);
while(1)
{
g_nKey = FileList();
if ( KEY_ENTER != g_nKey )
break;
if ( g_study.handle != FS_ERROR_HANDLE )
{
FsCloseHandle(g_study.handle);
}
if ( StudySetFile() )
break;
g_study.set.szPath[0] = 0;
g_study.handle = FS_ERROR_HANDLE;
MessageBox(MSGBOX_EBOOK_ERROR);
}
if ( !IsPowerOffKey(g_nKey) )
{
shoot_setting_book_disp();
}
break;
case 1:
if ( g_study.set.szPath[0] && g_study.set.nUnit > 1 )
{
g_study.set.nUnit--;
StudyLoadUnit();
itoa(g_study.set.nUnit, g_study.szNum);
ClearRect((137+96)/2-8, 60, 16, 16);
DrawString((137+96)/2-8, 60, g_study.szNum);
itoa(g_study.nUnitWordCount, g_study.szNum);
ClearRect(84, 80, 16, 16);
DrawString(84, 80, g_study.szNum);
}
break;
case 2:
if ( g_study.set.szPath[0] && g_study.set.nUnit < g_study.nGroupCount )
{
g_study.set.nUnit++;
StudyLoadUnit();
itoa(g_study.set.nUnit, g_study.szNum);
ClearRect((137+96)/2-8, 60, 16, 16);
DrawString((137+96)/2-8, 60, g_study.szNum);
itoa(g_study.nUnitWordCount, g_study.szNum);
ClearRect(84, 80, 16, 16);
DrawString(84, 80, g_study.szNum);
}
break;
}
nButton = 0xFF;
}
}
else if ( KEY_HELP== g_nKey )
{
g_nKey = Help();
if ( !IsPowerOffKey(g_nKey) )
{
ClearScreen();
g_nKey = KEY_NULL;
shoot_setting_book_disp();
}
}
if ( IsPowerOffKey(g_nKey) )
break;
}
return g_nKey;
}
void shoot_setting_book_disp(void)
{
ClearScreen();
DrawImage(0, 0, IMAGE_SHOOTSET_START);
if ( strlen(g_study.set.szPath) >= 20 )
DrawString(0, 20, g_study.set.szPath);
else
DrawString((20-strlen(g_study.set.szPath))*4, 20, g_study.set.szPath);
if ( g_study.set.szPath[0] )
{
itoa(g_study.nWordCount, g_study.szNum);
DrawString(84, 40, g_study.szNum);
itoa(g_study.set.nUnit, g_study.szNum);
DrawString((137+96)/2-8, 60, g_study.szNum);
itoa(g_study.nUnitWordCount, g_study.szNum);
DrawString(84, 80, g_study.szNum);
}
}
void Shoot_Init_Disp(void)
{
ClearScreen();
if(g_shootinfo.flag!=GAME_PAUSE)
DrawImage(130,136,IMAGE_PAUSE_BUTTON_START);
else
DrawImage(130,136,IMAGE_START_START);
DrawTextLine(FONT12,SHOOT_WORDX,128,"打中:",5);
DrawTextLine(FONT12,SHOOT_WORDX,144,"飞靶:",5);
DrawRect( 0,0,160,160);
DrawVertLine(80,0,160);
DrawHorizLine(80,126,159);
}
void ShootGameResult(void)
{
BYTE y;
y=(g_shootinfo.BootX-9)/16;
if((g_shootinfo.TypeSel[y] == g_shootinfo.TypeCh)&&(g_shootinfo.BootX -1== g_shootinfo.StartX[y]))
{
g_shootinfo.flag = GAME_TRUE;
g_shootinfo.WringNum++;
ShootResultDisp(g_shootinfo.WringNum,GAME_TRUE);
DrawRect(87,80,64,28);
DrawSpecialString(FONT24,89,82,"厉害!");
}
else
{
g_shootinfo.flag = GAME_FALSE;
g_shootinfo.WrongNum++;
ShootResultDisp(g_shootinfo.WrongNum,GAME_FALSE);
DrawRect(87,80,64,28);
DrawSpecialString(FONT24,89,82,"错了!");
}
Shoot_Display();
SysDeadDelay(1500);
GetWord();
g_shootinfo.state = GAME_DISPLAY;
}
code RECT Shoot_Button[]={{130+1,136+1,159-1,151-1}};
BYTE ShootGame(void)
{
BYTE nKey,g_nSelectKey=0xff;
g_shootinfo.reflash =0;
g_SyncDiffTimeCounter = SHOOT_TIME;
g_nKey = shoot_setting(1);
if ( KEY_ENTER != g_nKey )
return g_nKey;
// g_study.rect.left = 122;
// g_study.rect.top = 2;
// g_study.rect.right = CXSCR-2;
// g_study.rect.bottom = 126;
// GetWord();
while(1)
{
if(g_shootinfo.flag!=GAME_PAUSE&&g_shootinfo.state ==GAME_DISPLAY )
Shoot_Display();
nKey=WaitKey(50);
if (IsFuncKey(nKey)||nKey==KEY_EXIT)
break;
if(nKey == PEN_DOWN||nKey == PEN_MOVE||nKey == PEN_UP)
{
if(PenSelectButton(nKey,Shoot_Button,1,&g_nSelectKey))
{
if(nKey==PEN_UP)
{
if(g_shootinfo.flag!=GAME_PAUSE)
{
DrawImage(130,136,IMAGE_START_START);
g_shootinfo.flag=GAME_PAUSE;
}
else
{
DrawImage(130,136,IMAGE_PAUSE_BUTTON_START);
g_shootinfo.flag=GAME_DURING;
}
g_nSelectKey = 0xff;
}
}
}
switch(g_shootinfo.state)
{
case GAME_DISPLAY:
nKey=DoGameShoot(nKey);
break;
case GAME_RESULT:
ShootGameResult();
break;
case GAME_OVER:
break;
}
if(g_shootinfo.state==GAME_OVER)
break;
if (IsFuncKey(nKey))
break;
}
if ( FS_ERROR_HANDLE != g_study.handle )
FsCloseHandle(g_study.handle);
return nKey;
}
//----------------------------------------------------------
void StudyLoadWord(uint16 nWordNo);
void StudyLoadDictWord(uint32 nWordNo);
void GetWord(void)
{
BYTE temp;
g_study.nWordNo[0] = g_study.nWordIndex;
g_shootinfo.BootX = 0;
g_shootinfo.BootY = 0;
g_study.isUserWord = 0;
StudyLoadWord(g_study.nWordNo[0]);
if(g_study.nWordIndex<g_study.nUnitWordStart+g_study.nUnitWordCount-1)
g_study.nWordIndex++;
else
g_study.nWordIndex=g_study.nUnitWordStart;
temp = rand()%(strlen(g_study.pszSpelling)-1);
if(g_study.pszSpelling[temp]==' ')
temp++;
g_shootinfo.TypeCh = g_study.pszSpelling[temp];
g_study.pszSpelling[temp] = '_';
g_shootinfo.TypeSel[0] = 'a' + rand()%6;
g_shootinfo.TypeSel[1] = 'g' + rand()%6;
g_shootinfo.TypeSel[2] = 'm' + rand()%6;
g_shootinfo.TypeSel[3] = 's' + rand()%6;
// g_shootinfo.TypeSel[4] = 'u' + rand()%6;
if(g_shootinfo.TypeCh<'g')
g_shootinfo.TypeSel[0] = g_shootinfo.TypeCh;
else if(g_shootinfo.TypeCh<'m')
g_shootinfo.TypeSel[1] = g_shootinfo.TypeCh;
else if(g_shootinfo.TypeCh<'s')
g_shootinfo.TypeSel[2] = g_shootinfo.TypeCh;
else //if(g_shootinfo.TypeCh<'u')
g_shootinfo.TypeSel[3] = g_shootinfo.TypeCh;
// else
// g_shootinfo.TypeSel[4] = g_shootinfo.TypeCh;
g_shootinfo.TypeSel[4] = 0;
g_shootinfo.WordNum = rand()%2;
g_shootinfo.StartX[0] = 9+(rand()%2)*8;
g_shootinfo.StartX[1] = 25+(rand()%2)*8;
g_shootinfo.StartX[2] = 41+(rand()%2)*8;
g_shootinfo.StartX[3] = 57+(rand()%2)*8;
// g_shootinfo.StartX[4] = 65;
g_shootinfo.StartY = 8;
g_shootinfo.flag = GAME_DURING;
ClearRect(1,1,78,156);
shoot_display_word();
g_SyncDiffTimeCounter = SHOOT_TIME;
}
//----------------------------------------------------------
void ShootResultDisp(BYTE result,BYTE flag)
{
BYTE buf[10];
itoa(result,buf);
if(flag==3) //ok
{
DrawTextLine(FONT12,112,128,buf,0xff);
}
else
{
DrawTextLine(FONT12,112,144,buf,0xff);
}
}
//----------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -