Content class reorganization, beginning work on unit factory
This commit is contained in:
@@ -2,6 +2,9 @@ package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
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.game.Team;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
@@ -10,8 +13,10 @@ import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
@@ -34,9 +39,9 @@ public class Player extends Unit{
|
||||
public boolean isAdmin;
|
||||
public Color color = new Color();
|
||||
|
||||
public Weapon weaponLeft = Weapon.blaster;
|
||||
public Weapon weaponRight = Weapon.blaster;
|
||||
public Mech mech = Mech.standard;
|
||||
public Weapon weaponLeft = Weapons.blaster;
|
||||
public Weapon weaponRight = Weapons.blaster;
|
||||
public Mech mech = Mechs.standard;
|
||||
|
||||
public float targetAngle = 0f;
|
||||
public float stucktime = 0f;
|
||||
|
||||
@@ -70,14 +70,7 @@ public class Units {
|
||||
|
||||
/**Iterates over all units that are enemies of this team.*/
|
||||
public static void getNearbyEnemies(Team team, Rectangle rect, Consumer<Unit> cons){
|
||||
//check if it's an ally team to the 'main team'
|
||||
boolean ally = state.allyTeams.contains(team);
|
||||
boolean enemy = state.enemyTeams.contains(team);
|
||||
|
||||
//this team isn't even in the game, so target nothing!
|
||||
if(!ally && !enemy) return;
|
||||
|
||||
ObjectSet<Team> targets = ally ? state.enemyTeams : state.allyTeams;
|
||||
ObjectSet<Team> targets = state.teams.enemiesOf(team);
|
||||
|
||||
for(Team other : targets){
|
||||
EntityGroup<BaseUnit> group = unitGroups[other.ordinal()];
|
||||
@@ -93,12 +86,4 @@ public class Units {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**Returns whether these two teams are enemies.*/
|
||||
public static boolean areEnemies(Team team, Team other){
|
||||
if(team == other) return false; //fast fail to be more efficient
|
||||
boolean ally = state.allyTeams.contains(team);
|
||||
boolean ally2 = state.allyTeams.contains(other);
|
||||
return ally == ally2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Physics;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
@@ -88,7 +89,7 @@ public class DamageArea{
|
||||
for(int dx = -trad; dx <= trad; dx ++){
|
||||
for(int dy= -trad; dy <= trad; dy ++){
|
||||
Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
|
||||
if(tile != null && tile.entity != null && (team == null || Units.areEnemies(team, tile.getTeam())) && Vector2.dst(dx, dy, 0, 0) <= trad){
|
||||
if(tile != null && tile.entity != null && (team == null || state.teams.areEnemies(team, tile.getTeam())) && Vector2.dst(dx, dy, 0, 0) <= trad){
|
||||
int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
|
||||
tile.entity.damage(amount);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
@@ -17,7 +18,7 @@ public class BaseUnit extends Unit {
|
||||
public UnitType type;
|
||||
public Timer timer = new Timer(5);
|
||||
public float walkTime = 0f;
|
||||
public Unit target;
|
||||
public Entity target;
|
||||
|
||||
public BaseUnit(UnitType type, Team team){
|
||||
this.type = type;
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
|
||||
public class FlyingUnitType extends UnitType {
|
||||
private static Vector2 vec = new Vector2();
|
||||
|
||||
public FlyingUnitType(String name) {
|
||||
super(name);
|
||||
speed = 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,6 +29,36 @@ 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
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTargeting(BaseUnit unit) {
|
||||
if(!unit.timer.get(timerTarget, 20)) return;
|
||||
|
||||
ObjectSet<TeamData> teams = state.teams.enemyDataOf(unit.team);
|
||||
|
||||
Tile closest = null;
|
||||
float cdist = 0f;
|
||||
|
||||
for(TeamData data : teams){
|
||||
for(Tile tile : data.cores){
|
||||
float dist = Vector2.dst(unit.x, unit.y, tile.drawx(), tile.drawy());
|
||||
if(closest == null || dist < cdist){
|
||||
closest = tile;
|
||||
cdist = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(closest != null){
|
||||
unit.target = closest.entity;
|
||||
}else{
|
||||
unit.target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
@@ -78,11 +79,11 @@ public abstract class UnitType {
|
||||
public abstract void behavior(BaseUnit unit);
|
||||
|
||||
public void updateTargeting(BaseUnit unit){
|
||||
if(unit.target == null || unit.target.isDead()){
|
||||
if(unit.target == null || (unit.target instanceof Unit && ((Unit)unit.target).isDead())){
|
||||
unit.target = null;
|
||||
}
|
||||
|
||||
if(unit.timer.get(timerTarget, 30)){
|
||||
if(unit.timer.get(timerTarget, 20)){
|
||||
unit.target = Units.getClosestEnemy(unit.team, unit.x, unit.y, range, e -> true);
|
||||
}
|
||||
}
|
||||
@@ -113,4 +114,8 @@ public abstract class UnitType {
|
||||
public static UnitType getByID(byte id){
|
||||
return types.get(id);
|
||||
}
|
||||
|
||||
public static Array<UnitType> getAllTypes(){
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import io.anuke.mindustry.entities.units.types.Scout;
|
||||
|
||||
public class UnitTypes {
|
||||
public static final UnitType
|
||||
|
||||
scout = new Scout();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.anuke.mindustry.entities.units.types;
|
||||
|
||||
import io.anuke.mindustry.entities.units.FlyingUnitType;
|
||||
|
||||
public class Flier extends FlyingUnitType {
|
||||
|
||||
public Flier(){
|
||||
super("flier");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user