子弹出生点ok
This commit is contained in:
parent
2414f407a0
commit
b774a1030f
@ -60,7 +60,7 @@ static void SavePerfLog()
|
||||
|
||||
void App::Init(int argc, char* argv[])
|
||||
{
|
||||
#if 1
|
||||
#if 0
|
||||
{
|
||||
Vector2D v1(0.0f, 12.0f);
|
||||
v1.Rotate2(-45 / 360.f);
|
||||
|
@ -38,6 +38,22 @@ namespace MetaData
|
||||
return "";
|
||||
}
|
||||
|
||||
void Equip::Init()
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(i->bullet_born_offset(), strings, '|');
|
||||
for (auto& str : strings) {
|
||||
std::vector<std::string> strings2;
|
||||
a8::Split(str, strings2, ':');
|
||||
assert(strings2.size() == 2);
|
||||
bullet_born_offset.push_back(std::make_tuple(
|
||||
a8::XValue(strings2[0]).GetDouble(),
|
||||
a8::XValue(strings2[1]).GetDouble()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Drop::Init()
|
||||
{
|
||||
std::vector<std::string> item_list;
|
||||
|
@ -39,6 +39,10 @@ namespace MetaData
|
||||
struct Equip
|
||||
{
|
||||
const metatable::Equip* i = nullptr;
|
||||
|
||||
std::vector<std::tuple<float, float>> bullet_born_offset;
|
||||
|
||||
void Init();
|
||||
};
|
||||
|
||||
struct Player
|
||||
|
@ -124,6 +124,7 @@ private:
|
||||
}
|
||||
MetaData::Equip& item = a8::FastAppend(equip_list);
|
||||
item.i = &meta;
|
||||
item.Init();
|
||||
equip_hash[item.i->id()] = &item;
|
||||
if (meta._inventory_slot() > -1) {
|
||||
equip_slot_hash[meta._inventory_slot()] = &item;
|
||||
|
@ -269,15 +269,6 @@ void Player::Shot()
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2D bullet_born_offset = Vector2D(0, 12.0f);
|
||||
#if 0
|
||||
Vector2D bullet_born_dir = Vector2D(0, 12.0f);
|
||||
bullet_born_dir.Normalize();
|
||||
bullet_born_offset = bullet_born_dir * bullet_born_offset.Norm();
|
||||
#else
|
||||
bullet_born_offset.Rotate2(attack_dir.Angle(Vector2D::UP));
|
||||
#endif
|
||||
Vector2D bullet_born_pos = pos + bullet_born_offset;
|
||||
{
|
||||
cs::MFShot* shot = room->frame_data.shots.Add();
|
||||
shot->set_player_id(entity_uniid);
|
||||
@ -285,30 +276,35 @@ void Player::Shot()
|
||||
shot->set_offhand(true);
|
||||
shot->set_bullskin(10001);
|
||||
}
|
||||
{
|
||||
cs::MFBullet* bullet = room->frame_data.bullets.Add();
|
||||
bullet->set_player_id(entity_uniid);
|
||||
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
|
||||
bullet_born_pos.ToPB(bullet->mutable_pos());
|
||||
attack_dir.ToPB(bullet->mutable_dir());
|
||||
bullet->set_bulletskin(10001);
|
||||
bullet->set_gun_id(curr_weapon->meta->i->id());
|
||||
bullet->set_fly_distance(fly_distance);
|
||||
}
|
||||
{
|
||||
Bullet* bullet = new Bullet();
|
||||
bullet->player = this;
|
||||
bullet->room = room;
|
||||
bullet->gun_meta = curr_weapon->meta;
|
||||
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
|
||||
bullet->pos = bullet_born_pos;
|
||||
bullet->dir = attack_dir;
|
||||
bullet->born_pos = bullet_born_pos;
|
||||
bullet->born_dir = attack_dir;
|
||||
bullet->fly_distance = fly_distance;
|
||||
bullet->entity_uniid = bullet->room->AllocUniid();
|
||||
bullet->Initialize();
|
||||
room->AddBullet(bullet);
|
||||
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
|
||||
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
|
||||
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
|
||||
Vector2D bullet_born_pos = pos + bullet_born_offset;
|
||||
{
|
||||
cs::MFBullet* bullet = room->frame_data.bullets.Add();
|
||||
bullet->set_player_id(entity_uniid);
|
||||
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
|
||||
bullet_born_pos.ToPB(bullet->mutable_pos());
|
||||
attack_dir.ToPB(bullet->mutable_dir());
|
||||
bullet->set_bulletskin(10001);
|
||||
bullet->set_gun_id(curr_weapon->meta->i->id());
|
||||
bullet->set_fly_distance(fly_distance);
|
||||
}
|
||||
{
|
||||
Bullet* bullet = new Bullet();
|
||||
bullet->player = this;
|
||||
bullet->room = room;
|
||||
bullet->gun_meta = curr_weapon->meta;
|
||||
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
|
||||
bullet->pos = bullet_born_pos;
|
||||
bullet->dir = attack_dir;
|
||||
bullet->born_pos = bullet_born_pos;
|
||||
bullet->born_dir = attack_dir;
|
||||
bullet->fly_distance = fly_distance;
|
||||
bullet->entity_uniid = bullet->room->AllocUniid();
|
||||
bullet->Initialize();
|
||||
room->AddBullet(bullet);
|
||||
}
|
||||
}
|
||||
--curr_weapon->ammo;
|
||||
int slot_id = curr_weapon->meta->i->_inventory_slot();
|
||||
|
@ -104,23 +104,7 @@ void Vector2D::Rotate(float angle)
|
||||
y = v[1];
|
||||
}
|
||||
|
||||
void Vector2D::Rotate2(float angle)
|
||||
{
|
||||
#if 1
|
||||
Eigen::Vector3f v(x, y, 0);
|
||||
v = Eigen::AngleAxisf(angle * 3.1415926f, Eigen::Vector3f::UnitZ()) * v;
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
#else
|
||||
float newx = x * cos(angle) - y * sin(angle);
|
||||
float newy = x * sin(angle) + y * cos(angle);
|
||||
x = newx;
|
||||
y = newy;
|
||||
int i = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
float Vector2D::Angle(const Vector2D& b)
|
||||
float Vector2D::CalcAngle(const Vector2D& b)
|
||||
{
|
||||
float a1 = acos(Dot(b) / Norm() / b.Norm());
|
||||
float a2 = atan2(y, x);
|
||||
@ -132,7 +116,7 @@ float Vector2D::Angle(const Vector2D& b)
|
||||
if (at_right_side) {
|
||||
a1 = -a1;
|
||||
}
|
||||
return a1 / 3.14;
|
||||
return a1 / 3.1415926f;
|
||||
// return a3 / 360.0f;
|
||||
#endif
|
||||
}
|
||||
|
@ -26,8 +26,7 @@ struct Vector2D
|
||||
void FromPB(const cs::MFVector2D* pb_obj);
|
||||
void Normalize();
|
||||
void Rotate(float angle);
|
||||
void Rotate2(float angle);
|
||||
float Angle(const Vector2D& b);
|
||||
float CalcAngle(const Vector2D& b);
|
||||
|
||||
bool operator == (const Vector2D& b) const;
|
||||
Vector2D operator + (const Vector2D& b) const;
|
||||
|
@ -66,6 +66,7 @@ message Equip
|
||||
optional int32 energy = 17; //能量值
|
||||
optional int32 volume = 19; //装备容量
|
||||
optional int32 bullet_rad = 20; //子弹半径
|
||||
optional string bullet_born_offset = 30; //子弹出生偏移
|
||||
|
||||
optional string inventory_slot = 21; //库存槽位
|
||||
optional int32 _inventory_slot = 22; //库存槽位
|
||||
|
Loading…
x
Reference in New Issue
Block a user