📄 ball.cpp
字号:
// Ball.cpp: implementation of the CBall class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DBallGame.h"
#include "Ball.h"
#include "MyDef.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBall::CBall()
{
}
CBall::~CBall()
{
}
void CBall::InitBall(CDC * pDC,CRect * rect ,CStatic * news )
{
p_WinDC = pDC;
WinRect = rect;
m_news = news;
Pos.x = rect->right /2;
//y值需要扩展初始化
delta_x = delta_y = 2;
y_Above = rect->bottom /11;
y_Below = rect->bottom *10/11;
InitOther();
PrePos.x = Pos.x;
PrePos.y =Pos.y;
}
void CBall::InitOther()//对其他环境参数进行设置
{
}
void CBall::DrawBall(bool style)
{
if(style==1)
{
p_WinDC->SelectStockObject (BLACK_PEN);
p_WinDC->SelectStockObject (BLACK_BRUSH);
p_WinDC->Ellipse ( Pos.x-5, Pos.y-5 , Pos.x+5, Pos.y+5);
}
else
{
p_WinDC->SelectStockObject (WHITE_PEN);
p_WinDC->SelectStockObject (WHITE_BRUSH);
p_WinDC->Ellipse ( PrePos.x-5, PrePos.y-5 , PrePos.x+5, PrePos.y+5);
}
}
void CBall::FollowBar(int pos)
{
Pos.x = pos;
m_BelowBarPos = pos;
DrawBall(0);
DrawBall(1);
PrePos.x = Pos.x;
}
bool CBall::Move()
{
DrawBall(0);
DrawBall(1);
PrePos.x = Pos.x;
PrePos.y = Pos.y;
if(Pos.x >=WinRect->right -5||Pos.x <=5)x_dir=!x_dir;
if(MoveEx()==1)
return 1;
if(x_dir==0)Pos.x +=delta_x;
else Pos.x-=delta_x;
if(y_dir==0)Pos.y +=delta_y;
else Pos.y-=delta_y;
return 0;
}
bool CBall::MoveEx()
{
return 0;
}
bool CBall::Analyse(int v)
{
if(v==BAR_BELOW)//belowbar
{
if(Pos.x >=m_BelowBarPos-23 && Pos.x<=m_BelowBarPos+23 )
{
if(Pos.x >=m_BelowBarPos-12&&Pos.x <= m_BelowBarPos+12)
{
delta_x = 2;
}
else if(Pos.x >=m_BelowBarPos-17&&Pos.x <= m_BelowBarPos+17)
{
delta_x = 3;
}
else if(Pos.x >=m_BelowBarPos-20&&Pos.x <= m_BelowBarPos+20)
{
delta_x = 4;
}
else
{
delta_x = 5;
}
return 1;
}
else return 0;
}
else//AboveBar
{
if(Pos.x >=m_AboveBarPos-23 && Pos.x<=m_AboveBarPos+23 )
{
if(Pos.x >=m_AboveBarPos-12&&Pos.x <= m_AboveBarPos+12)
{
delta_x = 2;
}
else if(Pos.x >=m_AboveBarPos-17&&Pos.x <= m_AboveBarPos+17)
{
delta_x = 3;
}
else if(Pos.x >=m_AboveBarPos-20&&Pos.x <= m_AboveBarPos+20)
{
delta_x = 4;
}
else
{
delta_x = 5;
}
return 1;
}
else return 0;
}
}
void CBall::SetBarPos(int pos, int type)
{
if(type == BAR_ABOVE)
m_AboveBarPos = pos;
else if(type == BAR_BELOW)
m_BelowBarPos = pos;
}
void CBall::Failure()
{
}
void CBall::ResetEx()
{
}
void CBall::Reset()
{
DrawBall(0);
delta_x = 2;
ResetEx();
DrawBall(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -