我要崩溃了 怎么都找不出来为什么
我做的是推箱子程序,逻辑是没问题的,但是现在画图出问题了。
先看图吧
这说要推时的样子:
这是推了后样子, 空位直接被覆盖掉了,问题就是这里, 怎么都找不到原因。
但是推箱子的英雄却是没问题的啊蓝色圆圈:
下面是画图的代码:
程序代码:
case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); mg.SetGDC(hdc); mg.DrawMap(txz.GetZAV()); mg.DrawMB(txz.GetMBV()); mg.DrawXZ(txz.Getxzv()); mg.DrawHR(txz.GetHP()); EndPaint(hwnd,&ps); } void CXZMG:: DrawMap(vector<POINT>* _za) //绘制地图迷宫 { if (m_hdc != NULL) { HBRUSH brush1 = CreateSolidBrush(0x00000000), oldbrs; //黑色画刷 oldbrs = (HBRUSH)SelectObject(m_hdc, brush1); //换画刷 Rectangle(m_hdc, SX, SY, SX + m_W*(JS + JG) - JG, SY + m_H*(JS + JG) - JG);//画黑色背景 HBRUSH brush2 = CreateSolidBrush(0x000000FF); //换红色画刷 SelectObject(m_hdc, brush2); vector<POINT>::iterator b = _za->begin(), e = _za->end(); for (; b != e; ++b) { int l = SX + (*b).x * (JS + JG), t = SY + (*b).y * (JS + JG); int r = l + JS, b = t + JS; Rectangle(m_hdc, l, t, r, b); //根据每个障碍障碍物的坐标画障碍物 } SelectObject(m_hdc, oldbrs);//恢复原来的刷子 DeleteObject(brush1); DeleteObject(brush2); } } void CXZMG:: DrawMB(vector<POINT>* mbv) { if (m_hdc != NULL) { HBRUSH brush = CreateSolidBrush(0x00FFFFFF),oldbrs; HPEN pen = CreatePen(PS_SOLID,2,0x0000FF00), oldpen; oldbrs = (HBRUSH)SelectObject(m_hdc, brush);//换白色刷子刷白色空心 oldpen = (HPEN)SelectObject(m_hdc, pen); //换绿色画笔画边框 vector<POINT>::iterator b = mbv->begin(), e = mbv->end(); for (; b != e; ++b) { int l = SX + (*b).x * (JS + JG), t = SY + (*b).y * (JS + JG); int r = l + JS, d = t + JS; Rectangle(m_hdc, l, t, r, d);//画空位 } SelectObject(m_hdc, oldbrs);//恢复 SelectObject(m_hdc, oldpen);//恢复 DeleteObject(brush); DeleteObject(pen); } } void CXZMG:: DrawXZ(vector<POINT>* _xz)//绘制所有箱子 传入箱子的坐标点表 { if (m_hdc != NULL) { HBRUSH brush = CreateHatchBrush(HS_DIAGCROSS,0x000000ff),oldbrs; HPEN pen = CreatePen(PS_SOLID,1, 0x00ffffff),oldpen; oldbrs = (HBRUSH)SelectObject(m_hdc, brush); //换网格刷子 oldpen = (HPEN)SelectObject(m_hdc, pen); //白色边框 vector<POINT>::iterator b = _xz->begin(), e = _xz->end(); for (; b != e; ++b) { int l = SX + (*b).x * (JS + JG), t = SY + (*b).y * (JS + JG); int r = l + JS, d = t + JS; Rectangle(m_hdc,l+3, t+3, r-3, d-3); } SelectObject(m_hdc, oldbrs);//恢复 SelectObject(m_hdc, oldpen);//恢复 DeleteObject(pen); DeleteObject(brush); } } void CXZMG:: DrawHR(POINT hp) //绘制英雄 传入英雄的坐标 { if (m_hdc != NULL) { HBRUSH brush = CreateSolidBrush(0x00FF0000),oldbrs; HPEN pen = CreatePen(PS_SOLID,1, 0x00FF0000),oldpen; oldbrs = (HBRUSH)SelectObject(m_hdc, brush); //蓝色画刷 oldpen = (HPEN)SelectObject(m_hdc, pen); //蓝色边框 Ellipse(m_hdc, SX + hp.x * (JS+JG)+JG, SY + hp.y * (JS+JG)+JG, SX + hp.x * (JS+JG)+JS -JG-1, SY + hp.y * (JS+JG)+JS -JG-1); SelectObject(m_hdc, oldbrs);//恢复 SelectObject(m_hdc, oldpen);//恢复 DeleteObject(pen); DeleteObject(brush); }
[ 本帖最后由 死了都要C 于 2012-2-26 17:44 编辑 ]