• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Tank类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Tank的典型用法代码示例。如果您正苦于以下问题:C++ Tank类的具体用法?C++ Tank怎么用?C++ Tank使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tank类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:GustavPersson,项目名称:miniature-dubstep,代码行数:26,代码来源:Ant.cpp


示例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;
    }
    
}
开发者ID:jarod68,项目名称:robot_tank_firmware,代码行数:34,代码来源:ManualTankState.cpp


示例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;
}
开发者ID:propanoid,项目名称:KLCFRT34,代码行数:35,代码来源:MyStrategy.cpp


示例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;
}
开发者ID:bradleyjeck,项目名称:epanet-dev,代码行数:26,代码来源:qualengine.cpp


示例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;
}
开发者ID:propanoid,项目名称:KLCFRT34,代码行数:35,代码来源:MyStrategy.cpp


示例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;
}
开发者ID:propanoid,项目名称:KLCFRT34,代码行数:32,代码来源:MyStrategy.cpp


示例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;
        }
    }
开发者ID:fferner,项目名称:carbudget,代码行数:33,代码来源:car.cpp


示例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();
			}
		}
	}
}
开发者ID:antonikon,项目名称:BattleCity,代码行数:60,代码来源:world.cpp


示例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++;
				}
		}
	}
开发者ID:robinbattle,项目名称:tankwar,代码行数:26,代码来源:TankFactory.cpp


示例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);
			}
		}

	}
}
开发者ID:GustavPersson,项目名称:miniature-dubstep,代码行数:30,代码来源:KamikazeAnt.cpp


示例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;
}
开发者ID:JoeKyuSung,项目名称:SGA48.2,代码行数:27,代码来源:Block.cpp


示例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;
	}
}
开发者ID:ArthurAlensky,项目名称:Tank,代码行数:26,代码来源:main.cpp


示例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;
}
开发者ID:OpenWaterAnalytics,项目名称:epanet-dev,代码行数:30,代码来源:hydengine.cpp


示例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
}
开发者ID:GustavPersson,项目名称:miniature-dubstep,代码行数:31,代码来源:Ant.cpp


示例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;
}
开发者ID:allangdc,项目名称:TheTank,代码行数:9,代码来源:gameengine.cpp


示例16: getTankValue

int getTankValue(int param, Node* node, double* value, Network* nw)
{
    double lcf = nw->ucf(Units::LENGTH);
    double vcf = lcf * lcf * lcf;
    *value = 0.0;
    if ( node->type() != Node::TANK ) return 0;
    Tank* tank = static_cast<Tank*>(node);
    switch (param)
    {
    case EN_TANKLEVEL:
        *value = (tank->head - tank->elev) * lcf;
        break;
    case EN_INITVOLUME:
        *value = tank->findVolume(tank->head) * vcf;
        break;
    case EN_MIXMODEL:
        *value = tank->mixingModel.type;
        break;
    case EN_MIXZONEVOL:
        *value = (tank->mixingModel.fracMixed * tank->maxVolume) * vcf;
        break;
    case EN_TANKDIAM:
        *value = tank->diameter * lcf;
        break;
    case EN_MINVOLUME:
        *value = tank->minVolume * vcf;
        break;
    case EN_VOLCURVE:
        if ( tank->volCurve )
        {
            string name = tank->volCurve->name;
            int index = nw->indexOf(Element::CURVE, name);
            *value = index;
            if ( index < 0 ) return 205;
        }
        else *value = -1.0;
        break;
    case EN_MINLEVEL:
        *value = (tank->minHead - tank->elev) * lcf;
        break;
    case EN_MAXLEVEL:
        *value = (tank->maxHead - tank->elev) * lcf;
        break;
    case EN_MIXFRACTION:
        *value = tank->mixingModel.fracMixed;
        break;
    case EN_TANK_KBULK:
        *value = tank->bulkCoeff ;
        break;
    case EN_TANKVOLUME:
        *value = tank->volume * vcf;
        break;
    default: return 203;
    }
    return 0;
}
开发者ID:OpenWaterAnalytics,项目名称:epanet-dev,代码行数:56,代码来源:datamanager.cpp


示例17: Tank

void Car::addNewTank(QDate date, unsigned int distance, double quantity, double price, bool full, unsigned int station, QString note)
{
    Tank *tank = new Tank(date, distance, quantity, price, full, station, CREATE_NEW_EVENT, note, this);
    _tanklist.append(tank);
    qSort(_tanklist.begin(), _tanklist.end(), sortTankByDistance);
    tank->save();
    emit nbtankChanged(_tanklist.count());
    emit consumptionChanged(this->consumption());
    emit maxdistanceChanged(this->maxdistance());
    emit tanksChanged();
}
开发者ID:loisspitz,项目名称:carbudget,代码行数:11,代码来源:car.cpp


示例18: Tank

Tank* Tank::createTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
    SpriteFrameCache* pCache = SpriteFrameCache::getInstance();
    pCache->addSpriteFramesWithFile("tank.plist");

    Tank* tank = new Tank();
    tank->initTankWithTankType(tankTypeName, tileMapInfo);
    tank->autorelease();

    return tank;
}
开发者ID:jypeitao,项目名称:Cocosdx-tk,代码行数:11,代码来源:Tank.cpp


示例19: keyboardSpecialHandler

void keyboardSpecialHandler(int key, int mooseX, int mooseY){
	/*if(key==GLUT_KEY_UP)//just for testing and fun
		myTank.barrelAngle++;
	else if(key==GLUT_KEY_DOWN)
		myTank.barrelAngle--;*/
	if(key==GLUT_KEY_LEFT)//just for testing and fun
		myTank.move(-1);
	else if(key==GLUT_KEY_RIGHT)
		myTank.move(1);
	glutPostRedisplay();
}
开发者ID:KdayTacos,项目名称:C-doodle,代码行数:11,代码来源:main.cpp


示例20: ForceModify

void ForceModify(Tank & self, Unit & u, double & xForce, double & yForce, double neg_c)
{
		//double absBearing = fabs( u.angle() );
		double absBearing = self.GetAngleTo( u );

		/* from 0 to 2*PI */

		double distance = self.GetDistanceTo( u );

		xForce += neg_c * ( sin(absBearing) / (distance * distance) );
		yForce += neg_c * ( cos(absBearing) / (distance * distance) );
}
开发者ID:propanoid,项目名称:KLCFRT34,代码行数:12,代码来源:MyStrategy.cpp



注:本文中的Tank类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TaoCrypt类代码示例发布时间:2022-05-31
下一篇:
C++ Talon类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap