📄 outofmouth.cpp
字号:
iScore=0;
iLevel=0;
iFrame=0;
delayflag=0;
iDistance=DISTANCE;
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
}
// lookup for proper walking sequence
static int animation_seq[4] = {0,1,0,2};
static int state[5]={0,1,2,3,4};
static int ss=0;
int index; // general looping variable
// make sure this isn't executed again
if (window_closed)
return(0);
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if
// copy background to back buffer显示背景
DDraw_Draw_Surface(lpddsbackground,0,0, SCREEN_WIDTH,SCREEN_HEIGHT, lpddsback,0);
//显示文字
sprintf(buffer,"狗口脱险 ver 0.1 分数: %d 关卡: %d 帧数: %d",iScore,iLevel,iFrame);
Draw_Text_GDI(buffer, 16,SCREEN_HEIGHT-130, 252,lpddsback);
if(iGameMode==0)
{
sprintf(buffer,"记分模式");
Draw_Text_GDI(buffer, 16,110, 252,lpddsback);
}
if(iGameMode==1)
{
sprintf(buffer,"过关模式");
Draw_Text_GDI(buffer, 16,110, 252,lpddsback);
}
if(iGameMode==2)
{
sprintf(buffer,"连续模式");
Draw_Text_GDI(buffer, 16,110, 252,lpddsback);
}
if(iGameMode==3)
{
sprintf(buffer,"挑战模式 尚未完成 ;-)");
Draw_Text_GDI(buffer, 16,110, 252,lpddsback);
}
// move objects around
for (index=0; index < 3; index++)
{
// move each object to the right at its given velocity
aliens[index].x++; // =aliens[index].velocity;
// test if off screen edge, and wrap around
if (aliens[index].x > SCREEN_WIDTH)
aliens[index].x = - 80;
// animate bot
if (++aliens[index].counter >= (8 - aliens[index].velocity))
{
// reset counter
aliens[index].counter = 0;
// advance to next frame
if (++aliens[index].current_frame > 3)
aliens[index].current_frame = 0;
} // end if
} // end for index
// draw all the bots
for (index=0; index < 3; index++)
{
// draw objects
DDraw_Draw_Surface(aliens[index].frames[animation_seq[aliens[index].current_frame]],
aliens[index].x, aliens[index].y,
72,80,
lpddsback);
} // end for index
if (KEYDOWN('A')&&KEYDOWN('S')&&delayflag)
{
//跳关
iLevel++;
iScore+=500;
delayflag=0;
iDistance=DISTANCE;
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
}
///////////////////////////////////////////////
//game logic
//move mouth
if(iDistance>30)
{
//游戏逻辑
smallone.y-=iSpeed;
for(index=0; index<TOOTH_NUM; index++)
{
map.BottomSet[index].y -= iSpeed;
map.TopSet[index].y += iSpeed;
}
iDistance-=2;
}
else
{
//关卡判断
if(smallone.position==map.iKey&&!iDeathFlag)
{
//过关动画
if(iDistance>0)
{
smallone.y-=iSpeed;
for(index=0; index<TOOTH_NUM; index++)
{
map.BottomSet[index].y -= iSpeed;
map.TopSet[index].y += iSpeed;
}
iDistance-=2;
}
else
{
//过关等待,生成下一关。
iLevel++;
if(iGameMode!=1)
{
iScore+=500;
}
Sleep(500);
iDistance=DISTANCE;
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
}
}
else if(!iDeathFlag)
{
//死亡
iDeathFlag=1;
//bow2
iBowFlag2=1;
iCounterBow2=0;
bow2.x=smallone.x-15;
bow2.y=smallone.y-15;
smallone.current_frame=1;
//
if(iGameMode!=1)
{
iScore-=250;
}
//int now=iFrame;
}
else
{
//死亡动画
if(iDistance>0)
{
bow2.y-=iSpeed;
smallone.y-=iSpeed;
for(index=0; index<TOOTH_NUM; index++)
{
map.BottomSet[index].y -= iSpeed;
//map.TopSet[index].y += iSpeed;
}
iDistance-=1;
}
else if(iGameMode==2)
{
//连续模式死亡处理
iDeathDelayFlag=0;
iDistance=DISTANCE;
Sleep(1000);
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
}
else if(iGameMode==1)
{
//闯关模式死亡处理
sprintf(buffer,"你被卡死了!!!!!! 最高关数: %d 按回车键在玩一盘!",iLevel);
Draw_Text_GDI(buffer, 16,26, 252,lpddsback);
/*
iDeathDelayFlag=0;
iDistance=DISTANCE;
Sleep(8000);
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
*/
}
else if(iGameMode==3)
{
//极限模式死亡处理
}
else if(iGameMode==0)
{
//记分模式死亡处理
iScore--;
if(smallone.position==map.iKey)
{
Sleep(500);
iDistance=DISTANCE;
if(!Build_Map())
{
return(0);
}
iDeathFlag=0;
}
}
}
}
///////////////////////////////////////////
if(KEYDOWN(VK_RIGHT)&&delayflag)
{
//右操作
//bow
iBowFlag=1;
iCounterBow=0;
bow.x=smallone.x;
bow.y=smallone.y;
/////////
delayflag=0;
if( smallone.position==(TOOTH_NUM - 1) )
{
smallone.position=0;
smallone.x=INIT_BOTTOM_X;
smallone.y=map.BottomSet[0].y- map.BottomSet[smallone.position].current_frame * SMALLONE_HEIGHT + SMALLONE_SPEC;
//turnflag=0;
}
else
{
switch(map.BottomSet[smallone.position+1].current_frame)
{
case 0:
{
smallone.x+=50;
smallone.y=map.BottomSet[0].y+110;
break;
}
case 1:
{
smallone.x+=50;
smallone.y=map.BottomSet[0].y+80;
break;
}
case 2:
{
smallone.x+=50;
smallone.y=map.BottomSet[0].y+50;
break;
}
case 3:
{
smallone.x+=50;
smallone.y=map.BottomSet[0].y+20;
break;
}
case 4:
{
smallone.x+=50;
smallone.y=map.BottomSet[0].y-10;
break;
}
}//switch end
smallone.position++;
}
}
if(KEYDOWN(VK_LEFT)&&delayflag)
{
//左操作
//bow
iBowFlag=1;
iCounterBow=0;
bow.x=smallone.x;
bow.y=smallone.y;
/////////
delayflag=0;
if( smallone.position==0 )
{
smallone.position=TOOTH_NUM - 1;
smallone.x=INIT_BOTTOM_X + smallone.position * TOOTH_WIDTH;
smallone.y=map.BottomSet[0].y- map.BottomSet[smallone.position].current_frame * SMALLONE_HEIGHT + SMALLONE_SPEC;
//turnflag=0;
}
else
{
switch(map.BottomSet[smallone.position-1].current_frame)
{
case 0:
{
smallone.x-=50;
smallone.y=map.BottomSet[0].y+110;
break;
}
case 1:
{
smallone.x-=50;
smallone.y=map.BottomSet[0].y+80;
break;
}
case 2:
{
smallone.x-=50;
smallone.y=map.BottomSet[0].y+50;
break;
}
case 3:
{
smallone.x-=50;
smallone.y=map.BottomSet[0].y+20;
break;
}
case 4:
{
smallone.x-=50;
smallone.y=map.BottomSet[0].y-10;
break;
}
}//switch end
smallone.position--;
}
}
//显示小东西
DDraw_Draw_Surface(smallone.frames[smallone.current_frame],
smallone.x, smallone.y,
50,30,
lpddsback);
//显示牙齿
for (index=0; index < TOOTH_NUM; index++)
{
DDraw_Draw_Surface(tooth[map.BottomSet[index].current_frame].frames[0],
map.BottomSet[index].x, map.BottomSet[index].y,
TOOTH_WIDTH,TOOTH_HEIGHT,
lpddsback);
DDraw_Draw_Surface(tooth[map.TopSet[index].current_frame].frames[0],
map.TopSet[index].x, map.TopSet[index].y,
TOOTH_WIDTH,TOOTH_HEIGHT,
lpddsback);
}
//显示爆炸1
if(iCounterBow>12)
{
iBowFlag=0;
}
if(iBowFlag)
{
DDraw_Draw_Surface(bow.frames[iCounterBow],
bow.x, bow.y,
BOW_WIDTH,BOW_HEIGHT,
lpddsback);
iCounterBow++;
}
////显示爆炸2
if (KEYDOWN(VK_CONTROL))
{
iBowFlag2=1;
iCounterBow2=0;
bow2.x=smallone.x-15;
bow2.y=smallone.y-15;
smallone.current_frame=1;
}
if(iCounterBow2>12)
{
iBowFlag2=0;
}
if(iBowFlag2)
{
DDraw_Draw_Surface(bow2.frames[iCounterBow2],
bow2.x, bow2.y,
BOW2_WIDTH,BOW2_HEIGHT,
lpddsback);
iCounterBow2++;
}
//结束显示
// flip pages
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
// wait a sec
iFrame++;
Sleep(FRAME_PER_SEC);
// return success or failure or your own return code here
return(1);
} // end Game_Main
////////////////////////////////////////////////////////////
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
return(0);
// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set display mode to 640x480x8
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
return(0);
// we need a complex surface system with a primary and backbuffer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -