Flying unit factory implementation, bugfixes
This commit is contained in:
@@ -38,6 +38,8 @@ public class Units {
|
||||
Unit[] result = {null};
|
||||
float[] cdist = {0};
|
||||
|
||||
rect.setSize(range*2f).setCenter(x, y);
|
||||
|
||||
getNearbyEnemies(team, rect, e -> {
|
||||
if (!predicate.test(e))
|
||||
return;
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.unitGroups;
|
||||
|
||||
public class BaseUnit extends Unit {
|
||||
@@ -71,7 +72,7 @@ public class BaseUnit extends Unit {
|
||||
|
||||
@Override
|
||||
public boolean collides(SolidEntity other){
|
||||
return (other instanceof Bullet) && !(((Bullet) other).owner instanceof BaseUnit);
|
||||
return other instanceof Bullet && state.teams.areEnemies((((Bullet) other).team), team);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,27 +2,47 @@ package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
|
||||
public class FlyingUnitType extends UnitType {
|
||||
private static Vector2 vec = new Vector2();
|
||||
|
||||
protected float boosterLength = 4.5f;
|
||||
|
||||
public FlyingUnitType(String name) {
|
||||
super(name);
|
||||
speed = 1f;
|
||||
speed = 0.2f;
|
||||
maxVelocity = 4f;
|
||||
drag = 0.01f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(BaseUnit unit) {
|
||||
super.update(unit);
|
||||
|
||||
unit.rotation = unit.velocity.angle();
|
||||
|
||||
if(unit.velocity.len() > 0.2f && unit.timer.get(timerBoost, 2f)){
|
||||
Effects.effect(Fx.dashsmoke, unit.x + Angles.trnsx(unit.rotation + 180f, boosterLength),
|
||||
unit.y + Angles.trnsy(unit.rotation + 180f, boosterLength));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(BaseUnit unit) {
|
||||
Draw.alpha(unit.hitTime / Unit.hitDuration);
|
||||
|
||||
Draw.rect(name, unit.x, unit.y, unit.rotation);
|
||||
Draw.rect(name, unit.x, unit.y, unit.rotation - 90);
|
||||
|
||||
Draw.alpha(1f);
|
||||
}
|
||||
@@ -30,10 +50,22 @@ public class FlyingUnitType extends UnitType {
|
||||
@Override
|
||||
public void behavior(BaseUnit unit) {
|
||||
vec.set(unit.target.x - unit.x, unit.target.y - unit.y);
|
||||
vec.setLength(speed);
|
||||
|
||||
unit.velocity.lerp(vec, 0.1f * Timers.delta()); //TODO clamp it so it doesn't glitch out at low fps
|
||||
float ang = vec.angle();
|
||||
|
||||
float circleLength = 40f;
|
||||
|
||||
if(vec.len() < circleLength){
|
||||
vec.rotate((circleLength-vec.len())/circleLength * 180f);
|
||||
}
|
||||
|
||||
vec.setLength(speed * Timers.delta());
|
||||
|
||||
unit.velocity.add(vec); //TODO clamp it so it doesn't glitch out at low fps
|
||||
|
||||
if(unit.timer.get(timerReload, reload)){
|
||||
shoot(unit, BulletType.shot, ang, 4f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
@@ -9,6 +10,7 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
@@ -21,6 +23,8 @@ public abstract class UnitType {
|
||||
private static int timerIndex = 0;
|
||||
|
||||
protected static final int timerTarget = timerIndex++;
|
||||
protected static final int timerBoost = timerIndex++;
|
||||
protected static final int timerReload = timerIndex++;
|
||||
|
||||
public final String name;
|
||||
public final byte id;
|
||||
@@ -35,6 +39,8 @@ public abstract class UnitType {
|
||||
protected float mass = 1f;
|
||||
protected boolean isFlying;
|
||||
protected float drag = 0.1f;
|
||||
protected float maxVelocity = 5f;
|
||||
protected float reload = 40f;
|
||||
|
||||
public UnitType(String name){
|
||||
this.id = lastid++;
|
||||
@@ -64,6 +70,7 @@ public abstract class UnitType {
|
||||
|
||||
//TODO logic
|
||||
|
||||
unit.velocity.limit(maxVelocity);
|
||||
unit.x += unit.velocity.x / mass;
|
||||
unit.y += unit.velocity.y / mass;
|
||||
|
||||
@@ -88,8 +95,10 @@ public abstract class UnitType {
|
||||
}
|
||||
}
|
||||
|
||||
public void onShoot(BaseUnit unit, BulletType type, float rotation){
|
||||
//TODO remove?
|
||||
public void shoot(BaseUnit unit, BulletType type, float rotation, float translation){
|
||||
new Bullet(type, unit,
|
||||
unit.x + Angles.trnsx(rotation, translation),
|
||||
unit.y + Angles.trnsy(rotation, translation), rotation).add();
|
||||
}
|
||||
|
||||
public void onDeath(BaseUnit unit){
|
||||
|
||||
Reference in New Issue
Block a user