?? game_地圖.cpp
字號:
/*
[學VC、編游戲]
編著、程序設計:唐明理 2004.7
E-mail: cqtml@163.com
*/
#include "stdafx.h"
#include "game_地圖.h"
extern unsigned short dw[7][6];
gamemap:: gamemap(){}
gamemap::~gamemap(){}
void gamemap::initmap()
{ mapt=10,mapb=120;
maph=mapb-mapt;
mapl=WIDTH+6;
mapr=mapl+maph*WIDTH/HEIGHT;
mapw=mapr-mapl;
hScrDC0=CreateDC("DISPLAY", NULL, NULL, NULL);
SMAP =CreateCompatibleDC(hScrDC0);
mapbit=CreateCompatibleBitmap(hScrDC0,mapw,maph);
SelectObject(SMAP,mapbit);
pen0.CreatePen(PS_SOLID,1,RGB(0x0,0xf0,0xf0));
pen1.CreatePen(PS_SOLID,1,RGB(0x60,0x60,0x60));
movemap=0;
fls=0;
init();
}
void gamemap::exitmap()
{ DeleteObject(mapbit);
DeleteDC(SMAP);
DeleteObject(pen0);
DeleteObject(pen1);
DeleteDC(hScrDC0);
exit();
}
void gamemap::mlmap()//DX
{ if(movemap!=0)
{int gx=scrx%WIDTH,gy=scry%HEIGHT;
rect.left=gx, rect.right=WIDTH, rect.top=0, rect.bottom=HEIGHT;
DXSBack00->BltFast(0,0,DXSBack0,&rect,DDBLTFAST_WAIT);
rect.left=0, rect.right=gx, rect.top=0, rect.bottom=HEIGHT;
DXSBack00->BltFast(WIDTH-gx,0,DXSBack0,&rect,DDBLTFAST_WAIT);
rect.left=0, rect.right=WIDTH, rect.top=gy, rect.bottom=HEIGHT;
DXSBack1->BltFast(SCRW,SCRH,DXSBack00,&rect,DDBLTFAST_WAIT);
rect.left=0, rect.right=WIDTH, rect.top=0, rect.bottom=gy;
DXSBack1->BltFast(SCRW,SCRH+HEIGHT-gy,DXSBack00,&rect,DDBLTFAST_WAIT);
}
sort();
movemap=0;
}
void gamemap::getsmap()
{ char name[256];
sprintf(name,"%s%s",dir,mapbak);
loadbmp(name);
SelectObject(MemDC,bitmap);
//DX
HDC hdc;
if ( DXSBack0->GetDC(&hdc) != DD_OK) return;
BitBlt(hdc,0,0,WIDTH,HEIGHT,MemDC,0,0,SRCCOPY);
DXSBack0->ReleaseDC(hdc);
DeleteObject(bitmap);
int i,j;
COLORREF col=RGB(255,255,255);
for(i=0;i<mapw;i=i+mapw/SCRP0)
for(j=0;j<maph;j=j+maph/SCRP0)
TransparentBlt2
(SMAP,i,j,mapw/SCRP0,maph/SCRP0,
MemDC,0,0,WIDTH,HEIGHT,col);
int wi=WIDTH*SCRP0,he=HEIGHT*SCRP0;
for(int q=0;q<rs;q++)
{ if(man[q].lb==2)
{if(getpic("景",man[q].p,1)==FALSE) continue;
int x=(man[q].xix-w/4)*mapw;
int y=(man[q].xiy-h)*maph;
TransparentBlt2
(SMAP,x/wi,y/he,(w*mapw)/(wi*2/3),(h*maph)/(he*2/3),
MemDC,0,0,w,h,col);
}
}
}
void gamemap::movesmap(int x0,int y0)
{ int a=3;
if(edi==1) a=1;
if(x0>SCRWI-10)
{scrx=scrx+GX/a;if(scrx>WIDTH*(SCRP0-1)) scrx=WIDTH*(SCRP0-1);}
if(x0<10)
{scrx=scrx-GX/a;if(scrx<0) scrx=0;}
if(y0>SCRHE-10)
{scry=scry+GY/a;if(scry>HEIGHT*(SCRP0-1)) scry=HEIGHT*(SCRP0-1);}
if(y0<10)
{scry=scry-GY/a;if(scry<0) scry=0;}
movemap=1;
}
BOOL gamemap::dingweimap(int x,int y)
{ if(y>mapt&&y<mapb&&x>mapl&&x<mapr)
{scrx=(x-mapl)*WIDTH *SCRP0/mapw-mapw*2;
scry=(y-mapt)*HEIGHT*SCRP0/maph-maph*2;
scrx=(scrx/GX)*GX;
scry=(scry/GY)*GY;
if(scrx>WIDTH*(SCRP0-1)) scrx=WIDTH*(SCRP0-1);
if(scrx<0) scrx=0;
if(scry>HEIGHT*(SCRP0-1)) scry=HEIGHT*(SCRP0-1);
if(scry<0) scry=0;
return TRUE;
}
return FALSE;
}
void gamemap::smlmap(HDC dc0)
{ if(rs<1||SCRP0<1) return;
CDC* dc = CDC::FromHandle (dc0);
BitBlt(dc0,mapl,mapt,mapw,maph,SMAP,0,0,SRCCOPY);
CPen *old;
old=dc->SelectObject(&pen0);
int mapw0=mapw/SCRP0,maph0=maph/SCRP0-1;
int i,q;
int scrx0=mapl+(scrx*mapw)/(WIDTH*SCRP0);
int scry0=mapt+(scry*maph)/(HEIGHT*SCRP0);
dc->MoveTo(scrx0,scry0);
dc->LineTo(scrx0+mapw0,scry0);
dc->LineTo(scrx0+mapw0,scry0+maph0);
dc->LineTo(scrx0,scry0+maph0);
dc->LineTo(scrx0,scry0);
for(q=0;q<rs;q++)
{ COLORREF col=RGB(0x0,0x0,0x0);//
scrx0=(man[q].xix*mapw)/(WIDTH*SCRP0)-1;
scry0=(man[q].xiy*maph)/(HEIGHT*SCRP0)-2;
if(scrx0<1||scry0<1) continue;
if(man[q].jisu==0)
{mann=q;
if(fls==0){fls=1;col=RGB(0xf0,0xf0,0xf0);}
else {fls=0;col=RGB(0xf0,0x0,0x0);}
dc->SetPixel(mapl+scrx0+1,mapt+scry0, col);
dc->SetPixel(mapl+scrx0+1,mapt+scry0+1,col);
}
if(man[q].lb==2) continue;
dc->SetPixel(mapl+scrx0,mapt+scry0, col);
dc->SetPixel(mapl+scrx0,mapt+scry0+1,col);
}
i=mann;
dc->SelectObject(old);
if(man[i].pk<1)
{ CDC::DeleteTempMap( );
return;
}
int x,y,x0,y0;
x=man[i].ph[0].x*GX;
y=man[i].ph[0].y*GY;
x0=mapl+(x*mapw)/(WIDTH*SCRP0);
y0=mapt+(y*maph)/(HEIGHT*SCRP0);
old=dc->SelectObject(&pen1);
for (int j=1;j<man[i].pk;j++)
{dc->MoveTo(x0,y0);
x=man[i].ph[j].x*GX;
y=man[i].ph[j].y*GY;
x0=mapl+(x*mapw)/(WIDTH*SCRP0);
y0=mapt+(y*maph)/(HEIGHT*SCRP0);
dc->LineTo(x0,y0);
}
x0=mapl+(man[i].fx*mapw)/(WIDTH*SCRP0);
y0=mapt+(man[i].fy*maph)/(HEIGHT*SCRP0);
dc->LineTo(x0,y0);
dc->SelectObject(old);
CDC::DeleteTempMap( );
}
int gamemap::leftdown(HDC hdc,int x,int y)
{ int fidtim=0;
if(x>0&&x<WIDTH&&y>0&&y<HEIGHT&&edi==0)
{int i=mann;
man[i].x0=x-2+scrx;
man[i].y0=y-10+scry;
man[i].p=man[i].m1-1;
}
if(dingweimap(x,y)==TRUE) smlmap(hdc);
return fidtim;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -