Now with only 28 errors!

This commit is contained in:
Anuken
2018-02-05 23:38:23 -05:00
parent 55ae4c6ea5
commit 2fafb327c2
32 changed files with 206 additions and 211 deletions

View File

@@ -1,15 +1,21 @@
package io.anuke.mindustry; package io.anuke.mindustry;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.core.*; import io.anuke.mindustry.core.*;
import io.anuke.mindustry.io.BlockLoader; import io.anuke.mindustry.io.BlockLoader;
import io.anuke.mindustry.io.BundleLoader; import io.anuke.mindustry.io.BundleLoader;
import io.anuke.mindustry.io.Platform; import io.anuke.mindustry.io.Platform;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.ModuleCore; import io.anuke.ucore.modules.ModuleCore;
import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Log;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class Mindustry extends ModuleCore { public class Mindustry extends ModuleCore {
boolean multithread = true;
Thread thread;
float delta = 1f;
@Override @Override
public void init(){ public void init(){
@@ -19,7 +25,11 @@ public class Mindustry extends ModuleCore {
BundleLoader.load(); BundleLoader.load();
BlockLoader.load(); BlockLoader.load();
module(logic = new Logic());
logic = new Logic();
if(!multithread) module(logic);
module(world = new World()); module(world = new World());
module(control = new Control()); module(control = new Control());
module(renderer = new Renderer()); module(renderer = new Renderer());
@@ -27,5 +37,49 @@ public class Mindustry extends ModuleCore {
module(netServer = new NetServer()); module(netServer = new NetServer());
module(netClient = new NetClient()); module(netClient = new NetClient());
module(netCommon = new NetCommon()); module(netCommon = new NetCommon());
Timers.setDeltaProvider(() ->
Math.min(Thread.currentThread() == thread ? delta : Gdx.graphics.getDeltaTime()*60f, 20f)
);
if(multithread) {
logic.init();
thread = new Thread(() -> {
try {
while (true) {
long time = TimeUtils.millis();
logic.update();
long elapsed = TimeUtils.timeSinceMillis(time);
long target = (long) (1000 / 60f);
delta = Math.max(elapsed, target) / 1000f * 60f;
if (elapsed < target) {
Thread.sleep(target - elapsed);
}
}
} catch (Exception ex) {
Gdx.app.postRunnable(() -> {
throw new RuntimeException(ex);
});
}
});
thread.setDaemon(true);
thread.setName("Update Thread");
thread.start();
}
} }
public void render(){
super.render();
try {
//Thread.sleep(40);
}catch (Exception e){
e.printStackTrace();
}
}
} }

View File

@@ -11,7 +11,6 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -26,6 +25,10 @@ public class Pathfind{
/**temporary vector2 for calculations*/ /**temporary vector2 for calculations*/
Vector2 vector = new Vector2(); Vector2 vector = new Vector2();
Vector2 v1 = new Vector2();
Vector2 v2 = new Vector2();
Vector2 v3 = new Vector2();
/**Finds the position on the path an enemy should move to. /**Finds the position on the path an enemy should move to.
* If the path is not yet calculated, this returns the enemy's position (i. e. "don't move") * If the path is not yet calculated, this returns the enemy's position (i. e. "don't move")
* @param enemy The enemy to find a path for * @param enemy The enemy to find a path for
@@ -76,7 +79,7 @@ public class Pathfind{
if(projectLen < 8 || !onLine(projection, prev.worldx(), prev.worldy(), target.worldx(), target.worldy())){ if(projectLen < 8 || !onLine(projection, prev.worldx(), prev.worldy(), target.worldx(), target.worldy())){
canProject = false; canProject = false;
}else{ }else{
projection.add(Angles.translation(Angles.angle(prev.worldx(), prev.worldy(), projection.add(v1.set(Angles.angle(prev.worldx(), prev.worldy(),
target.worldx(), target.worldy()), projectLen)); target.worldx(), target.worldy()), projectLen));
} }
@@ -122,7 +125,8 @@ public class Pathfind{
public void update(){ public void update(){
//go through each spawnpoint, and if it's not found a path yet, update it //go through each spawnpoint, and if it's not found a path yet, update it
for(SpawnPoint point : world.getSpawns()){ for(int i = 0; i < world.getSpawns().size; i ++){
SpawnPoint point = world.getSpawns().get(i);
if(point.request == null || point.finder == null){ if(point.request == null || point.finder == null){
continue; continue;
} }
@@ -204,7 +208,7 @@ public class Pathfind{
} }
/**Finds the closest tile to a position, in an array of tiles.*/ /**Finds the closest tile to a position, in an array of tiles.*/
private static int findClosest(Tile[] tiles, float x, float y){ private int findClosest(Tile[] tiles, float x, float y){
int cindex = -2; int cindex = -2;
float dst = Float.MAX_VALUE; float dst = Float.MAX_VALUE;
@@ -222,23 +226,23 @@ public class Pathfind{
} }
/**Returns whether a point is on a line.*/ /**Returns whether a point is on a line.*/
private static boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){ private boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){
return MathUtils.isEqual(vector.dst(x1, y1) + vector.dst(x2, y2), Vector2.dst(x1, y1, x2, y2), 0.01f); return MathUtils.isEqual(vector.dst(x1, y1) + vector.dst(x2, y2), Vector2.dst(x1, y1, x2, y2), 0.01f);
} }
/**Returns distance from a point to a line segment.*/ /**Returns distance from a point to a line segment.*/
private static float pointLineDist(float x, float y, float x2, float y2, float px, float py){ private float pointLineDist(float x, float y, float x2, float y2, float px, float py){
float l2 = Vector2.dst2(x, y, x2, y2); float l2 = Vector2.dst2(x, y, x2, y2);
float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2)); float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2));
Vector2 projection = Tmp.v1.set(x, y).add(Tmp.v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment Vector2 projection = v1.set(x, y).add(v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
return projection.dst(px, py); return projection.dst(px, py);
} }
//TODO documentation //TODO documentation
private static Vector2 projectPoint(float x1, float y1, float x2, float y2, float pointx, float pointy){ private Vector2 projectPoint(float x1, float y1, float x2, float y2, float pointx, float pointy){
float px = x2-x1, py = y2-y1, dAB = px*px + py*py; float px = x2-x1, py = y2-y1, dAB = px*px + py*py;
float u = ((pointx - x1) * px + (pointy - y1) * py) / dAB; float u = ((pointx - x1) * px + (pointy - y1) * py) / dAB;
float x = x1 + u * px, y = y1 + u * py; float x = x1 + u * px, y = y1 + u * py;
return Tmp.v3.set(x, y); //this is D return v3.set(x, y); //this is D
} }
} }

View File

@@ -4,12 +4,13 @@ import com.badlogic.gdx.ai.utils.Collision;
import com.badlogic.gdx.ai.utils.Ray; import com.badlogic.gdx.ai.utils.Ray;
import com.badlogic.gdx.ai.utils.RaycastCollisionDetector; import com.badlogic.gdx.ai.utils.RaycastCollisionDetector;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Raycaster implements RaycastCollisionDetector<Vector2>{ public class Raycaster implements RaycastCollisionDetector<Vector2>{
private boolean found = false; private boolean found = false;
@@ -75,7 +76,8 @@ public class Raycaster implements RaycastCollisionDetector<Vector2>{
if(tile == null || tile.solid()) return true; if(tile == null || tile.solid()) return true;
for(Tile near : tile.getNearby()){ for(int i = 0; i < 4; i ++){
Tile near = tile.getNearby(i);
if(near == null || near.solid()) return true; if(near == null || near.solid()) return true;
} }

View File

@@ -4,11 +4,12 @@ import io.anuke.mindustry.world.Tile;
/**Tilegraph that ignores player-made tiles.*/ /**Tilegraph that ignores player-made tiles.*/
public class TileGraph implements OptimizedGraph<Tile> { public class TileGraph implements OptimizedGraph<Tile> {
private Tile[] tiles = new Tile[4];
/**Used for the OptimizedPathFinder implementation.*/ /**Used for the OptimizedPathFinder implementation.*/
@Override @Override
public Tile[] connectionsOf(Tile node){ public Tile[] connectionsOf(Tile node){
Tile[] nodes = node.getNearby(); Tile[] nodes = node.getNearby(tiles);
for(int i = 0; i < 4; i ++){ for(int i = 0; i < 4; i ++){
if(nodes[i] != null && !nodes[i].passable()){ if(nodes[i] != null && !nodes[i].passable()){
nodes[i] = null; nodes[i] = null;

View File

@@ -117,6 +117,9 @@ public class Logic extends Module {
if(!state.is(State.menu)){ if(!state.is(State.menu)){
if(!Net.client())
world.pathfinder().update();
if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){ if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){
state.gameOver = true; state.gameOver = true;
NetEvents.handleGameOver(); NetEvents.handleGameOver();

View File

@@ -247,8 +247,9 @@ public class Renderer extends RendererModule{
} }
float angle = Angles.angle(camera.position.x, camera.position.y, enemy.x, enemy.y); float angle = Angles.angle(camera.position.x, camera.position.y, enemy.x, enemy.y);
Angles.translation(angle, Unit.dp.scl(20f)); float tx = Angles.trnsx(angle, Unit.dp.scl(20f));
Draw.rect("enemyarrow", camera.position.x + Angles.x(), camera.position.y + Angles.y(), angle); float ty = Angles.trnsy(angle, Unit.dp.scl(20f));
Draw.rect("enemyarrow", camera.position.x + tx, camera.position.y + ty, angle);
} }
Draw.color(); Draw.color();

View File

@@ -8,7 +8,6 @@ import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.game.SpawnPoint; import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.io.Maps; import io.anuke.mindustry.io.Maps;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Map; import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@@ -42,12 +41,6 @@ public class World extends Module{
currentMap = maps.getMap(0); currentMap = maps.getMap(0);
} }
@Override
public void update(){
if(!Net.client())
pathfind.update();
}
@Override @Override
public void dispose(){ public void dispose(){
maps.dispose(); maps.dispose();
@@ -140,18 +133,6 @@ public class World extends Module{
return tiles; return tiles;
} }
public Tile[] getNearby(int x, int y){
return getNearby(x, y, temptiles);
}
public Tile[] getNearby(int x, int y, Tile[] temptiles){
temptiles[0] = tile(x+1, y);
temptiles[1] = tile(x, y+1);
temptiles[2] = tile(x-1, y);
temptiles[3] = tile(x, y-1);
return temptiles;
}
private void createTiles(){ private void createTiles(){
for(int x = 0; x < tiles.length; x ++){ for(int x = 0; x < tiles.length; x ++){
for(int y = 0; y < tiles[0].length; y ++){ for(int y = 0; y < tiles[0].length; y ++){

View File

@@ -253,9 +253,10 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Effects.effect(Fx.blastsmoke, b); Effects.effect(Fx.blastsmoke, b);
Effects.effect(Fx.blastexplosion, b); Effects.effect(Fx.blastexplosion, b);
Angles.circle(30, f->{ //TODO remove translation() usage
Angles.translation(f, 6f); Angles.circleVectors(30, 6f, (x, y) -> {
Bullet o = new Bullet(blastshot, b.owner, b.x + Angles.x(), b.y + Angles.y(), f).add(); float ang = Mathf.atan2(x, y);
Bullet o = new Bullet(blastshot, b.owner, b.x + x, b.y + y, ang).add();
o.damage = b.damage/9; o.damage = b.damage/9;
}); });
} }

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities; package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.graphics.Shaders;
@@ -17,6 +18,7 @@ import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp; import io.anuke.ucore.util.Tmp;
import io.anuke.ucore.util.Translator;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@@ -42,6 +44,9 @@ public class Player extends SyncEntity{
public int clientid; public int clientid;
public boolean isLocal = false; public boolean isLocal = false;
private Vector2 movement = new Vector2();
private Translator tr = new Translator();
public Player(){ public Player(){
hitbox.setSize(5); hitbox.setSize(5);
hitboxTile.setSize(5f); hitboxTile.setSize(5f);
@@ -121,12 +126,12 @@ public class Player extends SyncEntity{
if(!isAndroid) { if(!isAndroid) {
for (int i : Mathf.signs) { for (int i : Mathf.signs) {
Weapon weapon = i < 0 ? weaponLeft : weaponRight; Weapon weapon = i < 0 ? weaponLeft : weaponRight;
Angles.vector.set(3 * i, 2).rotate(angle - 90); tr.trns(angle - 90, 3*i, 2);
float w = i > 0 ? -8 : 8; float w = i > 0 ? -8 : 8;
if(snap){ if(snap){
Draw.rect(weapon.name + "-equip", (int)x + Angles.x(), (int)y + Angles.y(), w, 8, angle - 90); Draw.rect(weapon.name + "-equip", (int)x + tr.x, (int)y + tr.y, w, 8, angle - 90);
}else{ }else{
Draw.rect(weapon.name + "-equip", x + Angles.x(), y + Angles.y(), w, 8, angle - 90); Draw.rect(weapon.name + "-equip", x + tr.x, y + tr.y, w, 8, angle - 90);
} }
} }
} }
@@ -172,15 +177,15 @@ public class Player extends SyncEntity{
health = Mathf.clamp(health, -1, maxhealth); health = Mathf.clamp(health, -1, maxhealth);
vector.set(0, 0); movement.set(0, 0);
float xa = Inputs.getAxis("move_x"); float xa = Inputs.getAxis("move_x");
float ya = Inputs.getAxis("move_y"); float ya = Inputs.getAxis("move_y");
if(Math.abs(xa) < 0.3) xa = 0; if(Math.abs(xa) < 0.3) xa = 0;
if(Math.abs(ya) < 0.3) ya = 0; if(Math.abs(ya) < 0.3) ya = 0;
vector.y += ya*speed; movement.y += ya*speed;
vector.x += xa*speed; movement.x += xa*speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null
&& !ui.hasMouse() && !control.input().onConfigurable(); && !ui.hasMouse() && !control.input().onConfigurable();
@@ -190,23 +195,22 @@ public class Player extends SyncEntity{
weaponRight.update(player, false); weaponRight.update(player, false);
} }
if(dashing && Timers.get(this, "dashfx", 3) && vector.len() > 0){ if(dashing && Timers.get(this, "dashfx", 3) && movement.len() > 0){
Angles.translation(angle + 180, 3f); Effects.effect(Fx.dashsmoke, x + Angles.trnsx(angle + 180f, 3f), y + Angles.trnsy(angle + 180f, 3f));
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
} }
vector.limit(speed); movement.limit(speed);
if(!noclip){ if(!noclip){
move(vector.x*Timers.delta(), vector.y*Timers.delta()); move(movement.x*Timers.delta(), movement.y*Timers.delta());
}else{ }else{
x += vector.x*Timers.delta(); x += movement.x*Timers.delta();
y += vector.y*Timers.delta(); y += movement.y*Timers.delta();
} }
if(!shooting){ if(!shooting){
if(!vector.isZero()) if(!movement.isZero())
angle = Mathf.lerpAngDelta(angle, vector.angle(), 0.13f); angle = Mathf.lerpAngDelta(angle, movement.angle(), 0.13f);
}else{ }else{
float angle = Angles.mouseAngle(x, y); float angle = Angles.mouseAngle(x, y);
this.angle = Mathf.lerpAngDelta(this.angle, angle, 0.1f); this.angle = Mathf.lerpAngDelta(this.angle, angle, 0.1f);
@@ -299,14 +303,15 @@ public class Player extends SyncEntity{
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f); angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
float tx = x + Angles.trnsx(angle + 180f, 3f);
float ty = y + Angles.trnsy(angle + 180f, 3f);
if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){ if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){
Angles.translation(angle + 180, 3f); Effects.effect(Fx.dashsmoke, tx, ty);
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
} }
if(dashing && !dead && Timers.get(this, "dashfx", 3) && i.target.dst(i.last) > 1f){ if(dashing && !dead && Timers.get(this, "dashfx", 3) && i.target.dst(i.last) > 1f){
Angles.translation(angle + 180, 3f); Effects.effect(Fx.dashsmoke, tx, ty);
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
} }
} }

View File

@@ -11,20 +11,21 @@ import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity; import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Physics; import io.anuke.ucore.util.Physics;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class DamageArea{ public class DamageArea{
private static Rectangle rect = new Rectangle(); private static Rectangle rect = new Rectangle();
private static Translator tr = new Translator();
//only for entities, not tiles (yet!) //only for entities, not tiles (yet!)
public static void damageLine(Entity owner, Effect effect, float x, float y, float angle, float length, int damage){ public static void damageLine(Entity owner, Effect effect, float x, float y, float angle, float length, int damage){
Angles.translation(angle, length); tr.trns(angle, length);
rect.setPosition(x, y).setSize(Angles.x(), Angles.y()); rect.setPosition(x, y).setSize(tr.x, tr.y);
float x2 = Angles.x() + x, y2 = Angles.y() + y; float x2 = tr.x + x, y2 = tr.y + y;
if(rect.width < 0){ if(rect.width < 0){
rect.x += rect.width; rect.x += rect.width;

View File

@@ -3,21 +3,23 @@ package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor; import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.TimedEntity; import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf; 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{ public class EMP extends TimedEntity{
static final int maxTargets = 8; static final int maxTargets = 8;
static Array<Tile> array = new Array<>(); static Array<Tile> array = new Array<>();
static Translator tr = new Translator();
int radius = 4; int radius = 4;
int damage = 6; int damage = 6;
@@ -80,8 +82,8 @@ public class EMP extends TimedEntity{
} }
for(int i = 0; i < 14 - targets.size; i ++){ for(int i = 0; i < 14 - targets.size; i ++){
Angles.translation(Mathf.randomSeed(i + id*77)*360f, radius * tilesize); tr.trns(Mathf.randomSeed(i + id*77)*360f, radius * tilesize);
drawLine(x + Angles.x(), y + Angles.y()); drawLine(x + tr.x, y + tr.y);
} }
Lines.stroke(fract()*2f); Lines.stroke(fract()*2f);

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.entities.enemies; package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.entities.Bullet; import io.anuke.mindustry.entities.Bullet;
@@ -10,10 +11,8 @@ import io.anuke.mindustry.net.NetEvents;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity; import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Timer;
import io.anuke.ucore.util.Tmp;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@@ -37,6 +36,9 @@ public class Enemy extends SyncEntity {
public int tier = 1; public int tier = 1;
public Vector2 totalMove = new Vector2(); public Vector2 totalMove = new Vector2();
public TextureRegion region;
public Translator tr = new Translator();
public Enemy(EnemyType type){ public Enemy(EnemyType type){
this.type = type; this.type = type;
} }
@@ -90,6 +92,7 @@ public class Enemy extends SyncEntity {
hitbox.setSize(type.hitsize); hitbox.setSize(type.hitsize);
hitboxTile.setSize(type.hitsizeTile); hitboxTile.setSize(type.hitsizeTile);
maxhealth = type.health * tier; maxhealth = type.health * tier;
region = Draw.region(type.name + "-t" + Mathf.clamp(tier, 1, 3));
heal(); heal();
} }
@@ -166,13 +169,13 @@ public class Enemy extends SyncEntity {
public void shoot(BulletType bullet, float rotation){ public void shoot(BulletType bullet, float rotation){
if(!(Net.client())) { if(!(Net.client())) {
Angles.translation(angle + rotation, type.length); tr.trns(angle + rotation, type.length);
Bullet out = new Bullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation).add(); Bullet out = new Bullet(bullet, this, x + tr.x, y + tr.y, this.angle + rotation).add();
out.damage = (int) ((bullet.damage * (1 + (tier - 1) * 1f))); out.damage = (int) ((bullet.damage * (1 + (tier - 1) * 1f)));
type.onShoot(this, bullet, rotation); type.onShoot(this, bullet, rotation);
if(Net.server()){ if(Net.server()){
NetEvents.handleBullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation, (short)out.damage); NetEvents.handleBullet(bullet, this, x + tr.x, y + tr.y, this.angle + rotation, (short)out.damage);
} }
} }
} }

View File

@@ -67,15 +67,13 @@ public class EnemyType {
} }
public void draw(Enemy enemy){ public void draw(Enemy enemy){
String region = name + "-t" + Mathf.clamp(enemy.tier, 1, 3);
Shaders.outline.color.set(tierColors[enemy.tier - 1]); Shaders.outline.color.set(tierColors[enemy.tier - 1]);
Shaders.outline.lighten = Mathf.clamp(enemy.hitTime/hitDuration); Shaders.outline.lighten = Mathf.clamp(enemy.hitTime/hitDuration);
Shaders.outline.region = Draw.region(region); Shaders.outline.region = enemy.region;
Shaders.outline.apply(); Shaders.outline.apply();
Draw.rect(region, enemy.x, enemy.y, enemy.angle - 90); Draw.rect(enemy.region, enemy.x, enemy.y, enemy.angle - 90);
Draw.color(); Draw.color();
Graphics.flush(); Graphics.flush();

View File

@@ -35,13 +35,13 @@ public class FortressType extends EnemyType {
world.getCore().worldy()) <= 90f){ world.getCore().worldy()) <= 90f){
if(Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn){ if(Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn){
Angles.translation(enemy.angle, 20f); enemy.tr.trns(enemy.angle, 20f);
Enemy s = new Enemy(EnemyTypes.fast); Enemy s = new Enemy(EnemyTypes.fast);
s.lane = enemy.lane; s.lane = enemy.lane;
s.tier = enemy.tier; s.tier = enemy.tier;
s.spawner = enemy; s.spawner = enemy;
s.set(enemy.x + Angles.x(), enemy.y + Angles.y()); s.set(enemy.x + enemy.tr.x, enemy.y + enemy.tr.y);
s.add(); s.add();
Effects.effect(Fx.spawn, enemy); Effects.effect(Fx.spawn, enemy);
@@ -53,7 +53,7 @@ public class FortressType extends EnemyType {
public void onShoot(Enemy enemy, BulletType type, float rotation){ public void onShoot(Enemy enemy, BulletType type, float rotation){
Effects.effect(Fx.largeCannonShot, enemy.x + Angles.x(), enemy.y + Angles.y(), enemy.angle); Effects.effect(Fx.largeCannonShot, enemy.x + enemy.tr.x, enemy.y + enemy.tr.y, enemy.angle);
Effects.shake(3f, 3f, enemy); Effects.shake(3f, 3f, enemy);
} }

View File

@@ -74,7 +74,7 @@ public class HealerType extends EnemyType {
if(target == null) return; if(target == null) return;
Angles.translation(enemy.angleTo(target), 5f); enemy.tr.trns(enemy.angleTo(target), 5f);
Shaders.outline.color.set(Color.CLEAR); Shaders.outline.color.set(Color.CLEAR);
Shaders.outline.apply(); Shaders.outline.apply();
@@ -82,7 +82,7 @@ public class HealerType extends EnemyType {
if(target.health < target.maxhealth){ if(target.health < target.maxhealth){
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 13f)); Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 13f));
Draw.alpha(0.9f); Draw.alpha(0.9f);
Shapes.laser("laser", "laserend", enemy.x + Angles.x(), enemy.y + Angles.y(), target.x - Angles.x()/1.5f, target.y - Angles.y()/1.5f); Shapes.laser("laser", "laserend", enemy.x + enemy.tr.x, enemy.y + enemy.tr.y, target.x - enemy.tr.x/1.5f, target.y - enemy.tr.y/1.5f);
Draw.color(); Draw.color();
} }

View File

@@ -17,17 +17,14 @@ public class TankType extends EnemyType {
bullet = BulletType.small; bullet = BulletType.small;
length = 3f; length = 3f;
mass = 1.4f; mass = 1.4f;
length = 8f;
} }
@Override @Override
public void shoot(Enemy enemy){ public void shoot(Enemy enemy){
super.shoot(enemy); super.shoot(enemy);
Angles.translation(enemy.angle, 8f); Angles.shotgun(3, 8f, enemy.angle, f -> enemy.shoot(bullet, f));
Angles.shotgun(3, 8f, enemy.angle, f -> {
enemy.shoot(bullet, f);
});
} }
} }

View File

@@ -13,6 +13,7 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
public class Weapon extends Upgrade{ public class Weapon extends Upgrade{
public static final Weapon public static final Weapon
@@ -87,6 +88,8 @@ public class Weapon extends Upgrade{
float length = 3f; float length = 3f;
/**whether to shoot the weapons in different arms one after another, rather an all at once*/ /**whether to shoot the weapons in different arms one after another, rather an all at once*/
boolean roundrobin = false; boolean roundrobin = false;
/**translator for vector calulations*/
Translator tr = new Translator();
private Weapon(String name, float reload, BulletType type){ private Weapon(String name, float reload, BulletType type){
super(name); super(name);
@@ -100,15 +103,15 @@ public class Weapon extends Upgrade{
Timers.reset(p, "reload" + !left, reload/2f); Timers.reset(p, "reload" + !left, reload/2f);
} }
float ang = Angles.mouseAngle(p.x, p.y); float ang = Angles.mouseAngle(p.x, p.y);
Angles.vector.set(3f * Mathf.sign(left), length).rotate(ang - 90); tr.trns(ang - 90, 3f * Mathf.sign(left), length);
shoot(p, p.x + Angles.x(), p.y + Angles.y(), Angles.mouseAngle(p.x + Angles.x(), p.y + Angles.y())); shoot(p, p.x + tr.x, p.y + tr.y, Angles.mouseAngle(p.x + tr.x, p.y + tr.y));
} }
} }
void shootInternal(Player p, float x, float y, float rotation){ void shootInternal(Player p, float x, float y, float rotation){
Angles.shotgun(shots, spacing, rotation, f -> bullet(p, x, y, f + Mathf.range(inaccuracy))); Angles.shotgun(shots, spacing, rotation, f -> bullet(p, x, y, f + Mathf.range(inaccuracy)));
Angles.translation(rotation, 3f); tr.trns(rotation, 3f);
if(effect != null) Effects.effect(effect, x + Angles.x(), y + Angles.y(), rotation); if(effect != null) Effects.effect(effect, x + tr.x, y + tr.y, rotation);
Effects.shake(shake, shake, x, y); Effects.shake(shake, shake, x, y);
Effects.sound(shootsound, x, y); Effects.sound(shootsound, x, y);
} }
@@ -122,7 +125,7 @@ public class Weapon extends Upgrade{
} }
void bullet(Entity owner, float x, float y, float angle){ void bullet(Entity owner, float x, float y, float angle){
Angles.translation(angle, 3f); tr.trns(angle, 3f);
new Bullet(type, owner, x + Angles.x(), y + Angles.y(), angle).add(); new Bullet(type, owner, x + tr.x, y + tr.y, angle).add();
} }
} }

View File

@@ -31,7 +31,6 @@ public class Block{
protected static TextureRegion temp = new TextureRegion(); protected static TextureRegion temp = new TextureRegion();
public Tile[] temptiles = new Tile[4];
/**internal name*/ /**internal name*/
public final String name; public final String name;
/**internal ID*/ /**internal ID*/

View File

@@ -238,12 +238,12 @@ public class Tile{
return null; return null;
} }
public Tile[] getNearby(){ public Tile[] getNearby(Tile[] temptiles){
return world.getNearby(x, y); temptiles[0] = world.tile(x+1, y);
} temptiles[1] = world.tile(x, y+1);
temptiles[2] = world.tile(x-1, y);
public Tile[] getNearby(Tile[] copy){ temptiles[3] = world.tile(x, y-1);
return world.getNearby(x, y, copy); return temptiles;
} }
public void updateOcclusion(){ public void updateOcclusion(){

View File

@@ -45,8 +45,6 @@ public class DistributionBlocks{
}}, }},
liquidjunction = new LiquidJunction("liquidjunction"){{ liquidjunction = new LiquidJunction("liquidjunction"){{
}},
liquiditemjunction = new LiquidItemJunction("liquiditemjunction"){{
}}, }},
powerbooster = new PowerBooster("powerbooster"){{ powerbooster = new PowerBooster("powerbooster"){{
powerRange = 4; powerRange = 4;

View File

@@ -41,11 +41,10 @@ public class WeaponBlocks{
protected void shoot(Tile tile){ protected void shoot(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Angles.vector.set(4, -2).rotate(entity.rotation); for(int i : Mathf.signs){
bullet(tile, entity.rotation); tr.trns(entity.rotation, 4, -2 * i);
bullet(tile, entity.rotation);
Angles.vector.set(4, 2).rotate(entity.rotation); }
bullet(tile, entity.rotation);
} }
}, },
@@ -136,9 +135,10 @@ public class WeaponBlocks{
@Override @Override
public void shoot(Tile tile){ public void shoot(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Angles.translation(entity.rotation, 4);
new TeslaOrb(tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), range, 9).add(); float len = 4f;
new TeslaOrb(tile.drawx() + Angles.trnsx(entity.rotation, len), tile.drawy() + Angles.trnsy(entity.rotation, len), range, 9).add();
} }
}, },
@@ -179,10 +179,10 @@ public class WeaponBlocks{
float space = 3.5f; float space = 3.5f;
for(int i = -1; i < 1; i ++){ for(int i = -1; i < 1; i ++){
Angles.vector.set(len, Mathf.sign(i) * space).rotate(entity.rotation); tr.trns(entity.rotation, len, Mathf.sign(i) * space);
bullet(tile, entity.rotation); bullet(tile, entity.rotation);
Effects.effect(shootEffect, tile.drawx() + Angles.x(), Effects.effect(shootEffect, tile.drawx() + tr.x,
tile.drawy()+ Angles.y(), entity.rotation); tile.drawy() + tr.y, entity.rotation);
} }
Effects.shake(1f, 1f, tile.worldx(), tile.worldy()); Effects.shake(1f, 1f, tile.worldx(), tile.worldy());

View File

@@ -20,10 +20,9 @@ public class BlendBlock extends Block{
Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(), Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(),
tile.worldx(), tile.worldy()); tile.worldx(), tile.worldy());
Tile[] nearby = tile.getNearby();
for(int i = 0; i < 4; i ++){ for(int i = 0; i < 4; i ++){
if(nearby[i] != null && !blend.test(nearby[i].block())){ Tile near = tile.getNearby(i);
if(near != null && !blend.test(near.block())){
Draw.rect(edge + "-" + i, tile.worldx(), tile.worldy()); Draw.rect(edge + "-" + i, tile.worldx(), tile.worldy());
} }
} }

View File

@@ -34,7 +34,7 @@ public class LaserTurret extends PowerTurret{
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Enemy enemy = entity.target; Enemy enemy = entity.target;
if(Angles.angleDist(entity.rotation, Angles.angle(tile.worldx(), tile.worldy(), enemy.x, enemy.y)) < cone){ if(Angles.angleDist(entity.rotation, Angles.angle(tile.drawx(), tile.drawy(), enemy.x, enemy.y)) < cone){
enemy.damage(damage); enemy.damage(damage);
Effects.effect(hiteffect, enemy.x + Mathf.range(3), enemy.y + Mathf.range(3)); Effects.effect(hiteffect, enemy.x + Mathf.range(3), enemy.y + Mathf.range(3));
} }
@@ -45,10 +45,10 @@ public class LaserTurret extends PowerTurret{
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
if(entity.target != null && if(entity.target != null &&
Angles.angleDist(entity.rotation, Angles.angle(tile.worldx(), tile.worldy(), entity.target.x, entity.target.y)) <= cone){ Angles.angleDist(entity.rotation, Angles.angle(tile.drawx(), tile.drawy(), entity.target.x, entity.target.y)) <= cone){
Angles.translation(entity.rotation, 4f); float len = 4f;
float x = tile.worldx() + Angles.x(), y = tile.worldy() + Angles.y(); float x = tile.drawx() + Angles.trnsx(entity.rotation, len), y = tile.drawy() + Angles.trnsy(entity.rotation, len);
float x2 = entity.target.x, y2 = entity.target.y; float x2 = entity.target.x, y2 = entity.target.y;
float lighten = (MathUtils.sin(Timers.time()/1.2f) + 1f) / 10f; float lighten = (MathUtils.sin(Timers.time()/1.2f) + 1f) / 10f;

View File

@@ -73,7 +73,7 @@ public class RepairTurret extends PowerTurret{
@Override @Override
public void drawSelect(Tile tile){ public void drawSelect(Tile tile){
Draw.color(Color.GREEN); Draw.color(Color.GREEN);
Lines.dashCircle(tile.worldx(), tile.worldy(), range); Lines.dashCircle(tile.drawx(), tile.drawy(), range);
Draw.reset(); Draw.reset();
} }
@@ -83,8 +83,9 @@ public class RepairTurret extends PowerTurret{
if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){ if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
Tile targetTile = entity.blockTarget.tile; Tile targetTile = entity.blockTarget.tile;
Angles.translation(entity.rotation, 4f); float len = 4f;
float x = tile.drawx() + Angles.x(), y = tile.drawy() + Angles.y();
float x = tile.drawx() + Angles.trnsx(entity.rotation, len), y = tile.drawy() + Angles.trnsy(entity.rotation, len);
float x2 = targetTile.drawx(), y2 = targetTile.drawy(); float x2 = targetTile.drawx(), y2 = targetTile.drawy();
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f)); Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));

View File

@@ -21,6 +21,7 @@ import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import io.anuke.ucore.util.Translator;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@@ -51,6 +52,7 @@ public class Turret extends Block{
protected Effect shootEffect = null; protected Effect shootEffect = null;
protected float shootShake = 0f; protected float shootShake = 0f;
protected int soundReload = 0; protected int soundReload = 0;
protected Translator tr = new Translator();
public Turret(String name) { public Turret(String name) {
super(name); super(name);
@@ -210,14 +212,14 @@ public class Turret extends Block{
protected void shoot(Tile tile){ protected void shoot(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Angles.translation(entity.rotation, width * tilesize / 2f); tr.trns(entity.rotation, width * tilesize/2);
for(int i = 0; i < shots; i ++){ for(int i = 0; i < shots; i ++){
if(Mathf.zero(shotDelayScale)){ if(Mathf.zero(shotDelayScale)){
bullet(tile, entity.rotation + Mathf.range(inaccuracy)); bullet(tile, entity.rotation + Mathf.range(inaccuracy));
}else{ }else{
Timers.run(i * shotDelayScale, ()->{ Timers.run(i * shotDelayScale, () -> {
Angles.translation(entity.rotation, width * tilesize / 2f); tr.trns(entity.rotation, width * tilesize/2f);
bullet(tile, entity.rotation + Mathf.range(inaccuracy)); bullet(tile, entity.rotation + Mathf.range(inaccuracy));
}); });
} }
@@ -225,8 +227,8 @@ public class Turret extends Block{
} }
if(shootEffect != null){ if(shootEffect != null){
Effects.effect(shootEffect, tile.drawx() + Angles.x(), Effects.effect(shootEffect, tile.drawx() + tr.x,
tile.drawy()+ Angles.y(), entity.rotation); tile.drawy() + tr.y, entity.rotation);
} }
if(shootShake > 0){ if(shootShake > 0){
@@ -235,7 +237,7 @@ public class Turret extends Block{
} }
protected void bullet(Tile tile, float angle){ protected void bullet(Tile tile, float angle){
Bullet out = new Bullet(bullet, tile.entity, tile.drawx() + Angles.x(), tile.drawy() + Angles.y(), angle).add(); new Bullet(bullet, tile.entity, tile.drawx() + tr.x, tile.drawy() + tr.y, angle).add();
} }
public static class TurretEntity extends TileEntity{ public static class TurretEntity extends TileEntity{

View File

@@ -24,6 +24,7 @@ import java.util.List;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
public class Conveyor extends Block{ public class Conveyor extends Block{
private static ItemPos drawpos = new ItemPos();
private static ItemPos pos1 = new ItemPos(); private static ItemPos pos1 = new ItemPos();
private static ItemPos pos2 = new ItemPos(); private static ItemPos pos2 = new ItemPos();
private static LongArray removals = new LongArray(); private static LongArray removals = new LongArray();
@@ -72,7 +73,7 @@ public class Conveyor extends Block{
byte rotation = tile.getRotation(); byte rotation = tile.getRotation();
for(int i = 0; i < entity.convey.size; i ++){ for(int i = 0; i < entity.convey.size; i ++){
ItemPos pos = pos1.set(entity.convey.get(i)); ItemPos pos = drawpos.set(entity.convey.get(i));
if(pos.item == null) continue; if(pos.item == null) continue;

View File

@@ -1,64 +0,0 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
public class LiquidItemJunction extends LiquidBlock{
public LiquidItemJunction(String name) {
super(name);
rotate = true;
}
@Override
public void draw(Tile tile){
Draw.rect(name(), tile.worldx(), tile.worldy(), tile.getRotation() * 90);
}
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(tile.x, tile.y);
dir = (dir+4)%4;
Tile to = tile.getNearby()[dir];
((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount);
}
@Override
public boolean acceptLiquid(Tile dest, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(dest.x, dest.y);
dir = (dir+4)%4;
if(dir+dest.getRotation() % 2 == 1) return false;
Tile to = dest.getNearby()[dir];
return to != null && to.block() != this && to.block() instanceof LiquidBlock &&
((LiquidBlock)to.block()).acceptLiquid(to, dest, liquid, amount);
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
int dir = source.relativeTo(tile.x, tile.y);
Tile to = tile.getNearby()[dir];
Timers.run(15, ()->{
if(to == null || to.entity == null) return;
to.block().handleItem(item, to, tile);
});
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
int dir = source.relativeTo(tile.x, tile.y);
if((dir+ tile.getRotation()) % 2 == 0) return false;
Tile to = tile.getNearby()[dir];
return to != null && to.block().acceptItem(item, to, tile);
}
}

View File

@@ -23,7 +23,7 @@ public class LiquidJunction extends Conduit{
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(tile.x, tile.y); int dir = source.relativeTo(tile.x, tile.y);
dir = (dir+4)%4; dir = (dir+4)%4;
Tile to = tile.getNearby()[dir]; Tile to = tile.getNearby(dir);
((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount); ((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount);
@@ -33,7 +33,7 @@ public class LiquidJunction extends Conduit{
public boolean acceptLiquid(Tile dest, Tile source, Liquid liquid, float amount){ public boolean acceptLiquid(Tile dest, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(dest.x, dest.y); int dir = source.relativeTo(dest.x, dest.y);
dir = (dir+4)%4; dir = (dir+4)%4;
Tile to = dest.getNearby()[dir]; Tile to = dest.getNearby(dir);
return to != null && to.block() != this && to.block() instanceof LiquidBlock && return to != null && to.block() != this && to.block() instanceof LiquidBlock &&
((LiquidBlock)to.block()).acceptLiquid(to, dest, liquid, amount); ((LiquidBlock)to.block()).acceptLiquid(to, dest, liquid, amount);
} }

View File

@@ -19,7 +19,7 @@ public class LiquidRouter extends Conduit{
if(entity.liquidAmount > 0){ if(entity.liquidAmount > 0){
if(tile.getExtra() != tile.getRotation()){ if(tile.getExtra() != tile.getRotation()){
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]); tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
} }
tile.setRotation((byte)((tile.getRotation() + 1) % 4)); tile.setRotation((byte)((tile.getRotation() + 1) % 4));

View File

@@ -66,10 +66,10 @@ public class Sorter extends Block{
Tile to; Tile to;
if(item == entity.sortItem){ if(item == entity.sortItem){
to = dest.getNearby()[dir]; to = dest.getNearby(dir);
}else{ }else{
Tile a = dest.getNearby()[Mathf.mod(dir - 1, 4)]; Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
Tile b = dest.getNearby()[Mathf.mod(dir + 1, 4)]; Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
boolean ac = a.block().acceptItem(item, a, dest); boolean ac = a.block().acceptItem(item, a, dest);
boolean bc = b.block().acceptItem(item, b, dest); boolean bc = b.block().acceptItem(item, b, dest);

View File

@@ -31,8 +31,8 @@ public class Splitter extends Block{
if(dir == -1) return null; if(dir == -1) return null;
Tile to; Tile to;
Tile a = dest.getNearby()[Mathf.mod(dir - 1, 4)]; Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
Tile b = dest.getNearby()[Mathf.mod(dir + 1, 4)]; Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
boolean ac = a.block().acceptItem(item, a, dest); boolean ac = a.block().acceptItem(item, a, dest);
boolean bc = b.block().acceptItem(item, b, dest); boolean bc = b.block().acceptItem(item, b, dest);

View File

@@ -25,6 +25,9 @@ public class Generator extends PowerBlock{
public static final int powerTime = 2; public static final int powerTime = 2;
public static boolean drawRangeOverlay = false; public static boolean drawRangeOverlay = false;
protected Translator t1 = new Translator();
protected Translator t2 = new Translator();
public int laserRange = 6; public int laserRange = 6;
public int laserDirections = 4; public int laserDirections = 4;
public float powerSpeed = 0.5f; public float powerSpeed = 0.5f;
@@ -177,10 +180,10 @@ public class Generator extends PowerBlock{
if(target != null){ if(target != null){
boolean interfering = isInterfering(target, rotation); boolean interfering = isInterfering(target, rotation);
Tmp.v1.set(Angles.translation(rotation * 90, target.block().width * tilesize / 2 + 2f + t1.trns(rotation * 90, target.block().width * tilesize / 2 + 2f +
(interfering ? Vector2.dst(tile.worldx(), tile.worldy(), target.worldx(), target.worldy()) / 2f - tilesize / 2f * target.block().width + 1 : 0))); (interfering ? Vector2.dst(tile.worldx(), tile.worldy(), target.worldx(), target.worldy()) / 2f - tilesize / 2f * target.block().width + 1 : 0));
Angles.translation(rotation * 90, width * tilesize / 2 + 2f); t2.trns(rotation * 90, width * tilesize / 2 + 2f);
if(!interfering){ if(!interfering){
Draw.tint(Hue.mix(Color.GRAY, Color.WHITE, 0.904f + Mathf.sin(Timers.time(), 1.7f, 0.06f))); Draw.tint(Hue.mix(Color.GRAY, Color.WHITE, 0.904f + Mathf.sin(Timers.time(), 1.7f, 0.06f)));
@@ -188,7 +191,7 @@ public class Generator extends PowerBlock{
Draw.tint(Hue.mix(Color.SCARLET, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f))); Draw.tint(Hue.mix(Color.SCARLET, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f)));
if(state.is(State.playing) && Mathf.chance(Timers.delta() * 0.033)){ if(state.is(State.playing) && Mathf.chance(Timers.delta() * 0.033)){
Effects.effect(Fx.laserspark, target.worldx() - Tmp.v1.x, target.worldy() - Tmp.v1.y); Effects.effect(Fx.laserspark, target.worldx() - t1.x, target.worldy() - t1.y);
} }
} }
@@ -197,9 +200,9 @@ public class Generator extends PowerBlock{
int relative = tile.relativeTo(target.x, target.y); int relative = tile.relativeTo(target.x, target.y);
if(relative == -1){ if(relative == -1){
Shapes.laser("laser", "laserend", tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), Shapes.laser("laser", "laserend", tile.worldx() + t2.x, tile.worldy() + t2.y,
target.worldx() - Tmp.v1.x + Mathf.range(r), target.worldx() - t1.x + Mathf.range(r),
target.worldy() - Tmp.v1.y + Mathf.range(r), 0.7f); target.worldy() - t1.y + Mathf.range(r), 0.7f);
}else{ }else{
Draw.rect("laserfull", Draw.rect("laserfull",
tile.worldx() + Geometry.d4[relative].x * width * tilesize / 2f, tile.worldx() + Geometry.d4[relative].x * width * tilesize / 2f,