Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double dist = e.distanceTo(x, y, z) / r;
- double sp = level.getSeenPercent(center, e.bb);
- double pow = (1 - dist) * sp;
- e.hurt(DamageSource.explosion, (int) ((pow * pow + pow) / 2 * 8 * r + 1));
- public float getSeenPercent(Vec3 center, AABB bb) {
- double xs = 1.0 / ((bb.x1 - bb.x0) * 2 + 1);
- double ys = 1.0 / ((bb.y1 - bb.y0) * 2 + 1);
- double zs = 1.0 / ((bb.z1 - bb.z0) * 2 + 1);
- int hits = 0;
- int count = 0;
- for (float xx = 0; xx <= 1; xx += xs)
- for (float yy = 0; yy <= 1; yy += ys)
- for (float zz = 0; zz <= 1; zz += zs) {
- double x = bb.x0 + (bb.x1 - bb.x0) * xx;
- double y = bb.y0 + (bb.y1 - bb.y0) * yy;
- double z = bb.z0 + (bb.z1 - bb.z0) * zz;
- if (clip(Vec3.getPool().allocate(x, y, z), center) == null) hits++;
- count++;
- }
- return hits / (float) count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement