2D游戏 不能左右移动画面好的2d网游么

查看: 20|回复: 3
UID3218251积分78主题帖子精华0注册时间最后登录在线时间10 小时
LV 3 下士, 积分 78, 距离下一级还需 22 积分
金币0 银币446 战功0
22:54 上传
22:54 上传
UID3218251积分78主题帖子精华0注册时间最后登录在线时间10 小时
LV 3 下士, 积分 78, 距离下一级还需 22 积分
金币0 银币446 战功0
周年奖励的箱子么到现在还不发,游戏么BUG满天飞,你们还打不打算让人玩了
UID3218251积分78主题帖子精华0注册时间最后登录在线时间10 小时
LV 3 下士, 积分 78, 距离下一级还需 22 积分
金币0 银币446 战功0
22:56 上传
UID1906446积分34256主题帖子精华0注册时间最后登录在线时间1959 小时
金币5 银币6390 战功0
很高兴为您服 务。
如果您使用了过期的第三方插件,请您使用以下方法试一下。
1、请您退出游戏后,卸载第三方插件,并且找到游戏根目录以下文件。删除profile/下的所有文件夹、res_mods以及preferences文件试一试。
2、建议您下载最新客户端重新安装尝试一下。
感谢您对游戏的支持。
客服电话:010-
客服邮箱:igame_
欢迎关注空中网客服微信:kongzhong_KFZX
您好!因您的帖子中含有个人账号信息。为了保护您个人信息安全。我们将对您的帖子进行编辑。请您谅解。2354人阅读
Cocos2d-x(11)
& & & &在横版游戏中,实现屏幕随精灵移动而移动,要实现这个,首先要明白这个问题中的变与不变:
& & & && & & &不变:地图位置;
& & & && & & &变:精灵的位置、屏幕(或理解为所在图层)的位置;
& & & &故,说是滚动地图,其实是图层滚动;
& & & &从不变入手,首先要知道地图(CCTMXTileMap)的两个方法:
& & & && & & &1、map-&getMapSize():地图的图块数
& & && & & &&&2、map-&getTileSize():每一个图块的宽高
& & & &再而分析变:
& & & &精灵先移动,屏幕根据精灵移动的坐标去调整;
& & & && & & && & & &
& & & &总体分析前,先计算如下几个数值:
& & & && & & &地图宽度:tw=tilemap-&getMapSize().width*tilemap-&getTileSize().
& & & && & & &地图高度:th=tilemap-&getMapSize().height*tilemap-&getTileSize().
& & & && & & &屏幕宽度:ww=winsize.
& & && & & &&&屏幕高度:wh=winsize.
& & && & & &&&精灵坐标:x,y;
& & & &总体分析:首先准确判定精灵移动后的坐标,因为我们大部分游戏中的精灵都是一个图片,不是一个点,精灵的坐标到其图片的左右边和上下边是有距离的,分别为上图(此图出自时空猎人,其代码实现与本文无关)中的A边和B边,所以,整个精灵的水平坐标显示是有范围的(A&=x&=tw-A),而精灵的垂直坐标是同理的。这时,精灵坐标是能确定的,接下来是屏幕滚动了。屏幕滚动显然有以下三种情况:1、x&=ww/2;
2、ww/2&x&=tw-ww/2;3、tw-ww/2&x;在1情况,屏幕位置为(ww/2,wh/2);在2中,屏幕位置为(x,wh/2);在3中,屏幕位置为(tw-ww/2,wh/2);有很多人可能已经发现,屏幕垂直坐标是不用去改变的,因为横版游戏在垂直上是没有滚动的(屏幕高度=地图高度,当然这里是指大部分)。最后,将屏幕中点(ww/2,wh/2)减去上面三种情况的屏幕位置点,得出滚动的距离,将距离值以坐标形式代入setPosition()中。
完整代码如下:
void GameLayer::update(float dt)
this-&_hero-&updateDesiredPosition(dt);
//设置英雄位置
float posX=MIN(this-&_tilemp-&getMapSize().width*this-&_tilemp-&getTileSize().width-this-&_hero-&_centerToSides,MAX(this-&_hero-&_centerToSides,this-&_hero-&_desiredPosition.x));
float posY=MIN(3*this-&_tilemp-&getTileSize().height+this-&_hero-&_centerToBottom,MAX(_hero-&_centerToBottom,_hero-&_desiredPosition.y));
this-&_hero-&setPosition(ccp(posX,posY));
//地图滚动
CCSize winSize=CCDirector::sharedDirector()-&getWinSize();
int x=MAX(_hero-&getPositionX(),winSize.width/2);
int y=MAX(_hero-&getPositionY(),winSize.height/2);
x=MIN(x,(this-&_tilemp-&getMapSize().width*this-&_tilemp-&getTileSize().width)-winSize.width/2);
CCPoint actualPosition=ccp(x,y);
CCPoint centerOfView=ccp(winSize.width/2,winSize.height/2);
CCPoint viewPoint=ccpSub(centerOfView,actualPosition);
this-&setPosition(viewPoint);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:62538次
排名:千里之外
原创:24篇
转载:11篇
评论:15条
(1)(1)(1)(1)(4)(7)(5)(8)(1)(1)(2)(2)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'查看: 1242|回复: 4
有点难。一个2D网络游戏框架(客户端)鼠标不能移动出游戏边框。怎么修改?
阅读权限10
在线时间25 小时
当前用户组为 梦之始当前积分为 34, 升到下一级还需要 16 点。
主题精华积分
本帖最后由 skyddr8511 于
12:56 编辑
我学习修改一个游戏客户端代码,发现鼠标不能移除游戏边框以外,仔细阅读代码。
发现好像是引擎的问题。(鼠标的协作模式已经修改,出现的问题是,在游戏里面移动鼠标,桌面的鼠标也会跟着移动)。请看代码这种是什么引擎?
360截图45500.jpg (87.13 KB, 下载次数: 0)
12:55 上传
下面是详细源代码
class DXC_ddraw&&
{
public:& & & &
& & & & void * operator new (size_t size)
& & & & {
& & & & & & & & return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);& & & &
& & & & };& & & &
& & & & void operator delete(void * mem)
& & & & {
& & & & & & & & HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, mem); & & & & & & & &
& & & & };
& & & & DXC_ddraw();
& & & & virtual ~DXC_ddraw();
& & & & BOOL bInit(HWND hWnd,BOOL bWindowed);
& & & & void ColorTransferRGB(COLORREF fcolor, int * iR, int * iG, int * iB);
& & & & HRESULT InitFlipToGDI(HWND hWnd);
& & & & void ChangeDisplayMode(HWND hWnd);
& & & & void DrawText(LPRECT pRect, char * pString, COLORREF rgb);
& & & & void _ReleaseBackBufferDC();
& & & & void _GetBackBufferDC();
& & & & void TextOut(int x, int y, char const * cStr, COLORREF rgb);
& & & & // added by jcfly
& & & & void DrawText(char* cStr, LPRECT lpRect, COLORREF rgb,&&UINT uFormat = DT_TOP | DT_LEFT | DT_WORDBREAK);
& & & &
& & & & void _TestPixelFormat();
& & & & DWORD _dwColorMatch(IDirectDrawSurface7 * pdds4, WORD wColorKey);
& & & & DWORD _dwColorMatch(IDirectDrawSurface7 * pdds4, COLORREF rgb);
& & & & long _CalcMinValue(int iS, int iD, char cMode);
& & & & long _CalcMaxValue(int iS, int iD, char cMode, char cMethod, double dAlpha);
& & & & HRESULT iSetColorKey(IDirectDrawSurface7 * pdds4, WORD wColorKey);
& & & & void PutPixel(short sX, short sY, WORD wR, WORD wG, WORD wB);
& & & & void DrawShadowBox(short sX, short sY, short dX, short dY, int iType = 0);
& & & & void ClearBackB4();
& & & & IDirectDrawSurface7 * pCreateOffScreenSurface(WORD iSzX, WORD iSzY);
& & & & HRESULT iSetColorKey(IDirectDrawSurface7 * pdds4, COLORREF rgb);
& & & & HRESULT iFlip();
& & & & bool Screenshot(LPCTSTR FileName, LPDIRECTDRAWSURFACE7 lpDDS);
& & & &
& & & & long& & m_lTransG100[64][64], m_lTransRB100[64][64];
& & & & long& & m_lTransG70[64][64], m_lTransRB70[64][64];
& & & & long& & m_lTransG50[64][64], m_lTransRB50[64][64];
& & & & long& & m_lTransG25[64][64], m_lTransRB25[64][64];
& & & & long& & m_lTransG2[64][64], m_lTransRB2[64][64];
& & & & long& & m_lFadeG[64][64],&&m_lFadeRB[64][64];
& & & & BOOL m_bFullM
& & & & LPDIRECTDRAW7& & & & & & & &&&m_lpDD4;
& & & & LPDIRECTDRAWSURFACE7 m_lpFrontB4, m_lpBackB4, m_lpBackB4
& & & & LPDIRECTDRAWSURFACE7 m_lpPDBGS;// Pre-Draw Background Surface
& & & & WORD * m_pBackB4A
& & & & RECT&&m_rcClipArea, m_rcF
& & & & short&&m_sBackB4P
& & & & char& &m_cPixelF
& & & & HDC m_hDC;
& & & & HFONT m_hFontInU
};
复制代码
// DXC_ddraw.cpp: implementation of the DXC_ddraw class.
//
//////////////////////////////////////////////////////////////////////
#include &string.h&
#include &objbase.h&
#include &DXC_ddraw.h&
#include &stdafx.h&
extern HWND G_hEditW
extern HWND G_hW
#ifdef DEF_HTMLCOMMOM& & & & //& & & & Html 促捞倔肺弊 何盒..
& & & & extern HWND G_hInternetW
#endif
extern long& & G_lTransG100[64][64], G_lTransRB100[64][64];
extern long& & G_lTransG70[64][64], G_lTransRB70[64][64];
extern long& & G_lTransG50[64][64], G_lTransRB50[64][64];
extern long& & G_lTransG25[64][64], G_lTransRB25[64][64];
extern long& & G_lTransG2[64][64], G_lTransRB2[64][64];
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DXC_ddraw::DXC_ddraw()
{
& & & & m_lpFrontB4& & & & & & & & = NULL;
& & & & m_lpDD4& & & & & & & & & & & & = NULL;
& & & & m_lpPDBGS& & & & & & & & = NULL;
& & & & m_lpBackB4flip& & & & = NULL;
& & & & m_cPixelFormat& & & & = 0;
#ifdef _DEBUG
& & & & m_bFullMode& & & & & & & & = FALSE;
#else
& & & & m_bFullMode& & & & & & & & = TRUE;
#endif
}
DXC_ddraw::~DXC_ddraw()
{
& & & & if (m_hFontInUse != NULL) DeleteObject(m_hFontInUse);
& & & & if (m_lpBackB4flip != NULL) m_lpBackB4flip-&Release();
& & & & if (m_lpBackB4 != NULL) m_lpBackB4-&Release();
& & & & if (m_lpFrontB4 != NULL) m_lpFrontB4-&Release();
& & & & if (m_bFullMode == TRUE)
& & & & {
& & & & & & & & if (m_lpDD4 != NULL) m_lpDD4-&RestoreDisplayMode();
& & & & }
& & & & if (m_lpDD4 != NULL) m_lpDD4-&Release();
}
BOOL DXC_ddraw::bInit(HWND hWnd,BOOL bWindowed)
{
HRESULT& && &&&ddV
DDSURFACEDESC2
int& && && && &iS, iD;
& & & &&&m_bFullMode = ! bW
& & & & SetRect(&m_rcClipArea, 0,0, 640, 480);
& & & & ddVal = DirectDrawCreateEx(NULL, (VOID**)&m_lpDD4, IID_IDirectDraw7, NULL);
& & if (ddVal != DD_OK) return FALSE;
& & & & if( m_bFullMode == TRUE )
& & & & {
& & & & & & & & DDSCAPS2& && &
& & & & & & & & // 傈眉拳搁 葛靛捞促.
& & & & & & & & ddVal = m_lpDD4-&SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & & ddVal = m_lpDD4-&SetDisplayMode(WIDTH, HEIGHT, 16,0,0);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & & // 橇沸飘 滚欺 积己
& & & & & & & & memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
& & & & & & & & ddsd.dwSize = sizeof( ddsd );
& & & & & & & & ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
& & & & & & & & ddsd.dwBackBufferCount = 1;//2; //v1.3
& & & & & & & & ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
& & & & & & & &
& & & & & & & & ddVal = m_lpDD4-&CreateSurface(&ddsd, &m_lpFrontB4, NULL);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & & ZeroMemory(&ddscaps, sizeof(ddscaps));
& & & & & & & & ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
& & & & & & & & ddVal = m_lpFrontB4-&GetAttachedSurface(&ddscaps, &m_lpBackB4flip);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & & SetRect(&m_rcFlipping, 0, 0, WIDTH, HEIGHT); // our fictitious sprite bitmap is
& & & & }
& & & & else
& & & & {
& & & & & & & & // 扩档快 葛靛捞促.
& & & & & & & & int cx = GetSystemMetrics(SM_CXFULLSCREEN);
& & & & & & & & int cy = GetSystemMetrics(SM_CYFULLSCREEN);
& & & & & & & & ddVal = m_lpDD4-&SetCooperativeLevel(hWnd, DDSCL_NORMAL);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & &
& & & & & & & & cx = cx/2;
& & & & & & & & cy = cy/2;
& & & & & & & & if(cy&280) cy -= 40;
& & & & & & & & SetWindowPos( hWnd, HWND_TOP, cx-WIDTH /2 , cy-HEIGHT /2, WIDTH,HEIGHT, SWP_SHOWWINDOW);
& & & & & & & & // 橇沸飘 滚欺 积己
& & & & & & & & memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
& & & & & & & & ddsd.dwSize = sizeof( ddsd );
& & & & & & & & ddsd.dwFlags = DDSD_CAPS;
& & & & & & & & //ddsd.dwBackBufferCount = 0;
& & & & & & & & ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
& & & & & & & &
& & & & & & & & ddVal = m_lpDD4-&CreateSurface(&ddsd, &m_lpFrontB4, NULL);
& & & & & & & & if (ddVal != DD_OK) return FALSE;
& & & & & & & & SetRect(&m_rcFlipping, cx-WIDTH /2 , cy-HEIGHT/2, cx+WIDTH /2, cy+HEIGHT/2); // our fictitious sprite bitmap is
& & & & InitFlipToGDI(hWnd);
& & & & // 归滚欺 积己
& & & & m_lpBackB4 = pCreateOffScreenSurface(WIDTH,HEIGHT);
& & & & if (m_lpBackB4 == NULL) return FALSE;
& & & & // Pre-draw background surface 滚欺 积己
& & & & m_lpPDBGS = pCreateOffScreenSurface(WIDTH+32,HEIGHT+32);
& & & & if (m_lpPDBGS == NULL) return FALSE;
& & & & // 归滚欺狼 林家客 乔摹甫 掘绢柯促.
& & & & ddsd.dwSize = sizeof(ddsd);
& & & & if (m_lpBackB4-&Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) return FALSE;
& & & & m_pBackB4Addr& && &&&= (WORD *)ddsd.lpS
& & & & m_sBackB4Pitch& && & = (short)ddsd.lPitch && 1;
& & & & m_lpBackB4-&Unlock(NULL);
& & & & // 侨伎备炼甫 舅酒郴 拿矾 抛捞喉阑 积己茄促.
& & & & _TestPixelFormat();
& & & & for (iS = 0; iS & 64; iS++)
& & & & for (iD = 0; iD & 64; iD++) {
& & & & & & & & m_lTransRB100[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 1.0f);
& & & & & & & & m_lTransG100[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 1.0f);
& & & & & & & & m_lTransRB70[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.7f);
& & & & & & & & m_lTransG70[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.7f);
& & & & & & & &
& & & & & & & & m_lTransRB50[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.5f);
& & & & & & & & m_lTransG50[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.5f);
& & & & & & & & m_lTransRB25[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.25f);
& & & & & & & & m_lTransG25[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.25f);
& & & & & & & & m_lTransRB2[iD][iS] = _CalcMaxValue(iS, iD, 'R', 2, 1.0f);
& & & & & & & & m_lTransG2[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 2, 1.0f);
& & & & & & & & m_lFadeRB[iD][iS]&&= _CalcMinValue(iS, iD, 'R');
& & & & & & & & m_lFadeG[iD][iS]& &= _CalcMinValue(iS, iD, 'G');
& & & & & & & & G_lTransRB100[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 1.0f);
& & & & & & & & G_lTransG100[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 1.0f);
& & & & & & & & G_lTransRB70[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.7f);
& & & & & & & & G_lTransG70[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.7f);
& & & & & & & &
& & & & & & & & G_lTransRB50[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.5f);
& & & & & & & & G_lTransG50[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.5f);
& & & & & & & & G_lTransRB25[iD][iS] = _CalcMaxValue(iS, iD, 'R', 1, 0.25f);
& & & & & & & & G_lTransG25[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 1, 0.25f);
& & & & & & & & G_lTransRB2[iD][iS] = _CalcMaxValue(iS, iD, 'R', 2, 1.0f);
& & & & & & & & G_lTransG2[iD][iS]&&= _CalcMaxValue(iS, iD, 'G', 2, 1.0f);
& & & & }
& & & & m_hFontInUse = NULL;& & & &
#if DEF_LANGUAGE == 1& & & & // 攫绢:Taiwan
& & & & m_hFontInUse = CreateFont(12,0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, &MingLiu&) ;
#endif
#if DEF_LANGUAGE == 2& & & & // 攫绢:Chinese
& & & & m_hFontInUse = CreateFont(12,0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, &MingLiu&) ;
#endif
#if DEF_LANGUAGE == 3& & & & // 攫绢:Korean
& & & & m_hFontInUse = CreateFont(12,0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGUL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, &官帕&) ;
#endif
#if DEF_LANGUAGE == 4& & & & // 攫绢:English
& & & & m_hFontInUse = CreateFont(16,0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, &Comic Sans MS&) ;
#endif
#if DEF_LANGUAGE == 5& & & & // 攫绢:Japanese
& & & & m_hFontInUse = CreateFont(12,0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, &MS PGothic&) ;
#endif
& & & & m_hDC = NULL;
& & & & & & & &
& & & & return TRUE;
}
HRESULT DXC_ddraw::iFlip()
{
& & & & HRESULT ddV
& & & &
& & & & if( m_bFullMode )
& & & & {
#ifdef DEF_USING_WIN_IME
& & & & & & & & ddVal = m_lpFrontB4-&Blt( NULL, m_lpBackB4, NULL, DDBLT_WAIT, NULL );
& & & & & & & & if (G_hEditWnd != NULL) {
& & & & & & & & & & & & if (ddVal != DDERR_SURFACELOST) m_lpDD4-&FlipToGDISurface();
& & & & & & & & }
#else
#ifdef DEF_HTMLCOMMOM
& & & & & & & & if( G_hInternetWnd != NULL ) {
& & & & & & & & & & & & ddVal = m_lpFrontB4-&Blt( NULL, m_lpBackB4, NULL, DDBLT_WAIT, NULL );
& & & & & & & & & & & & m_lpDD4-&FlipToGDISurface();
& & & & & & & & }
& & & & & & & & else {
& & & & & & & & & & & & ddVal = m_lpBackB4flip-&BltFast( 0, 0, m_lpBackB4, &m_rcFlipping, DDBLTFAST_NOCOLORKEY); // | DDBLTFAST_WAIT);
& & & & & & & & & & & & ddVal = m_lpFrontB4-&Flip(m_lpBackB4flip, DDFLIP_WAIT);
& & & & & & & & }
#else
& & & & & & & & ddVal = m_lpBackB4flip-&BltFast( 0, 0, m_lpBackB4, &m_rcFlipping, DDBLTFAST_NOCOLORKEY); // | DDBLTFAST_WAIT);
& & & & & & & & ddVal = m_lpFrontB4-&Flip(m_lpBackB4flip, DDFLIP_WAIT);
#endif
#endif
& & & & }
& & & & else
& & & & {
& & & & & & & & //SetRect( &m_rcFlipping, 0, 0,
);
& & & & & & & & ddVal = m_lpFrontB4-&Blt(&m_rcFlipping, m_lpBackB4, NULL, DDBLT_WAIT, NULL);
& & & & }
& & & & if (ddVal == DDERR_SURFACELOST) {
& & & & & & & & DDSURFACEDESC2 ddsd2;
& & & & & & & & // 辑其捞胶啊 颊角登菌促. 汗备茄促.
& & & & & & & & m_lpFrontB4-&Restore();
& & & & & & & & m_lpBackB4-&Restore();
& & & & & & & &
& & & & & & & & // 归滚欺狼 林家甫 掘绢柯促.
& & & & & & & & ddsd2.dwSize = sizeof(ddsd2);
& & & & & & & & if (m_lpBackB4-&Lock(NULL, &ddsd2, DDLOCK_WAIT, NULL) != DD_OK) return FALSE;
& & & & & & & & m_pBackB4Addr&&= (WORD *)ddsd2.lpS
& & & & & & & & m_lpBackB4-&Unlock(NULL);
& & & & & & & & return DDERR_SURFACELOST;
& & & & }
& & & & return DD_OK;
}
void DXC_ddraw::ChangeDisplayMode(HWND hWnd)
{
& & & & HRESULT& && &&&ddV
& & & & DDSURFACEDESC2
& & & & if (m_lpBackB4flip != NULL)
& & & & {
& & & & & & & & m_lpBackB4flip-&Release();
& & & & & & & & m_lpBackB4flip = NULL;
& & & & }
& & & & if (m_lpBackB4 != NULL) m_lpBackB4-&Release();
& & & & if (m_lpFrontB4 != NULL) m_lpFrontB4-&Release();
& & & & if (m_lpDD4 != NULL)
& & & & {
& & & & & & & & if (m_bFullMode == TRUE) m_lpDD4-&RestoreDisplayMode();
& & & & }
& & & & if( m_bFullMode == TRUE )
& & & & {
& & & & & & & & int cx = GetSystemMetrics(SM_CXFULLSCREEN);
& & & & & & & & int cy = GetSystemMetrics(SM_CYFULLSCREEN);
& & & & & & & & ddVal = m_lpDD4-&SetCooperativeLevel(hWnd, DDSCL_NORMAL);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & cx = cx/2;
& & & & & & & & cy = cy/2;
& & & & & & & & if(cy&280) cy -= 40;
& & & & & & & & SetWindowPos( hWnd, NULL, cx-320, cy-240, 640, 480, SWP_SHOWWINDOW);
& & & & & & & & // 橇沸飘 滚欺 积己
& & & & & & & & memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
& & & & & & & & ddsd.dwSize = sizeof( ddsd );
& & & & & & & & ddsd.dwFlags = DDSD_CAPS;
& & & & & & & & //ddsd.dwBackBufferCount = 0;
& & & & & & & & ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
& & & & & & & &
& & & & & & & & ddVal = m_lpDD4-&CreateSurface(&ddsd, &m_lpFrontB4, NULL);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & SetRect(&m_rcFlipping, cx-320, cy-240, cx+320, cy+240); // our fictitious sprite bitmap is
& & & & & & & & m_bFullMode = FALSE;
& & & & }
& & & & else
& & & & {
& & & & & & & & DDSCAPS2& && &
& & & & & & & & // 傈眉拳搁 葛靛捞促.
& & & & & & & & ddVal = m_lpDD4-&SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & ddVal = m_lpDD4-&SetDisplayMode(640, 480, 16,0,0);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & // 橇沸飘 滚欺 积己
& & & & & & & & memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
& & & & & & & & ddsd.dwSize = sizeof( ddsd );
& & & & & & & & ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
& & & & & & & & ddsd.dwBackBufferCount = 1;//2; //v1.3
& & & & & & & & ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
& & & & & & & &
& & & & & & & & ddVal = m_lpDD4-&CreateSurface(&ddsd, &m_lpFrontB4, NULL);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & ZeroMemory(&ddscaps, sizeof(ddscaps));
& & & & & & & & ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
& & & & & & & & ddVal = m_lpFrontB4-&GetAttachedSurface(&ddscaps, &m_lpBackB4flip);
& & & & & & & & if (ddVal != DD_OK)
& & & & & & & & SetRect(&m_rcFlipping, 0, 0, 640, 480); // our fictitious sprite bitmap is
& & & & & & & & m_bFullMode = TRUE;
& & & & }
& & & & InitFlipToGDI(hWnd);
& & & & // 归滚欺 积己
& & & & m_lpBackB4 = pCreateOffScreenSurface(640, 480);
& & & & if (m_lpBackB4 == NULL)
& & & & // Pre-draw background surface 滚欺 积己
& & & & m_lpPDBGS = pCreateOffScreenSurface(640+32, 480+32);
& & & & if (m_lpPDBGS == NULL)
& & & & // 归滚欺狼 林家客 乔摹甫 掘绢柯促.
& & & & ddsd.dwSize = sizeof(ddsd);
& & & & if (m_lpBackB4-&Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK)
& & & & m_pBackB4Addr& && &&&= (WORD *)ddsd.lpS
& & & & m_sBackB4Pitch& && & = (short)ddsd.lPitch && 1;
& & & & m_lpBackB4-&Unlock(NULL);
}
IDirectDrawSurface7 * DXC_ddraw::pCreateOffScreenSurface(WORD wSzX, WORD wSzY)
{
& & & & DDSURFACEDESC2
& & & & IDirectDrawSurface7 * pdds4;
& & ZeroMemory(&ddsd, sizeof(ddsd));
& & & & if ((wSzX % 4) != 0) wSzX += 4 - (wSzX % 4);
& & ddsd.dwSize&&= sizeof(ddsd);
& & ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
& & & & ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
& & & & ddsd.dwWidth&&= (DWORD)wSzX;
& & ddsd.dwHeight = (DWORD)wSzY;
& & if (m_lpDD4-&CreateSurface(&ddsd, &pdds4, NULL) != DD_OK) return NULL;
& & & & return pdds4;
}
HRESULT DXC_ddraw::iSetColorKey(IDirectDrawSurface7 * pdds4, COLORREF rgb)
{
DDCOLORKEY
& & & & ddck.dwColorSpaceLowValue&&= _dwColorMatch(pdds4, rgb);
& & ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowV
& & return pdds4-&SetColorKey(DDCKEY_SRCBLT, &ddck);
}
HRESULT DXC_ddraw::iSetColorKey(IDirectDrawSurface7 * pdds4, WORD wColorKey)
{
DDCOLORKEY
& & & & ddck.dwColorSpaceLowValue&&= _dwColorMatch(pdds4, wColorKey);
& & ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowV
& & return pdds4-&SetColorKey(DDCKEY_SRCBLT, &ddck);
}
DWORD DXC_ddraw::_dwColorMatch(IDirectDrawSurface7 * pdds4, COLORREF rgb)
{
COLORREF rgbT;
DWORD dw = CLR_INVALID;
DDSURFACEDESC2 ddsd2;
& & if (rgb != CLR_INVALID && pdds4-&GetDC(&hdc) == DD_OK)
& & {
& && &&&rgbT = GetPixel(hdc, 0, 0);& && && && &
& && &&&SetPixel(hdc, 0, 0, rgb);& && && && && &
& && &&&pdds4-&ReleaseDC(hdc);
& & }
& & ddsd2.dwSize = sizeof(ddsd2);
& & while ((hres = pdds4-&Lock(NULL, &ddsd2, 0, NULL)) == DDERR_WASSTILLDRAWING);
& & if (hres == DD_OK)
& & {
& && &&&dw&&= *(DWORD *)ddsd2.lpS& && && && && && && &
& && &&&dw &= (1 && ddsd2.ddpfPixelFormat.dwRGBBitCount)-1;&&
& && &&&pdds4-&Unlock(NULL);
& & }
& & if (rgb != CLR_INVALID && pdds4-&GetDC(&hdc) == DD_OK)
& & {
& && &&&SetPixel(hdc, 0, 0, rgbT);
& && &&&pdds4-&ReleaseDC(hdc);
& & }
DWORD DXC_ddraw::_dwColorMatch(IDirectDrawSurface7 * pdds4, WORD wColorKey)
{
DWORD dw = CLR_INVALID, *
DDSURFACEDESC2 ddsd2;
HRESULT
& &
& & ddsd2.dwSize = sizeof(ddsd2);
& & while ((hres = pdds4-&Lock(NULL, &ddsd2, 0, NULL)) == DDERR_WASSTILLDRAWING);
& & if (hres == DD_OK)
& & {
& && &&&dwp = (DWORD *)ddsd2.lpS
& & & & & & & & *dwp = (DWORD)wColorK
& & & & & & & & dw&&= *(DWORD *)ddsd2.lpS& && && && && && && &
& && &&&dw &= (1 && ddsd2.ddpfPixelFormat.dwRGBBitCount)-1;&&
& && &&&pdds4-&Unlock(NULL);
& & }
void DXC_ddraw::TextOut(int x, int y, char const * cStr, COLORREF rgb)
{
& & & & SetTextColor(m_hDC, rgb );
& & & & ::TextOut(m_hDC, x, y, cStr, strlen(cStr));
}
// added by jcfly
void DXC_ddraw::DrawText(char * cStr, LPRECT lpRect, COLORREF rgb, UINT uFormat)
{
& & & & _GetBackBufferDC();
& & & & SetTextColor(m_hDC, rgb);
& & & & ::DrawText(m_hDC, cStr, -1, lpRect, uFormat);
& & & & _ReleaseBackBufferDC();
}
void DXC_ddraw::_TestPixelFormat()
{
DDSURFACEDESC2 ddSurfaceDesc2;
HRESULT& && & hR
& & & & ZeroMemory(&ddSurfaceDesc2, sizeof(DDSURFACEDESC2));
& & & & ddSurfaceDesc2.dwSize&&= sizeof(ddSurfaceDesc2);
& & & & ddSurfaceDesc2.dwFlags = DDSD_PIXELFORMAT;
& & & & hResult& && && && && & = m_lpBackB4-&GetSurfaceDesc(&ddSurfaceDesc2);
& & & & if (hResult == DD_OK)
& & & & {
& & & && & if (ddSurfaceDesc2.ddpfPixelFormat.dwRBitMask == 0x) {
& & & & & & & && & m_cPixelFormat = 1;
& & & & & & & && &// RGB 5:6:5
& & & && & }
& & & && & if (ddSurfaceDesc2.ddpfPixelFormat.dwRBitMask == 0x00007C00) {
& & & & & & & && & m_cPixelFormat = 2;
& & & & & & & && &// RGB 5:5:5
& & & && & }
& & & && & if (ddSurfaceDesc2.ddpfPixelFormat.dwRBitMask == 0x0000001F) {
& & & & & & & && & m_cPixelFormat = 3;
& & & & & & & && &// BGR 5:6:5
& & & && & }
& & & & }
}
long DXC_ddraw::_CalcMaxValue(int iS, int iD, char cMode, char cMethod, double dAlpha)
{
& & & & switch (cMethod) {
& & & & case 1:
& & & & & & & & dTmp = (double)iS;
& & & & & & & & dTmp = dTmp * dA
& & & & & & & & iS = (int)dT
& & & & & & & & Sum = (iS) + (iD);
& & & & & & & & if (Sum & iD) Sum = iD;
& & & & & & & &
& & & & case 2:
& & & & & & & & Sum = (iS + iD) / 2;
& & & & & & & &
& & & & }
& & & & switch (cMode) {
& & & & case 'G':
& & & & & & & & switch (m_cPixelFormat) {
& & & & & & & & case 1:
& & & & & & & & & & & & if (Sum &= 64) Sum = 63; //v1.3
& & & & & & & & & & & &
& & & & & & & & case 2:
& & & & & & & & & & & & if (Sum &= 32) Sum = 31;
& & & & & & & & & & & &
& & & & & & & & }
& & & & & & & &
& & & &
& & & & default:
& & & & & & & & if (Sum &= 32) Sum = 31;
& & & & & & & &
& & & & }
& & & & return S
}
long DXC_ddraw::_CalcMinValue(int iS, int iD, char cMode)
{
& & & & Sum = iD - iS;
& & & & if (Sum & 0) Sum = 0;
& & & & switch (cMode) {
& & & & case 'G':
& & & & & & & & switch (m_cPixelFormat) {
& & & & & & & & case 1:
& & & & & & & & & & & & if (Sum &= 64) Sum = 63; //v1.3
& & & & & & & & & & & &
& & & & & & & & case 2:
& & & & & & & & & & & & if (Sum &= 32) Sum = 31;
& & & & & & & & & & & &
& & & & & & & & }
& & & & & & & &
& & & &
& & & & default:
& & & & & & & & if (Sum &= 32) Sum = 31;
& & & & & & & &
& & & & }
& & & & return S
}
void DXC_ddraw::ClearBackB4()
{
& & & & DDSURFACEDESC2 ddsd2;& & & &
& & & & ddsd2.dwSize = sizeof(ddsd2);
& & & & if (m_lpBackB4-&Lock(NULL, &ddsd2, DDLOCK_WAIT, NULL) != DD_OK)
& & & & memset((char *)ddsd2.lpSurface, 0, ddsd2.lPitch * 480);
& & & & m_lpBackB4-&Unlock(NULL);
}
void DXC_ddraw::DrawShadowBox(short sX, short sY, short dX, short dY, int iType)
{
& & & & WORD * pDst, wV
& & & & int ix,
& & & & pDst = (WORD *)m_pBackB4Addr + sX + ((sY)*m_sBackB4Pitch);
& & & & if (iType == 0) {
& & & & & & & & switch (m_cPixelFormat) {
& & & & & & & & case 1:
& & & & & & & & & & & & for (iy = 0; iy &= (dY - sY); iy++) {
& & & & & & & & & & & & & & & & for (ix = 0; ix &= (dX - sX); ix++)
& & & & & & & & & & & & & & & & & & & & pDst[ix] = (pDst[ix] & 0xf7de) && 1; & & & &
& & & & & & & & & & & &
& & & & & & & & & & & & & & & & pDst += m_sBackB4P
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & case 2:
& & & & & & & & & & & & for (iy = 0; iy &= (dY - sY); iy++) {
& & & & & & & & & & & & & & & & for (ix = 0; ix &= (dX - sX); ix++)
& & & & & & & & & & & & & & & & & & & & pDst[ix] = (pDst[ix] & 0x7bde) && 1;
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & pDst += m_sBackB4P
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & }
& & & & }
& & & & else
& & & & {
& & & & & & & & switch (iType) {
& & & & & & & & case 1:
& & & & & & & & & & & & if (m_cPixelFormat == 1)
& & & & & & & & & & & & & & & &&&wValue = 0x38e7;
& & & & & & & & & & & & else wValue = 0x1ce7;
& & & & & & & & & & & &
& & & & & & & & case 2:
& & & & & & & & & & & & if (m_cPixelFormat == 1)
& & & & & & & & & & & & & & & &&&wValue = 0x1863;
& & & & & & & & & & & & else wValue = 0xc63;
& & & & & & & & & & & &
& & & & & & & & }
& & & & & & & &
& & & & & & & & for (iy = 0; iy &= (dY - sY); iy++) {
& & & & & & & & & & & & for (ix = 0; ix &= (dX - sX); ix++)
& & & & & & & & & & & & & & & & pDst[ix] = wV & & & &
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & pDst += m_sBackB4P
& & & & & & & & }
& & & & }
}
void DXC_ddraw::PutPixel(short sX, short sY, WORD wR, WORD wG, WORD wB)
{
& & & & if ((sX & 0) || (sY & 0) || (sX & 639) || (sY & 479))
& & & & pDst = (WORD *)m_pBackB4Addr + sX + ((sY)*m_sBackB4Pitch);
& & & &
& & & & switch (m_cPixelFormat) {
& & & & case 1:
& & & & & & & & *pDst = (WORD)( ((wR&&3)&&11) | ((wG&&2)&&5) | (wB&&3) );
& & & & & & & & //*pDst = (WORD)((wR&&11) | (wG&&5) | wB);
& & & & & & & &
& & & & case 2:
& & & & & & & & *pDst = (WORD)( ((wR&&3)&&10) | ((wG&&3)&&5) | (wB&&3) );
& & & & & & & & //*pDst = (WORD)((wR&&10) | (wG&&5) | wB);
& & & & & & & &
& & & & }
}
void DXC_ddraw::_GetBackBufferDC()
{
& & & & m_lpBackB4-&GetDC(&m_hDC);
& & & & SelectObject(m_hDC, m_hFontInUse);
& & & & SetBkMode(m_hDC, TRANSPARENT);
& & & & SetBkColor(m_hDC, RGB(0,0,0));
}
void DXC_ddraw::_ReleaseBackBufferDC()
{
& & & & m_lpBackB4-&ReleaseDC(m_hDC);
}
void DXC_ddraw::DrawText(LPRECT pRect, char *pString, COLORREF rgb)
{
& & & & SetTextColor(m_hDC, rgb);
& & & & ::DrawText(m_hDC, pString, strlen(pString), pRect, DT_CENTER | DT_NOCLIP | DT_WORDBREAK | DT_NOPREFIX);//v2.15
}
HRESULT DXC_ddraw::InitFlipToGDI(HWND hWnd)
{
LPDIRECTDRAWCLIPPER pC
& & ZeroMemory( &ddcaps, sizeof(ddcaps) );
& & ddcaps.dwSize = sizeof(ddcaps);
& & m_lpDD4-&GetCaps( &ddcaps, NULL );
& & if( (ddcaps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED) == 0 )
& & {
& && &&&// This means FlipToGDISurface() is not supported, so to display GDI
& && &&&// on these cards, you you must create a bitmap of the GDI window
& && &&&// and BitBlt the bitmap to the backbuffer then flip as normal. However,
& && &&&// this specific sample does not show this.
& && &&&return E_FAIL;
& & }
& & // Create a clipper when using GDI to draw on the primary surface
& & if( FAILED( hr = m_lpDD4-&CreateClipper( 0, &pClipper, NULL ) ) )
& && &&&
& & pClipper-&SetHWnd( 0, hWnd );
& & if( FAILED( hr = m_lpFrontB4-&SetClipper( pClipper ) ) )
& & // We can release the clipper now since g_pDDSPrimary
& & // now maintains a ref count on the clipper
& & & & if( pClipper )
& & & & {
& & & & & & & & pClipper-&Release();
& & & & & & & & pClipper = NULL;
& & & & }
& & return S_OK;
}
void DXC_ddraw::ColorTransferRGB(COLORREF fcolor, int * iR, int * iG, int * iB)
{
WORD wR, wG, wB;
& & & & switch(m_cPixelFormat)
& & & & {
& & & & case 1:
& & & & & & & & // R
& & & & & & & & wR = (WORD)((fcolor&0x)&&3);
& & & & & & & & // G
& & & & & & & & wG = (WORD)((fcolor&0x0000fc00)&&10);
& & & & & & & & // B
& & & & & & & & wB = (WORD)((fcolor&0x00f80000)&&19);
& & & & & & & & *iR = (int)wR;
& & & & & & & & *iG = (int)wG;
& & & & & & & & *iB = (int)wB;
& & & & & & & &
& & & & case 2:
& & & & & & & & // R
& & & & & & & & wR = (WORD)((fcolor&0x)&&3);
& & & & & & & & // G
& & & & & & & & wG = (WORD)((fcolor&0x)&&11);
& & & & & & & & // B
& & & & & & & & wB = (WORD)((fcolor&0x00f80000)&&19);
& & & & & & & & *iR = (int)wR;
& & & & & & & & *iG = (int)wG;
& & & & & & & & *iB = (int)wB;
& & & & & & & &
& & & & }
}
//---------------------------------------------------------------------------
bool DXC_ddraw::Screenshot(LPCTSTR FileName, LPDIRECTDRAWSURFACE7 lpDDS)
{
& & if (!FileName || !lpDDS)
& & bool Success=
& & HDC SurfDC=NULL;& && &&&// GDI-compatible device context for the surface
& & HBITMAP OffscrBmp=NULL; // bitmap that is converted to a DIB
& & HDC OffscrDC=NULL;& && &// offscreen DC that we can select OffscrBmp into
& & LPBITMAPINFO lpbi=NULL; // used by GetDIBits
& & LPVOID lpvBits=NULL;& & // pointer to bitmap bits array
& & HANDLE BmpFile=INVALID_HANDLE_VALUE;& & // destination .bmp file
& & BITMAPFILEHEADER&&// .bmp file header
try
{
& & // Get dimensions of Surface:
& & DDSURFACEDESC2
& & ZeroMemory(&ddsd, sizeof(ddsd));
& & ddsd.dwSize = sizeof(ddsd);
& & if (FAILED(lpDDS-&GetSurfaceDesc(&ddsd))) throw 0;
& & int Width = ddsd.dwW
& & int Height = ddsd.dwH
& & // Create a GDI-compatible device context for the surface:
& & if (FAILED(lpDDS-&GetDC(&SurfDC))) throw 1;
& & // We need an HBITMAP to convert it to a DIB:
& & if ((OffscrBmp = CreateCompatibleBitmap(SurfDC, Width, Height)) == NULL)
& && &&&throw 2;
& & // The bitmap is empty, so let's copy the contents of the surface to it.
& & // For that we need to select it into a device context. We create one.
& & if ((OffscrDC = CreateCompatibleDC(SurfDC)) == NULL) throw 3;
& & // Select OffscrBmp into OffscrDC:
& & HBITMAP OldBmp = (HBITMAP)SelectObject(OffscrDC, OffscrBmp);
& & // Now we can copy the contents of the surface to the offscreen bitmap:
& & BitBlt(OffscrDC, 0, 0, Width, Height, SurfDC, 0, 0, SRCCOPY);
& & // We don't need SurfDC anymore. Free it:
& & lpDDS-&ReleaseDC(SurfDC); SurfDC = NULL;
& & // GetDIBits requires format info about the bitmap. We can have GetDIBits
& & // fill a structure with that info if we pass a NULL pointer for lpvBits:
& & // Reserve memory for bitmap info (BITMAPINFOHEADER + largest possible
& & // palette):
& & if ((lpbi = (LPBITMAPINFO)(new char[sizeof(BITMAPINFOHEADER) +
& && &&&256 * sizeof(RGBQUAD)])) == NULL) throw 4;
& & ZeroMemory(&lpbi-&bmiHeader, sizeof(BITMAPINFOHEADER));
& & lpbi-&bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
& & // Get info but first de-select OffscrBmp because GetDIBits requires it:
& & SelectObject(OffscrDC, OldBmp);
& & if (!GetDIBits(OffscrDC, OffscrBmp, 0, Height, NULL, lpbi, DIB_RGB_COLORS))
& && &&&throw 5;
& & // Reserve memory for bitmap bits:
& & if ((lpvBits = new char[lpbi-&bmiHeader.biSizeImage]) == NULL)
& && &&&throw 6;
& & // Have GetDIBits convert OffscrBmp to a DIB (device-independent bitmap):
& & if (!GetDIBits(OffscrDC, OffscrBmp, 0, Height, lpvBits, lpbi,
& && &&&DIB_RGB_COLORS)) throw 7;
& & // Create a file to save the DIB to:
& & if ((BmpFile = CreateFile(FileName,
& && && && && && && && && && &GENERIC_WRITE,
& && && && && && && && && && &0, NULL,
& && && && && && && && && && &CREATE_ALWAYS,
& && && && && && && && && && &FILE_ATTRIBUTE_NORMAL,
& && && && && && && && && && &NULL)) == INVALID_HANDLE_VALUE) throw 8;
& & DWORD W& & // number of bytes written by WriteFile
& &
& & // Write a file header to the file:
& & bmfh.bfType = 19778;& && &&&// 'BM'
& & // bmfh.bfSize = ???& && &&&// we'll write that later
& & bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
& & // bmfh.bfOffBits = ???& &&&// we'll write that later
& & if (!WriteFile(BmpFile, &bmfh, sizeof(bmfh), &Written, NULL))
& && &&&throw 9;
& & if (Written & sizeof(bmfh)) throw 9;
& & // Write BITMAPINFOHEADER to the file:
& & if (!WriteFile(BmpFile, &lpbi-&bmiHeader, sizeof(BITMAPINFOHEADER),
& && &&&&Written, NULL)) throw 10;
& & if (Written & sizeof(BITMAPINFOHEADER)) throw 10;
& & // Calculate size of palette:
& & int PalE
& & // 16-bit or 32-bit bitmaps require bit masks:
& & if (lpbi-&bmiHeader.biCompression == BI_BITFIELDS) PalEntries = 3;
& & else
& && &&&// bitmap is palettized?
& && &&&PalEntries = (lpbi-&bmiHeader.biBitCount &= 8) ?
& && && && &// 2^biBitCount palette entries max.:
& && && && &(int)(1 && lpbi-&bmiHeader.biBitCount)
& && &&&// bitmap is TrueColor -& no palette:
& && &&&: 0;
& & // If biClrUsed use only biClrUsed palette entries:
& & if (lpbi-&bmiHeader.biClrUsed) PalEntries = lpbi-&bmiHeader.biClrU
& & // Write palette to the file:
& & if (PalEntries)
& & {
& && &&&if (!WriteFile(BmpFile, &lpbi-&bmiColors, PalEntries * sizeof(RGBQUAD),
& && && && &&Written, NULL)) throw 11;
& && &&&if (Written & PalEntries * sizeof(RGBQUAD)) throw 11;
& & }
& & // The current position in the file (at the beginning of the bitmap bits)
& & // will be saved to the BITMAPFILEHEADER:
& & bmfh.bfOffBits = SetFilePointer(BmpFile, 0, 0, FILE_CURRENT);
& & // Write bitmap bits to the file:
& & if (!WriteFile(BmpFile, lpvBits, lpbi-&bmiHeader.biSizeImage,
& && &&&&Written, NULL)) throw 12;
& & if (Written & lpbi-&bmiHeader.biSizeImage) throw 12;
& & // The current pos. in the file is the final file size and will be saved:
& & bmfh.bfSize = SetFilePointer(BmpFile, 0, 0, FILE_CURRENT);
& & // We have all the info for the file header. Save the updated version:
& & SetFilePointer(BmpFile, 0, 0, FILE_BEGIN);
& & if (!WriteFile(BmpFile, &bmfh, sizeof(bmfh), &Written, NULL))
& && &&&throw 13;
& & if (Written & sizeof(bmfh)) throw 13;
& & & & OutputDebugString(&Screenshot Success\r\n&);
& & Success =
}
catch (int &errorcode)
{
& & char Buf[100];
& & wsprintf(Buf, &Screenshot error #%i\r\n&, errorcode);
& & OutputDebugString(Buf);
}
catch (...)
{
& & OutputDebugString(&Screenshot error\r\n&);
}
& & if (SurfDC) lpDDS-&ReleaseDC(SurfDC);
& & if (OffscrDC) DeleteDC(OffscrDC);
& & if (OffscrBmp) DeleteObject(OffscrBmp);
& & if (lpbi) delete[]
& & if (lpvBits) delete[] lpvB
& & if (BmpFile != INVALID_HANDLE_VALUE) CloseHandle(BmpFile);
& &
& & return S
}
//---------------------------------------------------------------------------复制代码
阅读权限10
在线时间25 小时
当前用户组为 梦之始当前积分为 34, 升到下一级还需要 16 点。
主题精华积分
这里是鼠标部分。问题就在这里// DXC_dinput.cpp: implementation of the DXC_dinput class.
//
//////////////////////////////////////////////////////////////////////
#include &DXC_dinput.h&
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DXC_dinput::DXC_dinput()
{
& & & & m_pDI& & = NULL;
& & & & m_pMouse = NULL;
& & & & m_sX& &&&= 0;
& & & & m_sY& &&&= 0;
& & & & m_sZ& &&&= 0;
}
DXC_dinput::~DXC_dinput()
{
& & & & if (m_pMouse != NULL) {
& & & & & & & & m_pMouse-&Unacquire();
& && &&&m_pMouse-&Release();
& && &&&m_pMouse = NULL;
& & & & }
& & & & if (m_pDI != NULL) {
& & & & & & & & m_pDI-&Release();
& && &&&m_pDI = NULL;
& & & & }
}
BOOL DXC_dinput::bInit(HWND hWnd, HINSTANCE hInst)
{
DIMOUSESTATE& & & &
& & & & GetCursorPos(&Point);
& & & & m_sX& &&&= (short)(Point.x);
& & & & m_sY& &&&= (short)(Point.y);
& & & & hr = DirectInputCreate( hInst, DIRECTINPUT_VERSION, &m_pDI, NULL );
& & if (hr != DI_OK) return FALSE;
& & & & hr = m_pDI-&CreateDevice( GUID_SysMouse, &m_pMouse, NULL );
& & & & if (hr != DI_OK) return FALSE;
& & & & hr = m_pMouse-&SetDataFormat( &c_dfDIMouse );
& & & & if (hr != DI_OK) return FALSE;
& & & & hr = m_pMouse-&SetCooperativeLevel( hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
& & & & if (hr != DI_OK) return FALSE;
//& & & & m_pMouse-&GetDeviceState( sizeof(DIMOUSESTATE), &dims );
& & & & if ( m_pMouse-&GetDeviceState( sizeof(DIMOUSESTATE), &dims ) != DI_OK )
& & & & {
& & & & & & & & m_pMouse-&Acquire();
& & & & & & & & //return TRUE;
& & & & }
& & & & return TRUE;
}
void DXC_dinput::SetAcquire(BOOL bFlag)
{
DIMOUSESTATE
& & & & if (m_pMouse == NULL)
& & & & if (bFlag == TRUE) {
& & & & & & & & m_pMouse-&Acquire();
& & & & & & & & m_pMouse-&GetDeviceState( sizeof(DIMOUSESTATE), &dims );
& & & & }
& & & & else m_pMouse-&Unacquire();
}
void DXC_dinput::UpdateMouseState(short * pX, short * pY, short * pZ, char * pLB, char * pRB)
{
& & & & if ( m_pMouse-&GetDeviceState( sizeof(DIMOUSESTATE), &dims ) != DI_OK )
& & & & {
& & & & & & & & m_pMouse-&Acquire();
& & & & & & & &
& & & & }
& & & & m_sX += (short)dims.lX;
& & & & m_sY += (short)dims.lY;
& & & & if( (short)dims.lZ != 0 )m_sZ = (short)dims.lZ;
& & & & if (m_sX & 0) m_sX = 0;
& & & & if (m_sY & 0) m_sY = 0;
& & & & if (m_sX & 639) m_sX = 639;
& & & & if (m_sY & 479) m_sY = 479;
& & & & *pX = m_sX;
& & & & *pY = m_sY;
& & & & *pZ = m_sZ;
& & & & *pLB = (char)dims.rgbButtons[0];
& & & & *pRB = (char)dims.rgbButtons[1];
}复制代码
阅读权限200
在线时间3705 小时
当前用户组为 坛主当前积分为 1463, 该用户为特殊用户。
主题精华积分
锁定鼠标在某个窗口是调用SetCapture实现的,你找找有没有调用这个函数的地方呢
我一定是见鬼了!
阅读权限100
在线时间98 小时
当前用户组为 版主当前积分为 42, 该用户为特殊用户。
主题精华积分
这个是用direct写的。至于鼠标判定问题,我之前开发的小游戏中也遇到过,问题在于游戏设计本身 它的思路是一直获取鼠标位置,并且进行判定。
从代码可以得出。那么它对资源的消耗以及没有释放对鼠标的控制,这个在我之前开发的游戏中也遇到过。
那么可以转变下思路 可以在鼠标获取之前加入一些判定,比如单击游戏本身再进行获取,或者按ESC键能够退出等等一些优化
建议采用 ScreenToClient( )是把屏幕坐标转换为窗口坐标 ClientToScreen是把坐标从当前窗体转化成全屏幕的 或者判定完释放资源。
我手头没有源码不方便调试,只提供思路,具体还需要慢慢修改,祝好运。
新年做个贺岁小游戏
阅读权限10
在线时间2 小时
当前用户组为 梦之始当前积分为 3, 升到下一级还需要 47 点。
主题精华积分
看 DirectX角色扮演游戏编程 或者 Windows游戏编程大师技巧 里,讲DirectInput的那一节。
Powered by

我要回帖

更多关于 画面好的2d网游 的文章

 

随机推荐