Major turret and bullet refactoring // New effects

This commit is contained in:
Anuken
2018-04-02 21:43:06 -04:00
parent 20b95fa063
commit 54d0cae450
41 changed files with 606 additions and 1100 deletions

View File

@@ -1,6 +1,5 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.BulletEntity;
@@ -13,14 +12,14 @@ public class Bullet extends BulletEntity{
public Timer timer = new Timer(3);
public Team team;
public Bullet(io.anuke.mindustry.entities.bullets.BulletType type, Unit owner, float x, float y, float angle){
public Bullet(BulletType type, Unit owner, float x, float y, float angle){
super(type, owner, angle);
this.type = type;
this.team = owner.team;
set(x, y);
}
public Bullet(io.anuke.mindustry.entities.bullets.BulletType type, Entity owner, Team team, float x, float y, float angle){
public Bullet(BulletType type, Entity owner, Team team, float x, float y, float angle){
super(type, owner, angle);
this.team = team;
this.type = type;

View File

@@ -1,19 +1,20 @@
package io.anuke.mindustry.entities.bullets;
package io.anuke.mindustry.entities;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.graphics.fx.Fx;
import io.anuke.mindustry.graphics.fx.BulletFx;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.BaseBulletType;
public abstract class BulletType extends BaseBulletType<Bullet>{
public Effect hitEffect = BulletFx.hit;
private BulletType(float speed, int damage){
public BulletType(float speed, int damage){
this.speed = speed;
this.damage = damage;
}
@Override
public void hit(Bullet b, float hitx, float hity){
Effects.effect(Fx.hit, hitx, hity);
Effects.effect(hitEffect, hitx, hity, b.angle());
}
}

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.content.Weapons;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.fx.ExplosionFx;
import io.anuke.mindustry.graphics.fx.Fx;

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.util.Mathf;

View File

@@ -1,4 +0,0 @@
package io.anuke.mindustry.entities.bullets;
public class TurretBullets {
}

View File

@@ -1,4 +0,0 @@
package io.anuke.mindustry.entities.bullets;
public class UnitBullets {
}

View File

@@ -1,4 +0,0 @@
package io.anuke.mindustry.entities.bullets;
public class WeaponBullets {
}

View File

@@ -1,118 +0,0 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.graphics.fx.BulletFx;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class EMP extends TimedEntity{
static final int maxTargets = 8;
static Array<Tile> array = new Array<>();
static Translator tr = new Translator();
int radius = 4;
int damage = 6;
Array<Tile> targets = new Array<>(maxTargets);
public EMP(float x, float y, int damage){
this.damage = damage;
set(x, y);
lifetime = 30f;
int worldx = Mathf.scl2(x, tilesize);
int worldy = Mathf.scl2(y, tilesize);
array.clear();
for(int dx = -radius; dx <= radius; dx ++){
for(int dy = -radius; dy <= radius; dy ++){
if(Vector2.dst(dx, dy, 0, 0) < radius){
Tile tile = world.tile(worldx + dx, worldy + dy);
if(tile != null && tile.block().destructible){
array.add(tile);
}
}
}
}
array.shuffle();
for(int i = 0; i < array.size && i < maxTargets; i ++){
Tile tile = array.get(i);
targets.add(tile);
if(tile != null && tile.block().hasPower){
tile.entity.power.amount = 0f;
tile.entity.damage((int)(damage*2f)); //extra damage
}
if(tile == null) continue;
//entity may be null here, after the block is dead!
Effects.effect(BulletFx.empspark, tile.worldx(), tile.worldy());
if(tile.entity != null) tile.entity.damage(damage);
}
}
@Override
public void drawOver(){
Draw.color(Color.SKY);
for(int i = 0; i < targets.size; i ++){
Tile target = targets.get(i);
drawLine(target.worldx(), target.worldy());
float rad = 5f*fract();
Draw.rect("circle", target.worldx(), target.worldy(), rad, rad);
}
for(int i = 0; i < 14 - targets.size; i ++){
tr.trns(Mathf.randomSeed(i + id*77)*360f, radius * tilesize);
drawLine(x + tr.x, y + tr.y);
}
Lines.stroke(fract()*2f);
Lines.poly(x, y, 34, radius * tilesize);
Draw.reset();
}
private void drawLine(float targetx, float targety){
int joints = 3;
float r = 3f;
float lastx = x, lasty = y;
for(int seg = 0; seg < joints; seg ++){
float dx = Mathf.range(r),
dy = Mathf.range(r);
float frac = (seg+1f)/joints;
float tx = (targetx - x)*frac + x + dx,
ty = (targety - y)*frac + y + dy;
drawLaser(lastx, lasty, tx, ty);
lastx = tx;
lasty = ty;
}
}
private void drawLaser(float x, float y, float x2, float y2){
Lines.stroke(fract() * 2f);
Lines.line(x, y, x2, y2);
}
}

View File

@@ -1,132 +0,0 @@
package io.anuke.mindustry.entities.effect;
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.ObjectSet;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.fx.BulletFx;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
public class TeslaOrb extends Entity{
private final static Rectangle rect = new Rectangle();
private final Array<Vector2> points = new Array<>();
private final ObjectSet<BaseUnit> hit = new ObjectSet<>();
private final int damage;
private final float range;
private final float lifetime = 30f;
private final Vector2 vector = new Vector2();
private final Team team;
private float life = 0f;
private float curx = x, cury = y;
private boolean done = false;
public TeslaOrb(Team team, float x, float y, float range, int damage){
set(x, y);
this.team = team;
this.damage = damage;
this.range = range;
}
void shock(){
float stopchance = 0.1f;
float shake = 3f;
int max = 7;
while(points.size < max){
if(Mathf.chance(stopchance)){
break;
}
rect.setSize(range*2f).setCenter(curx, cury);
Units.getNearbyEnemies(team, rect, entity -> {
if(!done && entity != null && entity.distanceTo(curx, cury) < range && !hit.contains((BaseUnit)entity)){
hit.add((BaseUnit)entity);
points.add(new Vector2(entity.x + Mathf.range(shake), entity.y + Mathf.range(shake)));
damageEnemy((BaseUnit)entity);
curx = entity.x;
cury = entity.y;
done = true;
}
});
}
if(points.size == 0){
remove();
}
}
void damageEnemy(BaseUnit enemy){
enemy.damage(damage);
Effects.effect(BulletFx.laserhit, enemy.x + Mathf.range(2f), enemy.y + Mathf.range(2f));
}
@Override
public void update(){
life += Timers.delta();
if(life >= lifetime){
remove();
}
}
@Override
public void drawOver(){
if(points.size == 0) return;
float range = 1f;
Vector2 previous = vector.set(x, y);
for(Vector2 enemy : points){
float x1 = previous.x + Mathf.range(range),
y1 = previous.y + Mathf.range(range),
x2 = enemy.x + Mathf.range(range),
y2 = enemy.y + Mathf.range(range);
Draw.color(Color.WHITE);
Draw.alpha(1f-life/lifetime);
Lines.stroke(3f - life/lifetime*2f);
Lines.line(x1, y1, x2, y2);
float rad = 7f - life/lifetime*5f;
Draw.rect("circle", x2, y2, rad, rad);
if(previous.epsilonEquals(x, y, 0.001f)){
Draw.rect("circle", x, y, rad, rad);
}
Draw.reset();
previous = enemy;
}
}
@Override
public void added(){
Timers.run(1f, ()->{
shock();
});
}
@Override
public float drawSize(){
return 200;
}
}

View File

@@ -1,7 +1,7 @@
package io.anuke.mindustry.entities.units;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.Team;
import io.anuke.ucore.entities.Entity;

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.TeamInfo.TeamData;
import io.anuke.mindustry.graphics.fx.Fx;
@@ -66,7 +65,7 @@ public class FlyingUnitType extends UnitType {
unit.velocity.add(vec); //TODO clamp it so it doesn't glitch out at low fps
if(unit.timer.get(timerReload, reload) && len < range){
shoot(unit, BulletType.shot, ang, 4f);
//shoot(unit, BulletType.shot, ang, 4f);
}
}

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.game.TeamInfo.TeamData;
@@ -99,7 +98,7 @@ public abstract class GroundUnitType extends UnitType{
}
if(unit.timer.get(timerReload, reload)){
shoot(unit, BulletType.shot, tr2.angle(), 4f);
//shoot(unit, BulletType.shot, tr2.angle(), 4f);
}
}
}

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.bullets.BulletType;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.graphics.fx.ExplosionFx;