本文整理汇总了C++中PhysicsObject::get_type方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsObject::get_type方法的具体用法?C++ PhysicsObject::get_type怎么用?C++ PhysicsObject::get_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsObject
的用法示例。
在下文中一共展示了PhysicsObject::get_type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generate_next_hit_packet
Packet::PlayerHit* StandardGun::generate_next_hit_packet(Packet::PlayerHit* p, Player* shooter) {
if (m_hit_data.empty()) {
return NULL;
}
bool found_player = false;
while (!m_hit_data.empty()) {
vector<HitData> nextshot = m_hit_data.back();
m_hit_data.pop_back();
if (nextshot.empty()) {
continue;
}
m_objects_penetrated = 0;
m_current_damage = m_damage;
while (!found_player && !nextshot.empty()) {
// Don't go over max penetration depth.
if (m_objects_penetrated > m_max_penetration) {
return NULL;
}
if (m_current_damage <= 0) {
return NULL;
}
HitData nextdata = nextshot.back();
nextshot.pop_back();
b2Body* body = nextdata.fixture->GetBody();
PhysicsObject* userdata = static_cast<PhysicsObject*>(body->GetUserData());
if (userdata->get_type() == PhysicsObject::MAP_OBJECT) {
MapObject* mapobj = static_cast<MapObject*>(userdata);
if (!mapobj->is_shootable()) {
// Just ignore this object and keep going - it's not actually hitting it.
continue;
}
}
m_objects_penetrated++;
if (userdata->get_type() != PhysicsObject::PLAYER) {
m_current_damage = m_current_damage * m_penetrates_walls;
continue;
}
float actualdamage = m_current_damage - m_damage_degradation * (m_max_range * nextdata.fraction);
if (actualdamage <= 0) {
actualdamage = 0;
}
p->shooter_id = shooter->get_id();
p->weapon_id = get_id();
Player* hit_player = static_cast<Player*>(userdata);
p->shot_player_id = hit_player->get_id();
p->has_effect = hit_player->is_frozen() ? false : true;
std::stringstream out;
out << m_last_fired_dir << " " << nextdata.point.x << " " << nextdata.point.y << " " << actualdamage;
p->extradata = out.str();
hit(static_cast<Player*>(userdata), shooter, p);
m_current_damage = m_current_damage * m_penetrates_players;
found_player = true;
return p;
}
}
ASSERT(!found_player);
return NULL;
}
示例2: fire
Packet::WeaponDischarged* StandardGun::fire(b2World* physics, Player& player, Point start, float direction, Packet::WeaponDischarged* packet) {
m_last_fired_time = get_ticks();
m_last_fired_dir = direction;
b2Vec2 end_point;
m_hit_data.clear();
// Recharge ammo, if applicable
if (m_total_ammo) {
m_current_ammo = get_current_ammo();
if (m_current_ammo == 0) {
// Out of ammo
return NULL;
}
--m_current_ammo;
}
float currdirection = direction - m_angle/2.0f;
for (int i = 0; i < m_nbr_projectiles; i++) {
float endx = start.x + m_max_range * cos(currdirection);
float endy = start.y + m_max_range * sin(currdirection);
m_objects_penetrated = 0;
m_current_damage = m_damage;
m_hit_data.push_back(vector<HitData>());
physics->RayCast(this, b2Vec2(to_physics(start.x), to_physics(start.y)), b2Vec2(to_physics(endx), to_physics(endy)));
if (!m_hit_data.back().empty()) {
sort(m_hit_data.back().begin(), m_hit_data.back().end(), compare_hit_data);
}
// Find the end point of the middle projectile
if (i == m_nbr_projectiles/2) {
bool found = false;
vector<HitData>::iterator thishit = m_hit_data.back().end();
// Discard invalid collisions until we find the closest good collision
while (!found) {
thishit--;
b2Body* body = (*thishit).fixture->GetBody();
if (body->GetUserData() == NULL) {
continue;
}
PhysicsObject* hitobj = static_cast<PhysicsObject*>(body->GetUserData());
if ((*thishit).fixture->IsSensor()) {
continue;
}
if (hitobj->get_type() == PhysicsObject::MAP_OBJECT) {
MapObject* object = static_cast<MapObject*>(hitobj);
if (!object->is_shootable()) {
continue;
}
}
found = true;
}
end_point = (*thishit).point;
}
currdirection += m_angle/(m_nbr_projectiles - 1.0);
}
packet->player_id = player.get_id();
packet->weapon_id = get_id();
packet->start_x = start.x;
packet->start_y = start.y;
packet->end_x = to_game(end_point.x);
packet->end_y = to_game(end_point.y);
packet->direction = direction;
was_fired(physics, player, direction);
return packet;
}