📄 ball.cpp
字号:
#include "Ball.h"
Ball::Ball()
{
objectType = OT_Ball;
}
BallStateT Ball::doMove(VecPosition *pos,VecPosition *vel,VecPosition *acc)
{
Rect field(VecPosition(0,0),VecPosition(CFLDLEN,CFLDWIDTH));
Line leftDoor(0,1,0);
Line rightDoor(0,1,-CFLDLEN);
VecPosition oldPos = *pos;
if(acc->getMagnitude() > CMAXBALLACC)
{
acc->setMagnitude(CMAXBALLACC);
}
*vel += *acc;
if(vel->getMagnitude() > CMAXBALLV)
{
vel->setMagnitude(CMAXBALLV);
}
*acc = VecPosition(0,0);
*pos += *vel;
if(!field.isInside(*pos))
{
Line ballLine = Line::makeLineFromTwoPoints(oldPos,*pos);
if(pos->getX() < 0)
{
VecPosition posCross = ballLine.getIntersection(leftDoor);
if(posCross.getY() > CDOORY1 && posCross.getY() < CDOORY2)
{
return BS_LEFT_Goal;
}
else
{
vel->setX(- vel->getX());
pos->setX(- pos->getX());
}
}
else if(pos->getX() > CFLDLEN)
{
VecPosition posCross = ballLine.getIntersection(rightDoor);
if(posCross.getY() > CDOORY1 && posCross.getY() < CDOORY2)
{
return BS_RIGHT_Goal;
}
else
{
vel->setX(- vel->getX());
pos->setX(2.0 * CFLDLEN - pos->getX());
}
}
if( pos->getY() < 0)
{
vel->setY(- vel->getY());
pos->setY(- pos->getY());
}
else if(pos->getY() > CFLDWIDTH)
{
vel->setY(- vel->getY());
pos->setY(2 * CFLDWIDTH - pos->getY());
}
}
*vel *= CBALLDECAY;
return BS_Normal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -