本文整理汇总了C++中Enemy::SetX方法的典型用法代码示例。如果您正苦于以下问题:C++ Enemy::SetX方法的具体用法?C++ Enemy::SetX怎么用?C++ Enemy::SetX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enemy
的用法示例。
在下文中一共展示了Enemy::SetX方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display
void display(void) {
if (lastFrameTime == 0) {
lastFrameTime = glutGet(GLUT_ELAPSED_TIME);
}
int now = glutGet(GLUT_ELAPSED_TIME);
int elapsedMilliseconds = now - lastFrameTime;
float elapsedTime = elapsedMilliseconds / 1000.0f;
lastFrameTime = now;
int windowWidth = glutGet(GLUT_WINDOW_WIDTH);
int windowHeight = glutGet(GLUT_WINDOW_HEIGHT);
if (enemy.GetX() > windowWidth - enemy.GetWidth()) {
enemy.SetDirectionX(-1);
} else if (enemy.GetX() < 0) {
enemy.SetDirectionX(1);
}
enemy.SetX(enemy.GetX() +
enemy.GetVelocity() * elapsedTime * enemy.GetDirectionX());
enemy.SetY(enemy.GetY() +
enemy.GetVelocity() * elapsedTime * enemy.GetDirectionY());
if (enemy.GetY() > windowHeight - enemy.GetHeight()) {
enemy.SetDirectionY(-1);
} else if (enemy.GetY() < 0) {
enemy.SetDirectionY(1);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
enemy.Display();
player.Display();
glutSwapBuffers();
}
示例2: Update
//.........这里部分代码省略.........
(*itr)->DoInterpolateUpdate();
#else
bs.Read(x);
bs.Read(y);
bs.Read(w);
(*itr)->setLocation( x, y, w );
// Lab 7 Task 1 : Read Extrapolation Data velocity x, velocity y & angular velocity
bs.Read(temp);
(*itr)->SetVelocityX( temp );
bs.Read(temp);
(*itr)->SetVelocityY( temp );
bs.Read(temp);
(*itr)->SetAngularVelocity( temp );
#endif
break;
}
}
}
break;
case ID_COLLIDE:
{
unsigned int shipid;
float x, y;
bs.Read(shipid);
if( shipid == ships_.at(0)->GetID() )
{
std::cout << "collided with someone!" << std::endl;
bs.Read(x);
bs.Read(y);
ships_.at(0)->SetX( x );
ships_.at(0)->SetY( y );
bs.Read(x);
bs.Read(y);
ships_.at(0)->SetVelocityX( x );
ships_.at(0)->SetVelocityY( y );
#ifdef INTERPOLATEMOVEMENT
bs.Read(x);
bs.Read(y);
ships_.at(0)->SetServerVelocityX( x );
ships_.at(0)->SetServerVelocityY( y );
#endif
}
}
break;
// Lab 13 Task 10 : new cases to handle missile on application side
case ID_NEWMISSILE:
{
float x, y, w;
int id;
bs.Read(id);
bs.Read(x);
bs.Read(y);
bs.Read(w);
missiles_.push_back(new Missile("missile.png", x, y, w, id));
}
break;
case ID_UPDATEMISSILE:
{
float x, y, w;
int id;