Bugfixes / Tutorial cleanup

This commit is contained in:
Anuken
2020-11-21 15:50:44 -05:00
parent 96b55c6b1c
commit b09dc47aad
8 changed files with 110 additions and 80 deletions

View File

@@ -25,6 +25,7 @@ public class Damage{
private static Rect rect = new Rect();
private static Rect hitrect = new Rect();
private static Vec2 tr = new Vec2();
private static Seq<Unit> units = new Seq<>();
private static GridBits bits = new GridBits(30, 30);
private static IntQueue propagation = new IntQueue();
private static IntSet collidedBlocks = new IntSet();
@@ -117,14 +118,16 @@ public class Damage{
Building tile = world.build(cx, cy);
boolean collide = tile != null && collidedBlocks.add(tile.pos());
if(collide && tile.team != team && tile.collide(hitter)){
tile.collision(hitter);
hitter.type.hit(hitter, tile.x, tile.y);
}
if(hitter.damage > 0){
if(collide && tile.team != team && tile.collide(hitter)){
tile.collision(hitter);
hitter.type.hit(hitter, tile.x, tile.y);
}
//try to heal the tile
if(collide && hitter.type.collides(hitter, tile)){
hitter.type.hitTile(hitter, tile, 0f, false);
//try to heal the tile
if(collide && hitter.type.collides(hitter, tile)){
hitter.type.hitTile(hitter, tile, tile.health, false);
}
}
};
@@ -161,20 +164,27 @@ public class Damage{
rect.height += expand * 2;
Cons<Unit> cons = e -> {
if(!e.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround)) return;
e.hitbox(hitrect);
Vec2 vec = Geometry.raycastRect(x, y, x2, y2, hitrect.grow(expand * 2));
if(vec != null){
if(vec != null && hitter.damage > 0){
effect.at(vec.x, vec.y);
e.collision(hitter, vec.x, vec.y);
hitter.collision(e, vec.x, vec.y);
}
};
Units.nearbyEnemies(team, rect, cons);
units.clear();
Units.nearbyEnemies(team, rect, u -> {
if(u.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround)){
units.add(u);
}
});
units.sort(u -> u.dst2(hitter));
units.each(cons);
}
/**

View File

@@ -1,5 +1,7 @@
package mindustry.entities.bullet;
import arc.math.geom.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
@@ -15,36 +17,54 @@ public class RailBulletType extends BulletType{
/** Multiplier of damage decreased per health pierced. */
public float pierceDamageFactor = 1f;
public float length = 100f;
public float updateEffectSeg = 20f;
public RailBulletType(){
pierceBuilding = true;
pierce = true;
reflectable = false;
hitEffect = Fx.none;
despawnEffect = Fx.none;
collides = false;
lifetime = 1f;
}
@Override
public float range(){
return length;
}
void handle(Bullet b, Posc pos, float initialHealth){
float sub = initialHealth*pierceDamageFactor;
if(sub >= b.damage){
//cause a despawn
b.remove();
if(b.damage <= 0){
b.fdata = Math.min(b.fdata, b.dst(pos));
return;
}
if(b.damage > 0){
pierceEffect.at(pos.getX(), pos.getY(), b.rotation());
hitEffect.at(pos.getX(), pos.getY());
}
//subtract health from each consecutive pierce
b.damage -= Math.min(b.damage, sub);
if(b.damage > 0){
pierceEffect.at(pos.getX(), pos.getY(), b.rotation());
}
hitEffect.at(pos.getX(), pos.getY());
}
@Override
public void update(Bullet b){
if(b.timer(1, 0.9f)){
updateEffect.at(b.x, b.y, b.rotation());
public void init(Bullet b){
super.init(b);
b.fdata = length;
Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), length, false);
float resultLen = b.fdata;
Vec2 nor = Tmp.v1.set(b.vel).nor();
for(float i = 0; i <= resultLen; i += updateEffectSeg){
updateEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation());
}
}