📄 go.cpp
字号:
#include "Headers.h"
#include "resource.h"
#include "DriverDialog.h"
#include "MAIN.h"
void MAIN::Init()
{
srand( (unsigned)time( NULL ) );
ZeroMemory(hit, sizeof(BYTE)*MAX_HIT);
ZeroMemory(acc, sizeof(BYTE)*MAX_ACC);
int i;
game.Init("res\\res","res\\res2",
"res\\acc","res\\dialog",
640,480);
//text
text=new OBJECT();
text->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
90000);
text->Get();
//dialog
dialog=new OBJECT();
dialog->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
90001);
dialog->Get();
//wait
wait=new OBJECT();
wait->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
90002);
wait->Get();
//map i+10000
for(i=0;i<MAX_MAP;i++)
{
map[i]=new OBJECT();
map[i]->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
i+10000);
map[i]->Get();
}
map[0]->GetAppend(hit,MAX_HIT,acc,MAX_ACC);
//sub i+20000
for(i=0;i<MAX_SUB;i++)
{
sub[i]=new OBJECT();
sub[i]->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
i+20000);
sub[i]->Get();
sub[i]->InitDlg(game.dlgmem,game.dlglength);
}
//npc i+30000
for(i=0;i<MAX_NPC;i++)
{
npc[i]=new OBJECT();
npc[i]->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
i+30000);
npc[i]->Get();
npc[i]->InitDlg(game.dlgmem,game.dlglength);
}
//boss i+40000
for(i=0;i<MAX_BOSS;i++)
{
boss[i]=new OBJECT();
boss[i]->Init(lpdd,backsurf,game.screen,
game.aresmem,game.areslength,
game.ares2mem,game.ares2length,
i+40000);
}
dkey.Create( hwnd,instance );
game.step=4;
puttext=0;
nproc=1;
music=0;
}
void MAIN::Draw()
{
static int i;
//map
map[0]->Put();
//npc
for(i=0;i<MAX_NPC;i++)
{
npc[i]->Put();//(1,50,2016);
}
//npc
for(i=0;i<MAX_NPC;i++)
{
boss[i]->Put();//(1,50,2016);
}
//sub
sub[0]->Put();//(1,50,2016);
//text
if(puttext)
{
DrawText();
text->Put();
}
static a=1;
if(a)
{
FadeIn(primsurf,backsurf,&game.screen,lpdd);
a=0;
Dialog(sub[0]);
}
}
void MAIN::Deinit()
{
int i;
//text
delete text;
//dialog
delete dialog;
//wait
delete wait;
//map
for(i=0;i<MAX_MAP;i++)
delete map[i];
//sub
for(i=0;i<MAX_SUB;i++)
delete sub[i];
//npc
for(i=0;i<MAX_NPC;i++)
delete npc[i];
//boss
for(i=0;i<MAX_BOSS;i++)
delete boss[i];
}
void MAIN::DrawText()
{
ClearSurface( text->sfc,0 );
if( text->sfc->GetDC(&hdc)==DD_OK )
{
char tx[80];
int len;
SetBkColor( hdc,RGB(0,0,0) );
SetTextColor( hdc,RGB(255,0,255) );
len=wsprintf(tx,"FPS=%03d ( %04d , %04d , %04d ) step=%02d process=%d",
Fps(),sub[0]->res2.x,sub[0]->res2.y,sub[0]->spot,game.step,nproc);
TextOut(hdc,0,0,tx,len);
TextOut(hdc,0,16,map[0]->res.filename,8);
TextOut(hdc,0,32,npc[0]->res.filename,8);
TextOut(hdc,0,48,npc[1]->res.filename,8);
text->sfc->ReleaseDC(hdc);
}
}
void MAIN::TranslateNpcInput()
{
static int n;
static int d;
static int i;
for(n=0;n<MAX_NPC;n++)
{
if(npc[n]->running<=0)
{
d=npc[n]->direction;
npc[n]->direction=rand()%100;
npc[n]->get=1;
npc[n]->SetSpot();
}
else
{
npc[n]->running-=game.step;
if( npc[n]->running==24 || npc[n]->running==8 )
{
npc[n]->step=0;
}
if(npc[n]->running==16)
{
npc[n]->step=1;
}
}
if( npc[n]->direction!=2
&& npc[n]->direction!=4
&& npc[n]->direction!=6
&& npc[n]->direction!=8 )
{
npc[n]->direction=d;
goto end;
}
// LEFT
if( npc[n]->direction==4 )
{
if( npc[n]->IsHit(hit) )
goto end;
if(npc[n]->get)
{
npc[n]->running=npc[n]->res.apprect.right-game.step;
npc[n]->step=1;
npc[n]->get=0;
if( npc[n]->IsHitObj(sub[0]) )
{
npc[n]->running=0;
return;
}
else
{
for(i=0;i<MAX_NPC;i++)
if( npc[n]->IsHitObj(npc[i]) )
{
npc[n]->running=0;
return;
}
}
}
npc[n]->Move(4,game.step,&game.screen);
goto end;
}
// RIGHT
if( npc[n]->direction==6 )
{
npc[n]->direction=6;
if(npc[n]->get)
{
npc[n]->running=npc[n]->res.apprect.right-game.step;
npc[n]->step=1;
npc[n]->get=0;
if( npc[n]->IsHitObj(sub[0]) )
{
npc[n]->running=0;
return;
}
else
{
for(i=0;i<MAX_NPC;i++)
if( npc[n]->IsHitObj(npc[i]) )
{
npc[n]->running=0;
return;
}
}
}
if( npc[n]->IsHit(hit) )
goto end;
npc[n]->Move(6,game.step,&game.screen);
goto end;
}
// UP
if( npc[n]->direction==8 )
{
npc[n]->direction=8;
if(npc[n]->get)
{
npc[n]->running=npc[n]->res.apprect.right-game.step;
npc[n]->step=1;
npc[n]->get=0;
if( npc[n]->IsHitObj(sub[0]) )
{
npc[n]->running=0;
return;
}
else
{
for(i=0;i<MAX_NPC;i++)
if( npc[n]->IsHitObj(npc[i]) )
{
npc[n]->running=0;
return;
}
}
}
if( npc[n]->IsHit(hit) )
goto end;
npc[n]->Move(8,game.step,&game.screen);
goto end;
}
// DOWN
if( npc[n]->direction==2 )
{
npc[n]->direction=2;
if(npc[n]->get)
{
npc[n]->running=npc[n]->res.apprect.right-game.step;
npc[n]->step=1;
npc[n]->get=0;
if( npc[n]->IsHitObj(sub[0]) )
{
npc[n]->running=0;
return;
}
else
{
for(i=0;i<MAX_NPC;i++)
if( npc[n]->IsHitObj(npc[i]) )
{
npc[n]->running=0;
return;
}
}
}
if( npc[n]->IsHit(hit) )
goto end;
npc[n]->Move(2,game.step,&game.screen);
goto end;
}
end:
{
}
}
}
void MAIN::TranslateInput()
{
static int to,i;
if(sub[0]->running<=0)
{
dkey.GetInput();
sub[0]->get=1;
sub[0]->SetSpot();
//accident
Accident( acc[sub[0]->spot] );
sub[0]->SetSpot();
}
else
{
sub[0]->running-=game.step;
if( sub[0]->running==24 || sub[0]->running==8 )
{
sub[0]->step=0;
}
if(sub[0]->running==16)
{
sub[0]->step=1;
}
}
// LEFT
if( KEYDOWN(dkey.keys,DIK_LEFT) )
{
sub[0]->direction=4;
if(sub[0]->get)
{
sub[0]->running=sub[0]->res.apprect.right-game.step;
sub[0]->step=1;
sub[0]->get=0;
for(i=0;i<MAX_NPC;i++)
if( sub[0]->IsHitObj(npc[i]) )
{
sub[0]->running=0;
return;
}
}
if( sub[0]->IsHit(hit) )
return;
sub[0]->Move(4,game.step,&game.screen);
return;
}
// RIGHT
if( KEYDOWN(dkey.keys,DIK_RIGHT) )
{
sub[0]->direction=6;
if(sub[0]->get)
{
sub[0]->running=sub[0]->res.apprect.right-game.step;
sub[0]->step=1;
sub[0]->get=0;
for(i=0;i<MAX_NPC;i++)
if( sub[0]->IsHitObj(npc[i]) )
{
sub[0]->running=0;
return;
}
}
if( sub[0]->IsHit(hit) )
return;
sub[0]->Move(6,game.step,&game.screen);
return;
}
// UP
if( KEYDOWN(dkey.keys,DIK_UP) )
{
sub[0]->direction=8;
if(sub[0]->get)
{
sub[0]->running=sub[0]->res.apprect.right-game.step;
sub[0]->step=1;
sub[0]->get=0;
for(i=0;i<MAX_NPC;i++)
if( sub[0]->IsHitObj(npc[i]) )
{
sub[0]->running=0;
return;
}
}
if( sub[0]->IsHit(hit) )
return;
sub[0]->Move(8,game.step,&game.screen);
return;
}
// DOWN
if( KEYDOWN(dkey.keys,DIK_DOWN) )
{
sub[0]->direction=2;
if(sub[0]->get)
{
sub[0]->running=sub[0]->res.apprect.right-game.step;
sub[0]->step=1;
sub[0]->get=0;
for(i=0;i<MAX_NPC;i++)
if( sub[0]->IsHitObj(npc[i]) )
{
sub[0]->running=0;
return;
}
}
if( sub[0]->IsHit(hit) )
return;
sub[0]->Move(2,game.step,&game.screen);
return;
}
//------------------------------------------
if( KEYDOWN(dkey.keys,DIK_H) )
{
hit[sub[0]->spot]=0xff;
return;
}
if( KEYDOWN(dkey.keys,DIK_S) )
{
acc[sub[0]->spot]=0xff;
return;
}
if( KEYDOWN(dkey.keys,DIK_LCONTROL) )
{
switch(sub[0]->direction)
{
case 4:
to=sub[0]->spot-1;
break;
case 6:
to=sub[0]->spot+1;
break;
case 2:
to=sub[0]->spot+20;
break;
case 8:
to=sub[0]->spot-20;
break;
}
for(i=0;i<MAX_NPC;i++)
{
if(npc[i]->spot==to && npc[i]->running==0)
{
Dialog(npc[i]);
return;
}
}
return;
}
if( KEYDOWN(dkey.keys,DIK_LALT) )
{
Tr(primsurf,game.screen,game.screen,
0,game.screen,game.screen,
50,0,0);
return;
}
if( KEYDOWN(dkey.keys,DIK_SPACE) )
{
FadeOut(primsurf,backsurf,&game.screen,lpdd);
game.fade=1;
return;
}
if( KEYDOWN(dkey.keys,DIK_RALT) )
{
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -