本帖最后由 Avatar_Cc 于 2018-1-30 17:35 编辑
写的乱, 看不懂可以问我
代码:Data Jump(Bitmap * _Bitmap)
{
BYTE Jump_R = 0;
BYTE Jump_G = 0;
BYTE Jump_B = 0;
BYTE Next_R = 0;
BYTE Next_G = 0;
BYTE Next_B = 0;
POINT Next_One = { 0 };
int Next_One_Num = 0;
POINT Next_Two = { 0 };
int Next_Two_Num = 0;
POINT Jump_Point = { 0 };
int Jump_Num = 0;
for (int y = 400; y < _Bitmap->GetHeight() - 400; y++)
{
int i = 0;
for (int x = 0; x < _Bitmap->GetWidth(); x++)
{
Color m_Color;
_Bitmap->GetPixel(x, y, &m_Color);
if (y == 400 && x == 0)
{
Jump_R = m_Color.GetRed();
Jump_G = m_Color.GetGreen();
Jump_B = m_Color.GetBlue();
}
if (abs(m_Color.GetRed() - Jump_R) > 20 || abs(m_Color.GetGreen() - Jump_G) > 20 || abs(m_Color.GetBlue() - Jump_B) > 20)
{
if (y < _Bitmap->GetHeight() / 2)
{
if (abs(m_Color.GetRed() - 60) < 20 && abs(m_Color.GetGreen() - 60) < 20 && abs(m_Color.GetBlue() - 70) < 25 && i == 0)
{
i = x + 61;
}
if (x < i)
{
continue;
}
if (Next_One.y == 0)
{
Next_One.y = y;
Next_One.x = x;
//Next_One_Num++;
Color Temp_Color;
_Bitmap->GetPixel(x, y + 2, &Temp_Color);
Next_R = Temp_Color.GetRed();
Next_G = Temp_Color.GetGreen();
Next_B = Temp_Color.GetBlue();
Next_Two.x = x;
Next_Two.y = y;
}
if (Next_One.y == y)
{
Next_One_Num++;
}
else
{
if (y > Next_One.y)
{
if (abs(m_Color.GetRed() - Next_R) < 10 && abs(m_Color.GetGreen() - Next_G) < 10 && abs(m_Color.GetBlue() - Next_B) < 10)
{
if (x < Next_Two.x && (Next_One.x - x) * 2 < 410)
{
Next_Two.x = x;
Next_Two.y = y;
Next_Two_Num = 0;
}
if (x == Next_Two.x)
{
Next_Two_Num++;
}
}
}
}
}
else
{
if (abs(m_Color.GetRed() - 54) < 5 && abs(m_Color.GetGreen() - 59) < 5 && abs(m_Color.GetBlue() - 101) < 5)
{
if (Jump_Point.y != y)
{
Jump_Point.x = x;
Jump_Point.y = y;
Jump_Num = 0;
}
else
{
Jump_Num++;
}
}
}
}
}
}
Data m_Data;
if (Next_One_Num)
{
Next_One.x += Next_One_Num / 2;
}
if (Next_Two_Num)
{
Next_Two.y += Next_Two_Num / 2;
}
if (Jump_Num)
{
Jump_Point.x += Jump_Num / 2;
}
m_Data.m_Next.x = Next_One.x;
m_Data.m_Next.y = Next_Two.y;
m_Data.m_Jump = Jump_Point;
double Double_Temp_Distance = sqrt((abs(m_Data.m_Next.y - m_Data.m_Jump.y)) * (abs(m_Data.m_Next.y - m_Data.m_Jump.y)) + (abs(m_Data.m_Next.x - m_Data.m_Jump.x)) * (abs(m_Data.m_Next.x - m_Data.m_Jump.x)));
int Int_Temp_Distance = (int)Double_Temp_Distance;
if (Double_Temp_Distance - Int_Temp_Distance > 0.5)
{
Int_Temp_Distance++;
}
m_Data.m_Distance = Int_Temp_Distance;
return m_Data;
}
|