本文整理汇总了C++中Tank类的典型用法代码示例。如果您正苦于以下问题:C++ Tank类的具体用法?C++ Tank怎么用?C++ Tank使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tank类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: safeThreadSafeQueueEvent
void Ant::attack()
{
Actor *pTarget = ActorHandler::getInstance()->getActor(mTarget);
mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
//check if cooldownCounter is higher than weaponCooldown
if(mCooldownCounter > 1.0f)
{
Tank *pTank = dynamic_cast<Tank*>(pTarget);
Driver *pDriver = dynamic_cast<Driver*>(pTarget);
mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);
if(pTank != NULL)
{
safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
pTank->reduceHp(mDamage);
}
else if(pDriver != NULL)
{
safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
pDriver->reduceHp(mDamage);
}
}
//send event to have the enemy perform his attack animation
//send event to collision checking for a hit
}
示例2: getTank
void ManualTankState::onKeyPress(uint16_t keyCode)
{
Tank * tank = getTank();
if(tank == NULL)
return;
switch(keyCode)
{
case IR_BUTTON_A: tank->setMode(Auto); break;
case IR_BUTTON_B: break;
case IR_BUTTON_C: tank->setMode(Parking); break;
case IR_BUTTON_D: break;
case IR_BUTTON_E: break;
case IR_BUTTON_F: break;
case IR_BUTTON_SETTING: tank->stop(); break;
case IR_BUTTON_UP: tank->getCurrentMove() == Forward ? tank->forward(_baseSpeed * 2): tank->forward(_baseSpeed); break;
case IR_BUTTON_DOWN: tank->getCurrentMove() == Backward ? tank->backward(_baseSpeed * 2) : tank->backward(_baseSpeed); break;
case IR_BUTTON_LEFT: tank->left(); break;
case IR_BUTTON_RIGHT: tank->right(); break;
case IR_BUTTON_0: break;
case IR_BUTTON_1: break;
case IR_BUTTON_2: break;
case IR_BUTTON_3: break;
case IR_BUTTON_4: break;
case IR_BUTTON_5: break;
case IR_BUTTON_6: break;
case IR_BUTTON_7: break;
case IR_BUTTON_8: break;
case IR_BUTTON_9: break;
default:break;
}
}
示例3: IsStuck
bool IsStuck( Tank & self )
{
double sx = fabs( self.speed_x() );
double sy = fabs( self.speed_y() );
speed_stat.push_back( SpeedStat(sx, sy) );
if (speed_stat.size() > 50)
{
speed_stat.erase( speed_stat.begin() );
}
else
{
return false;
}
double avg_x = 0.0, avg_y = 0.0;
for (int i = 0; i < speed_stat.size(); ++i)
{
avg_x += speed_stat[i].m_sx;
avg_y += speed_stat[i].m_sy;
}
avg_x = avg_x / speed_stat.size();
avg_y = avg_y / speed_stat.size();
if (avg_x < min_stuck_speed && avg_y < min_stuck_speed)
{
stuck_tick = stuck_period;
return true;
}
return false;
}
示例4: init
void QualEngine::init()
{
if (engineState != QualEngine::OPENED) return;
// ... initialize node concentrations & tank volumes
for (Node* node : network->nodes)
{
if ( network->qualModel->type == QualModel::TRACE ) node->quality = 0.0;
else node->quality = node->initQual;
if ( node->type() == Node::TANK )
{
Tank* tank = static_cast<Tank*>(node);
tank->volume = tank->findVolume(tank->initHead);
}
}
// ... initialize reaction model and quality solver
qualSolver->init();
network->qualModel->init(network);
qualStep = network->option(Options::QUAL_STEP);
if ( qualStep <= 0 ) qualStep = 300;
qualTime = 0;
engineState = QualEngine::INITIALIZED;
}
示例5: MoveTurretOrShoot
bool MoveTurretOrShoot( Tank * pEnemy, Tank & self, World & world, model::Move& move, double offset )
{
double angle_to_enemy = self.GetTurretAngleTo(*pEnemy);
if (angle_to_enemy + offset > ( MIN_ANGLE) )
{
move.set_turret_turn(1.0);
}
else if (angle_to_enemy + offset < ( -MIN_ANGLE ) )
{
move.set_turret_turn(-1.0);
}
else
{
//vector<Tank> t = world.tanks();
//if ( ! EnemyBlocked(pEnemy, self, t) ) /* decide to shoot here, path may block */
//{
/* burst if we almoust alone */
if ( EnemyIsWalkingDead( pEnemy ) || self.premium_shell_count() > 3 )
{
move.set_fire_type(PREMIUM_PREFERRED);
}
else
{
move.set_fire_type(REGULAR_FIRE);
}
return true;
//}
}
return false;
}
示例6: EnemyBlocked
bool EnemyBlocked( Tank * pEnemy, Tank & self, vector<Tank> & t )
{
double my_angle = self.GetAngleTo( *pEnemy );
double my_dist = self.GetDistanceTo( *pEnemy );
for (int i = 0; i < t.size(); ++i)
{
if (t[i].id() == pEnemy->id() || t[i].id() == self.id())
{
continue;
}
double max_wh = std::max( t[i].width(), t[i].height() );
double alpha = fabs( self.GetAngleTo(t[i]) - my_angle );
double his_dist = self.GetDistanceTo( t[i] );
if (alpha > M_PI / 4)
{
continue;
}
double d_size = sin(alpha) * my_dist;
if ( d_size <= max_wh/2 && his_dist < my_dist )
{
return true;
}
}
return false;
}
示例7: while
double Car::budget_consumption_byType(unsigned int id)
{
/* Return sum(fuel price) / ODO * 100 for fueltype */
// We will calculate only full refills as partial refills cannat be calculated correctly
double totalDistance=0;
double totalQuantity=0;
//go to last tankstop
Tank *curTank = _tanklist.first();
const Tank *prevTank=NULL;
while (curTank)
{
prevTank=previousTank(curTank->distance());
if (!(prevTank==NULL))
{
//prevous tank must have correct fueltype
if (prevTank->fueltype()==id)
if (prevTank->full())
{
totalDistance += curTank->distance()-prevTank->distance();
totalQuantity += curTank->quantity();
}
//cannot set curTank to prevTank as it is const
curTank=NULL;
foreach(Tank *tmp,_tanklist)
{
if (tmp->id()==prevTank->id())
curTank=tmp;
}
}
else {
curTank=NULL;
}
}
示例8: testCollision
void World::moveBullets()
{
for (int q = 0; q < _bulletList.size(); q++) {
if (_bulletList[q]->getKillAnimation() != 0) {
if (_bulletList[q]->getKillAnimation() == 10) {
delete _bulletList[q];
_bulletList.remove(q);
} else {
_bulletList[q]->animation();
}
} else {
QPoint pos = _bulletList[q]->getPos();
bool withTank;
void *status = testCollision(_bulletList[q]->getSpeed(), _bulletList[q], false, &withTank);
if (status == nullptr) {
switch (_bulletList[q]->getAngle()) {
case 0: {
_bulletList[q]->setPos(QPoint(pos.x(), pos.y() - _bulletList[q]->getSpeed()));
break;
}
case 1: {
_bulletList[q]->setPos(QPoint(pos.x() + _bulletList[q]->getSpeed(), pos.y()));
break;
}
case 2: {
_bulletList[q]->setPos(QPoint(pos.x(), pos.y() + _bulletList[q]->getSpeed()));
break;
}
case 3: {
_bulletList[q]->setPos(QPoint(pos.x() - _bulletList[q]->getSpeed(), pos.y()));
break;
}
}
} else {
if (withTank) {
Tank *tank = ((Tank*)status);
tank->hit();
if (tank->getHp() == 0) {
tank->setSize(0);
}
} else {
Wall *wall = ((Wall*)status);
wall->hit();
if (wall->getHp() == 0) {
for (int i = 0; i < _wallList.size(); i++) {
if (_wallList[i] == wall) {
if (_wallList[i] == _playerBase) {
_playerBase = nullptr;
}
delete _wallList[i];
_wallList.remove(i);
}
}
}
}
_bulletList[q]->animation();
}
}
}
}
示例9: destroyTank
void TankFactory::updateAllTankStatus(float time){
for (TankIterator t = tankList.begin(); t != tankList.end();){ //t shouldn't be increment in for loop, may cause program crashes.
Tank* tank = *t;
tank->update(time);
if (tank->ifExplodeFinished())
{
if(tank->getType() != TANK_PLAYER){
//delete tank
destroyTank(tank);
Tank* tmp = tank;
t++;
tankList.remove(tmp);
}else{
destroyTank(tank);
Tank* tmp = tank;
t++;
tankList.remove(tmp);
rebornPlayer();
}
}
else
{
t++;
}
}
}
示例10: safeQueueEvent
void KamikazeAnt::attack()
{
Actor* pActor = ActorHandler::getInstance()->getActor(mpsPlayerInfo->getPlayerId());
if(pActor != NULL && (pActor->getPosition() - mPosition).longerThan(Enemy::getRange(), false) == false && mId.isOwner())
{
mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
//check if cooldownCounter is higher than weaponCooldown
if(mCooldownCounter > 1.0f)
{
Tank *pTank = dynamic_cast<Tank*>(pActor);
Driver *pDriver = dynamic_cast<Driver*>(pActor);
mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);
if(pTank != NULL)
{
safeQueueEvent(EventDataPtr(myNew EvtData_From_KamikazeAntExplode(this->getKey())));
pTank->reduceHp(50);
this->reduceHp(200);
}
else if(pDriver != NULL)
{
safeQueueEvent(EventDataPtr(myNew EvtData_From_KamikazeAntExplode(this->getKey())));
pDriver->reduceHp(50);
this->reduceHp(200);
}
}
}
}
示例11: IsCollide
bool Block::IsCollide(Object* obj)
{
if (obj->type() == OBJ_TANK)
{
Tank* pTank = dynamic_cast<Tank*>(obj);
Point pt = pTank->GetPosition();
LONG r = pTank->GetRadius();
for (int i = 0; i < hp/25 + 1; i++)
{
if (Collision(rc[i], pt, r))
return true;
}
}
else if (obj->type() == OBJ_BULLET)
{
Bullet* pBullet = dynamic_cast<Bullet*>(obj);
Point pt = pBullet->GetPosition();
LONG r = pBullet->GetRadius();
for (int i = 0; i < hp/25 + 1; i++)
{
if (Collision(rc[i], pt, r))
return true;
}
}
return false;
}
示例12: mySpecialKeyboard
void mySpecialKeyboard(int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT: //move to left
myTank.plusAngleWithX(gAngleTankDelta);
break;
case GLUT_KEY_RIGHT: //move to right
myTank.plusAngleWithX(-gAngleTankDelta);
break;
case GLUT_KEY_UP: //move to up
myTank.move(gMoveDelta);
break;
case GLUT_KEY_DOWN: //move to right
myTank.move(-gMoveDelta);
break;
case GLUT_KEY_F1: //view 1
gViewMode = 0;
break;
case GLUT_KEY_F2: //view 2
gViewMode = 1;
break;
case GLUT_KEY_F3: //view 3
gViewMode = 2;
break;
}
}
示例13: timeToCloseTank
int HydEngine::timeToCloseTank(int tstep)
{
Tank* closedTank = nullptr;
for (Node* node : network->nodes)
{
// ... check if node is a tank
if ( node->type() == Node::TANK )
{
// ... find the time to fill (or empty) the tank
Tank* tank = static_cast<Tank*>(node);
int t = tank->timeToVolume(tank->minVolume);
if ( t <= 0 ) t = tank->timeToVolume(tank->maxVolume);
// ... compare this time with current time step
if ( t > 0 && t < tstep )
{
tstep = t;
closedTank = tank;
}
}
}
if ( closedTank )
{
timeStepReason = " (Tank " + closedTank->name + " closed)";
}
return tstep;
}
示例14: safeQueueEvent
void Ant::attack()
{
//if enemy is in range of tank
Actor* pActor = ActorHandler::getInstance()->getActor(mpsPlayerInfo->getPlayerId());
if(pActor != NULL && (pActor->getPosition() - mPosition).longerThan(Enemy::getRange(), false) == false && mId.isOwner())
{
mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
//check if cooldownCounter is higher than weaponCooldown
if(mCooldownCounter > 1.0f)
{
Tank *pTank = dynamic_cast<Tank*>(pActor);
Driver *pDriver = dynamic_cast<Driver*>(pActor);
mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);
if(pTank != NULL)
{
safeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
pTank->reduceHp(15);
}
else if(pDriver != NULL)
{
safeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
pDriver->reduceHp(15);
}
}
}
//send event to have the enemy perform his attack animation
//send event to collision checking for a hit
}
示例15:
Tank *GameEngine::TankByID(int id)
{
for(int i=0; i<vehicles.size(); i++) {
Tank *t = vehicles.at(i);
if(id == t->ID())
return t;
}
return false;
}