本文整理汇总了C++中World::GetObjectFromId方法的典型用法代码示例。如果您正苦于以下问题:C++ World::GetObjectFromId方法的具体用法?C++ World::GetObjectFromId怎么用?C++ World::GetObjectFromId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World::GetObjectFromId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleHit
void Civilian::HandleHit(World & world, Uint8 x, Uint8 y, Object & projectile){
Hittable::HandleHit(*this, world, x, y, projectile);
if(projectile.healthdamage == 0){
return;
}
if(state == DYINGFORWARD || state == DYINGBACKWARD || state == DEAD || state == DYINGEXPLODE){
return;
}
float xpcnt = -((x - 50) / 50.0) * (mirrored ? -1 : 1);
if(x < 50){
state = DYINGFORWARD;
}else{
state = DYINGBACKWARD;
}
if((xpcnt < 0 && xv < 0) || (xpcnt > 0 && xv > 0)){
xv = abs(xv) * xpcnt;
}else{
xv = speed * xpcnt;
}
switch(projectile.type){
case ObjectTypes::BLASTERPROJECTILE:
case ObjectTypes::LASERPROJECTILE:{
if(rand() % 2 == 0){
EmitSound(world, world.resources.soundbank["strike03.wav"], 96);
}else{
EmitSound(world, world.resources.soundbank["strike04.wav"], 96);
}
}break;
case ObjectTypes::ROCKETPROJECTILE:{
state = DYINGEXPLODE;
draw = false;
for(int i = 0; i < 6; i++){
BodyPart * bodypart = (BodyPart *)world.CreateObject(ObjectTypes::BODYPART);
if(bodypart){
bodypart->suitcolor = suitcolor;
bodypart->x = Civilian::x;
bodypart->y = Civilian::y - 50;
bodypart->type = i;
bodypart->xv += (abs(xv) * 2) * xpcnt;
if(i == 0){
bodypart->xv = 0;
bodypart->yv = -20;
}
}
}
}break;
}
Object * owner = world.GetObjectFromId(projectile.ownerid);
if(owner && owner->type == ObjectTypes::PLAYER){
Player * player = static_cast<Player *>(owner);
Peer * peer = player->GetPeer(world);
if(peer){
peer->stats.civilianskilled++;
}
}
state_i = 0;
}
示例2: Tick
void FlamerProjectile::Tick(World & world){
for(int i = 0; i < plumecount; i++){
if(!plumeids[i]){
Plume * plume = (Plume *)world.CreateObject(ObjectTypes::PLUME);
if(plume){
plume->type = 4;
plume->xv = (rand() % 17) - 8 + (xv * 8);
plume->yv = (rand() % 17) - 8 + (yv * 8);
plume->SetPosition(x + (xv * (i * 1)), y + (yv * (i * 1)));
plumeids[i] = plume->id;
plume->state_i = i;
}
}
}
Object * object = 0;
Platform * platform = 0;
if(TestCollision(*this, world, &platform, &object)){
float xn = 0, yn = 0;
if(platform){
platform->GetNormal(x, y, &xn, &yn);
for(int i = 0; i < plumecount; i++){
Plume * plume = (Plume *)world.GetObjectFromId(plumeids[i]);
if(plume){
plume->xv /= 3;
plume->yv /= 3;
//world->MarkDestroyObject(plumeids[i]);
}
}
}
//world->MarkDestroyObject(id);
}
res_index = state_i;
if(state_i >= 14){
world.MarkDestroyObject(id);
}
state_i++;
}
示例3: Tick
//.........这里部分代码省略.........
if(plume){
plume->type = 4;
/*plume->xv = (rand() % 17) - 8;
plume->yv = (rand() % 17) - 8;
plume->xv = (xn * abs(plume->xv)) + (rand() % 33) - 16;
plume->yv = (yn * abs(plume->yv)) + (rand() % 33) - 16;*/
float angle = (i / float(numplumes)) * (2 * 3.14);
angle += anglen;
plume->xv = (sin(angle)) * 15;
plume->yv = (cos(angle)) * 15;
if(xn || yn){
plume->xv = (xn * abs(plume->xv)) + (rand() % 17) - 8;
plume->yv = (yn * abs(plume->yv)) + (rand() % 17) - 8;
}
plume->SetPosition(x, y);
Plume * plume2 = (Plume *)world.CreateObject(ObjectTypes::PLUME);
if(plume2){
plume2->type = 4;
plume2->xv = plume->xv + (rand() % 7) - 3;
plume2->yv = plume->yv + (rand() % 7) - 3;
plume2->SetPosition(x, y);
}
}
}
std::vector<Uint8> types;
types.push_back(ObjectTypes::PLAYER);
types.push_back(ObjectTypes::GUARD);
types.push_back(ObjectTypes::ROBOT);
types.push_back(ObjectTypes::CIVILIAN);
types.push_back(ObjectTypes::FIXEDCANNON);
types.push_back(ObjectTypes::WALLDEFENSE);
types.push_back(ObjectTypes::TECHSTATION);
Object * owner = world.GetObjectFromId(ownerid);
Uint16 teamid = 0;
bool issecurity = false;
if(owner){
switch(owner->type){
case ObjectTypes::PLAYER:{
Player * player = static_cast<Player *>(owner);
Team * team = player->GetTeam(world);
if(team){
teamid = team->id;
}
}break;
case ObjectTypes::ROBOT:{
Robot * robot = static_cast<Robot *>(owner);
teamid = robot->virusplanter;
issecurity = world.IsSecurity(*robot);
}break;
case ObjectTypes::GUARD:{
issecurity = true;
}break;
}
}
std::vector<Object *> objects = world.TestAABB(x - 30, y - 30, x + 30, y + 30, types, ownerid, teamid);
for(std::vector<Object *>::iterator it = objects.begin(); it != objects.end(); it++){
if(!object || (object && (*it)->id != object->id)){
if(!issecurity || (issecurity && !world.IsSecurity(*(*it)))){ // prevents robots/rocket guards from doing slash damage to other security
Object damageprojectile(ObjectTypes::ROCKETPROJECTILE);
damageprojectile.healthdamage = healthdamage;
damageprojectile.shielddamage = shielddamage;
damageprojectile.ownerid = ownerid;
(*it)->HandleHit(world, 50, 50, damageprojectile);
}
}