本文整理汇总了C++中Projectile::getx方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::getx方法的具体用法?C++ Projectile::getx怎么用?C++ Projectile::getx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projectile
的用法示例。
在下文中一共展示了Projectile::getx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: perform_collision_bullet
void CollisionManager::perform_collision_bullet(vector<WorldObject*> victims,
vector<Projectile*> bullets) {
vector<WorldObject*>::iterator victims_it;
vector<Projectile*>::iterator bullets_it;
if (bullets.size() < 1) {
return;
}
if (victims.size() < 1) {
return;
}
for (victims_it = victims.begin(); victims_it != victims.end(); victims_it++) {
WorldObject* victim = (*victims_it);
if (!victim->getcollisionable()) {
continue;
}
// check collision for each bullet
for (bullets_it = bullets.begin(); bullets_it != bullets.end(); bullets_it++) {
Projectile* bullet = (*bullets_it);
if ((bullet->getx() >= (victim->getx() - MAX_DISTANCE_FOR_COLLISION))
&& (bullet->gety() >= (victim->gety() - MAX_DISTANCE_FOR_COLLISION))) {
int bullet_min_x = bullet->getx();
int bullet_min_y = bullet->gety();
int bullet_max_x = bullet->getx() + bullet->getwidth();
int bullet_max_y = bullet->gety() + bullet->getheight();
int victim_min_x = victim->getx();
int victim_min_y = victim->gety();
int victim_max_x = victim->getx() + victim->getsurface()->w;
int victim_max_y = victim->gety() + victim->getsurface()->h;
if (((bullet_max_x > victim_min_x) &&
(bullet_max_y > victim_min_y) &&
(bullet_min_x < victim_max_x) &&
(bullet_min_y < victim_max_y)) ||
(bullet_min_x < 0 ||
bullet_max_x > DrawEngine::get_screen_width() ||
bullet_min_y < 0 ||
bullet_max_y > DrawEngine::get_screen_height())) {
// remove the bullet
GarbageCollector::add_deletion_queue(bullet);
}
}
if ((bullet->getx() > (bullet->getorgx() + 300)) ||
(bullet->gety() > (bullet->getorgy() + 300))) {
// if the bullet has been fired over 300 px, lets delete
GarbageCollector::add_deletion_queue(bullet);
}
}
}
}
示例2: perform_bullet_hit
void CollisionManager::perform_bullet_hit(vector<Zombie*> zombies, vector<Projectile*> bullets) {
vector<Zombie*>::iterator zombie_it;
vector<Projectile*>::iterator bullets_it;
bool hit = false;
for (zombie_it = zombies.begin(); zombie_it != zombies.end(); zombie_it++) {
Zombie* zombie = (*zombie_it);
if (!zombie->getcollisionable()) {
continue;
}
if (!zombie->getrevealed() || zombie->gethidden()) {
continue;
}
// check collision for each bullet
for (bullets_it = bullets.begin(); bullets_it != bullets.end(); bullets_it++) {
Projectile* bullet = (*bullets_it);
if ((bullet->getx() >= (zombie->getx() - MAX_DISTANCE_FOR_COLLISION))
&& (bullet->gety() >= (zombie->gety() - MAX_DISTANCE_FOR_COLLISION))
&& (bullet->gety() <= (zombie->gety() + zombie->getsurface()->h))
&& (bullet->getx() <= (zombie->getx() + zombie->getsurface()->w))) {
int bullet_min_x = bullet->getx();
int bullet_min_y = bullet->gety();
int bullet_max_x = bullet->getx() + bullet->getwidth();
int bullet_max_y = bullet->gety() + bullet->getheight();
int zombie_min_x = zombie->getx();
int zombie_min_y = zombie->gety();
int zombie_max_x = zombie->getx() + zombie->getsurface()->w;
int zombie_max_y = zombie->gety() + zombie->getsurface()->h;
if ((bullet_min_x > zombie_min_x) &&
(bullet_max_x < zombie_max_x) &&
(bullet_min_y > zombie_min_y) &&
(bullet_max_y < zombie_max_y)) {
hit = true;
}
}
if (hit) {
// remove the bullet
if (zombie->getrevealed() && !zombie->gethidden()) {
zombie->setdamage(bullet->getdamage());
if (zombie->gethealth() <= 0) {
GarbageCollector::add_deletion_queue(zombie);
}
GarbageCollector::add_deletion_queue(bullet);
}
hit = false;
}
}
zombie = 0;
}
}