本文整理汇总了C++中EventHandler::getTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ EventHandler::getTarget方法的具体用法?C++ EventHandler::getTarget怎么用?C++ EventHandler::getTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventHandler
的用法示例。
在下文中一共展示了EventHandler::getTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: act
sf::Sprite Ship::act(EventHandler e, Util* u)
{
int * tar = e.getTarget(alignment);
double dx = tar[0];
double dy = tar[1];
dx = dx-(x+radius);
dy = dy-(y+radius);
double magnitude = 2/std::sqrt(std::abs(dx)*std::abs(dx)+std::abs(dy)*std::abs(dy));
bool hitBarrier = false;
if(std::abs(dx) > 1 || std::abs(dy) > 1)
{
x += dx*magnitude;
y += dy*magnitude;
for (int i = 0; i < barrierVector.size() && !hitBarrier; i++) // check barrier collisions
{
if (didICollide(&barrierVector.at(i)))
{
hitBarrier = true;
}
}
}
if(x+radius<0 || x+radius > mx || hitBarrier)
x -= dx*magnitude;
if(y+radius<0 || y+radius > my || hitBarrier)
y -= dy*magnitude;
shipSprite.setPosition(x, y);
end = e.myClock.getElapsedTime();
special(e, u);
if(end - start >= sf::milliseconds(curAtkDelay)) // start bullet creation stuff
{
int dir = -(alignment*2-1);
start = end;
if(specialA > 0)
{
specialA--;
u->addBullet(generateA(specialA, dir));
}else if(specialB>0)
{
specialB--;
u->addBullet(generateB(specialB, dir, e));
}else if(e.shootNow(alignment))
{
//double dx = e.mouseX-(x+radius);
//double dy = e.mouseY-(y+radius);
curAtkDelay = attackDelay;
double dx = 0;
double dy = dir;
double magnitude = 4/dy; // equivalent to 4/std::sqrt(std::abs(dx)*std::abs(dx)+std::abs(dy)*std::abs(dy));
sf::Color newColor(curColor.r, curColor.g, curColor.b, sf::Int8(180));
Bullet * mine = new Bullet(x+radius/2, y+radius/2, dx*magnitude, dy*magnitude, mx, my, alignment, newColor);
u->addBullet(mine);
}
}
//std::cout << "pointer of first:" << u.first << "\n";
return shipSprite;
}