某物体限制在不规则区域的经典代码

  if (px[rgb_blu]==0&&px[rgb_bld]==0&&px[rgb_bru]==0&&px[rgb_brd]==0)//在红色区域运动 { TextOut(hDC,300,150,"红色区域",strlen("红色区域")); GameEngine::GetGameEngine()->m_bDown=TRUE; GameEngine::GetGameEngine()->m_bRight=TRUE; GameEngine::GetGameEngine()->m_bLeft=TRUE; GameEngine::GetGameEngine()->m_bUp=TRUE; } if (px[rgb_bruu]!=0&&px[rgb_bluu]!=0&&px[rgb_brdd]==0)//上碰壁 { TextOut(hDC,300,250,"上碰壁",strlen("上碰壁")); GameEngine::GetGameEngine()->m_bDown=TRUE; GameEngine::GetGameEngine()->m_bRight=TRUE; GameEngine::GetGameEngine()->m_bLeft=TRUE; GameEngine::GetGameEngine()->m_bUp=FALSE; } if (px[rgb_bldd]!=0&&px[rgb_brdd]!=0&&px[rgb_bruu]==0)//下碰壁 { TextOut(hDC,300,250,"下碰壁",strlen("下碰壁")); GameEngine::GetGameEngine()->m_bDown=FALSE; GameEngine::GetGameEngine()->m_bRight=TRUE; GameEngine::GetGameEngine()->m_bLeft=TRUE; GameEngine::GetGameEngine()->m_bUp=TRUE; } if (px[rgb_blul]!=0&&px[rgb_bldl]!=0&&px[rgb_brur]==0)//左碰壁 { TextOut(hDC,300,250,"左碰壁",strlen("左碰壁")); GameEngine::GetGameEngine()->m_bDown=TRUE; GameEngine::GetGameEngine()->m_bRight=TRUE; GameEngine::GetGameEngine()->m_bLeft=FALSE; GameEngine::GetGameEngine()->m_bUp=TRUE; } if (px[rgb_brur]!=0&&px[rgb_brdr]!=0&&px[rgb_blul]==0)//右碰壁 { TextOut(hDC,300,250,"右碰壁",strlen("右碰壁")); GameEngine::GetGameEngine()->m_bDown=TRUE; GameEngine::GetGameEngine()->m_bRight=FALSE; GameEngine::GetGameEngine()->m_bLeft=TRUE; GameEngine::GetGameEngine()->m_bUp=TRUE; } if(GetAsyncKeyState(VK_UP)<0 ) //判断上方向键是否按下 { if (px[rgb_bruu]!=0||px[rgb_bluu]!=0)//向上运动上面碰壁 { TextOut(hDC,300,250,"左上右上",strlen("左上右上")); GameEngine::GetGameEngine()->m_bUp=FALSE; } } if(GetAsyncKeyState(VK_DOWN)<0 ) //判断下方向键是否按下 { if (px[rgb_bldd]!=0||px[rgb_brdd]!=0)//下面碰壁 { TextOut(hDC,300,250,"左下右下",strlen("左下右下")); GameEngine::GetGameEngine()->m_bDown=FALSE; } } if(GetAsyncKeyState(VK_LEFT)<0 ) //判断左方向键是否按下 { if (px[rgb_blul]!=0||px[rgb_bldl]!=0)//左面碰壁 { TextOut(hDC,300,250,"左上左下",strlen("红色区域")); GameEngine::GetGameEngine()->m_bLeft=FALSE; } } if(GetAsyncKeyState(VK_RIGHT)<0 ) //判断上方向键是否按下 { if (px[rgb_brur]!=0||px[rgb_brdr]!=0)//右面碰壁 { TextOut(hDC,300,250,"右上右下",strlen("红色区域")); GameEngine::GetGameEngine()->m_bRight=FALSE; } }

 

你可能感兴趣的:(某物体限制在不规则区域的经典代码)