WIP point laser turret

This commit is contained in:
Anuken
2022-06-23 20:57:22 -04:00
parent ac47d22ea1
commit be61b45d08
18 changed files with 202 additions and 61 deletions

View File

@@ -298,6 +298,39 @@ public class Damage{
units.each(cons);
}
/**
* Damages entities on a point.
* Only enemies of the specified team are damaged.
*/
public static void collidePoint(Bullet hitter, Team team, Effect effect, float x, float y){
if(hitter.type.collidesGround){
Building build = world.build(World.toTile(x), World.toTile(y));
if(build != null && hitter.damage > 0){
float health = build.health;
if(build.team != team && build.collide(hitter)){
build.collision(hitter);
hitter.type.hit(hitter, x, y);
}
//try to heal the tile
if(hitter.type.testCollision(hitter, build)){
hitter.type.hitTile(hitter, build, x, y, health, false);
}
}
}
Units.nearbyEnemies(team, rect.setCentered(x, y, 1f), u -> {
if(u.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround) && u.hittable()){
effect.at(x, y);
u.collision(hitter, x, y);
hitter.collision(u, x, y);
}
});
}
/**
* Casts forward in a line.
* @return the first encountered object.

View File

@@ -4,7 +4,7 @@ import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
/** Basic continuous bullet type that does not draw itself. Essentially abstract. */
/** Basic continuous (line) bullet type that does not draw itself. Essentially abstract. */
public class ContinuousBulletType extends BulletType{
public float length = 220f;
public float shake = 0f;

View File

@@ -0,0 +1,85 @@
package mindustry.entities.bullet;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
/** A continuous bullet type that only damages in a point. */
public class PointLaserBulletType extends BulletType{
public String sprite = "drill-laser";
public TextureRegion laser, laserEnd;
public Color color = Color.white;
public Effect beamEffect = Fx.colorTrail;
public float beamEffectInterval = 3f, beamEffectSize = 3.5f;
public float oscScl = 2f, oscMag = 0.3f;
public float damageInterval = 5f;
public float shake = 0f;
public PointLaserBulletType(){
removeAfterPierce = false;
speed = 0f;
despawnEffect = Fx.none;
shootEffect = Fx.none;
lifetime = 20f;
impact = true;
keepVelocity = false;
collides = false;
pierce = true;
hittable = false;
absorbable = false;
optimalLifeFract = 0.5f;
//just make it massive, users of this bullet can adjust as necessary
drawSize = 1000f;
}
@Override
public float estimateDPS(){
return damage * 100f / damageInterval * 3f;
}
@Override
public void load(){
super.load();
laser = Core.atlas.find(sprite);
laserEnd = Core.atlas.find(sprite + "-end");
}
@Override
public void draw(Bullet b){
super.draw(b);
Draw.color(color);
Drawf.laser(laser, laserEnd, b.x, b.y, b.aimX, b.aimY, b.fslope() * (1f - oscMag + Mathf.absin(Time.time, oscScl, oscMag)));
Draw.reset();
}
@Override
public void update(Bullet b){
super.update(b);
if(b.timer.get(0, damageInterval)){
Damage.collidePoint(b, b.team, hitEffect, b.aimX, b.aimY);
}
if(b.timer.get(1, beamEffectInterval)){
beamEffect.at(b.aimX, b.aimY, beamEffectSize * b.fslope(), hitColor);
}
if(shake > 0){
Effect.shake(shake, shake, b);
}
}
}