本文整理汇总了C++中Coord::abs方法的典型用法代码示例。如果您正苦于以下问题:C++ Coord::abs方法的具体用法?C++ Coord::abs怎么用?C++ Coord::abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coord
的用法示例。
在下文中一共展示了Coord::abs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: distance
// process distance of center of gravity between two GeoObjs
Coord distance (GeoObj const& x1, GeoObj const& x2)
{
Coord c = x1.center_of_gravity() - x2.center_of_gravity();
return c.abs(); // return coordinates as absolute values
}
示例2: thinkEnemy
void Enemy::thinkEnemy()
{
// targetがあるかどうかで動きが変わる
int dx=0;
int dy=0;
if( m_targetID != NO_TARGET ){
if( (thinkCounter % 2 ) == 0 ){
Movable *m = g_app->getMovable( m_targetID );
if(m){
coord.dxdy8( m->coord, &dx, &dy );
} else {
setTarget( NO_TARGET );
}
}
} else {
if( ( random() % 7 ) != 0 ){
dx = dy = 0;
} else {
dx = -1 + ( random() % 3 );
dy = -1 + ( random() % 3 );
}
}
// 進む
Coord nextCo = coord.translate(dx,dy);
if( g_app->m_floor->hitMovable( nextCo, id ) == NULL
&& g_app->m_floor->hitMovable( coord, id ) == NULL
&& g_app->m_floor->getTile( nextCo ).walkable() == true ){
this->moveTo( nextCo, 250.0f, true );
}
// 撃つ
if( ( random() % 8 ) == 0 ){
Coord dc = g_app->m_mychar->coord - this->coord;
if( dc.abs().length() < 9 ){
dc.x *= 2;
dc.y *= 2;
if( dc.x != 0 || dc.y != 0 ){
g_app->allocShootBullet( g_app->getGuestID(),
g_app->getNewID(),
coord, coord + dc, id, MOVABLE_HUMAN );
}
}
}
if( ( random() % 19 ) == 0 ){
// ターゲットが無かったら探してターゲットにする
if( m_targetID == NO_TARGET ){
std::vector<Movable*> v;
v = g_app->getMovables();
std::vector<Movable*>::iterator it;
std::vector<Movable*> found;
for(it=v.begin(); it != v.end(); ++it ){
if( (*it)->typeID == MOVABLE_HUMAN
&& (*it)->guestid == g_app->getGuestID()
&& (*it)->coord.distance( coord ) < 8.0f ){
found.push_back( (*it) );
}
}
if( found.size() > 0 ){
int i = random() % found.size();
setTarget( found[i]->id );
std::cerr << "found player target ID:" << m_targetID << std::endl;
}
}
}
// たまには忘れる
if( ( random() % 41 ) == 0 ){
setTarget( NO_TARGET );
}
}