mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 01:37:36 +07:00
Fixed lightning not rendering
This commit is contained in:
@ -193,7 +193,7 @@ public class TurretBullets {
|
||||
|
||||
@Override
|
||||
public void init(Bullet b) {
|
||||
new Lightning(b.team, hiteffect, damage, b.x, b.y, b.angle(), 30).add();
|
||||
Lightning.create(b.team, hiteffect, Palette.lancerLaser, damage, b.x, b.y, b.angle(), 30);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.BelowLiquidEffect;
|
||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity;
|
||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
||||
@ -40,7 +40,6 @@ import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.graphics.*;
|
||||
import io.anuke.ucore.modules.RendererModule;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
@ -543,33 +542,33 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
//TODO draw health bars
|
||||
|
||||
/*
|
||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||
|
||||
//draw entity health bars
|
||||
for(BaseUnit entity : enemyGroup.all()){
|
||||
drawHealth(entity);
|
||||
for(EntityGroup<BaseUnit> group : unitGroups){
|
||||
drawHealth(group);
|
||||
}
|
||||
|
||||
for(Player player : playerGroup.all()){
|
||||
if(!player.isDead()) drawHealth(player);
|
||||
}
|
||||
}*/
|
||||
drawHealth(playerGroup);
|
||||
}
|
||||
}
|
||||
|
||||
void drawHealth(SyncEntity dest){
|
||||
float x = dest.getDrawPosition().x;
|
||||
float y = dest.getDrawPosition().y;
|
||||
if(dest instanceof Player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){
|
||||
drawHealth((int) x, (int) y - 7f, dest.health, dest.maxhealth);
|
||||
void drawHealth(EntityGroup<? extends Unit> group){
|
||||
for(Unit e : group.all()){
|
||||
drawHealth(e);
|
||||
}
|
||||
}
|
||||
|
||||
void drawHealth(Unit unit){
|
||||
float x = unit.getDrawPosition().x;
|
||||
float y = unit.getDrawPosition().y;
|
||||
if(unit instanceof Player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){
|
||||
drawHealth((int) x, (int) y - 7f, unit.health, unit.maxhealth);
|
||||
}else{
|
||||
drawHealth(x, y - 7f, dest.health, dest.maxhealth);
|
||||
drawHealth(x, y - 7f, unit.health, unit.maxhealth);
|
||||
}
|
||||
}
|
||||
|
||||
void drawHealth(float x, float y, float health, float maxhealth){
|
||||
drawBar(Color.RED, x, y, health / maxhealth);
|
||||
drawBar(Color.SCARLET, x, y, health / maxhealth);
|
||||
}
|
||||
|
||||
//TODO optimize!
|
||||
@ -613,7 +612,8 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
public void clampScale(){
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.scl(2)), Math.round(Unit.dp.scl((5))));
|
||||
float s = io.anuke.ucore.scene.ui.layout.Unit.dp.scl(1f);
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(s*2), Math.round(s*5));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,9 +29,7 @@ public class DamageArea{
|
||||
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i ++){
|
||||
int branches = 5 + Mathf.clamp((int)(power/30), 1, 20);
|
||||
Timers.run(i*2f + Mathf.random(4f), () -> {
|
||||
Lightning l = new Lightning(Team.none, Fx.none, 3, x, y, Mathf.random(360f), branches + Mathf.range(2));
|
||||
l.color = Colors.get("power");
|
||||
l.add();
|
||||
Lightning.create(Team.none, Fx.none, Colors.get("power"), 3, x, y, Mathf.random(360f), branches + Mathf.range(2));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,16 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@ -17,32 +21,35 @@ import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Lightning extends TimedEntity {
|
||||
public class Lightning extends TimedEntity implements Poolable{
|
||||
private static Array<SolidEntity> entities = new Array<>();
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static float angle;
|
||||
private static float wetDamageMultiplier = 2;
|
||||
|
||||
private Array<Vector2> lines = new Array<>();
|
||||
private float angle;
|
||||
|
||||
public Color color = Palette.lancerLaser;
|
||||
|
||||
public Lightning(Team team, Effect effect, int damage, float x, float y, float targetAngle, int length){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.lifetime = 10f;
|
||||
this.angle = targetAngle;
|
||||
public static void create(Team team, Effect effect, Color color, int damage, float x, float y, float targetAngle, int length){
|
||||
Lightning l = Pools.obtain(Lightning.class);
|
||||
|
||||
l.x = x;
|
||||
l.y = y;
|
||||
l.lifetime = 10f;
|
||||
l.color = color;
|
||||
|
||||
float step = 3f;
|
||||
float range = 6f;
|
||||
float attractRange = 20f;
|
||||
|
||||
angle = targetAngle;
|
||||
entities.clear();
|
||||
|
||||
Units.getNearbyEnemies(team, rect, entities::add);
|
||||
|
||||
for(int i = 0; i < length; i ++){
|
||||
lines.add(new Vector2(x, y));
|
||||
l.lines.add(new Vector2(x, y));
|
||||
|
||||
float fx = x, fy = y;
|
||||
float x2 = x + Angles.trnsx(angle, step);
|
||||
@ -72,14 +79,24 @@ public class Lightning extends TimedEntity {
|
||||
});
|
||||
|
||||
if(Mathf.chance(0.1)){
|
||||
new Lightning(team, effect, damage, x2, y2, angle + Mathf.range(100f), length/3).add();
|
||||
Lightning.create(team, effect, color, damage, x2, y2, angle + Mathf.range(100f), length/3);
|
||||
}
|
||||
|
||||
x = x2;
|
||||
y = y2;
|
||||
}
|
||||
|
||||
lines.add(new Vector2(x, y));
|
||||
l.lines.add(new Vector2(x, y));
|
||||
l.add();
|
||||
}
|
||||
|
||||
/**For pooling use only. Do not call directly!*/
|
||||
public Lightning(){}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
color = Palette.lancerLaser;
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,4 +112,9 @@ public class Lightning extends TimedEntity {
|
||||
}
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.bulletGroup);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user