Multiple bugfixes and turret rotation improvements

This commit is contained in:
Anuken
2017-08-24 20:51:35 -04:00
parent 86c02bf469
commit b73a7ce046
9 changed files with 92 additions and 31 deletions

View File

@@ -21,6 +21,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.graphics.Atlas;
import io.anuke.ucore.modules.RendererModule;
import io.anuke.ucore.util.Mathf;
@@ -41,8 +42,6 @@ public class Control extends RendererModule{
float respawntime;
//GifRecorder recorder = new GifRecorder(batch);
public Control(){
cameraScale = baseCameraScale;
pixelate();
@@ -293,6 +292,13 @@ public class Control extends RendererModule{
Renderer.clearTiles();
}
if(Inputs.keyUp(Keys.C)){
for(Entity entity : Entities.all()){
if(entity instanceof Enemy)
entity.remove();
}
}
if(Inputs.keyDown(Keys.SPACE)){
Effects.shake(6, 4);
}
@@ -351,7 +357,7 @@ public class Control extends RendererModule{
float prex = camera.position.x, prey = camera.position.y;
updateShake(1f);
updateShake(0.75f);
float prevx = camera.position.x, prevy = camera.position.y;
clampCamera(-tilesize / 2f, -tilesize / 2f, World.pixsize - tilesize / 2f, World.pixsize - tilesize / 2f);
@@ -381,7 +387,7 @@ public class Control extends RendererModule{
camera.position.set(lastx - deltax, lasty - deltay, 0);
//recorder.update();
record();
}
if(!GameState.is(State.paused)){

View File

@@ -207,21 +207,27 @@ public class Renderer{
}
public static void drawHealth(float x, float y, float health, float maxhealth){
drawBar(Color.RED, x, y, health/maxhealth);
}
public static void drawBar(Color color, float x, float y, float fraction){
float len = 3;
float offset = 7;
float fraction = Mathf.clamp((float) health / maxhealth);
float w = (len * 2 * fraction);
float w = (int)(len * 2 * fraction) + 0.5f;
x -= 0.5f;
y += 0.5f;
Draw.thickness(3f);
Draw.color(Color.GRAY);
Draw.line(x - len + 1, y - offset, x + len + 1, y - offset);
Draw.color(Color.SLATE);
Draw.line(x - len + 1, y - offset, x + len + 1.5f, y - offset);
Draw.thickness(1f);
Draw.color(Color.BLACK);
Draw.line(x - len + 1, y - offset, x + len, y - offset);
Draw.color(Color.RED);
Draw.line(x - len + 1, y - offset, x + len + 0.5f, y - offset);
Draw.color(color);
if(w >= 1)
Draw.line(x - len + 1, y - offset, x - len + w, y - offset);
Draw.line(x - len + 1, y - offset, x - len + w, y - offset);
Draw.reset();
}
}

View File

@@ -451,6 +451,15 @@ public class UI extends SceneModule{
get().setVisible(nplay);
}}.end();
if(debug){
new table(){{
atop();
new table("button"){{
new label("[red]DEBUG MODE").scale(1);
}}.end();
}}.end();
}
new table(){{
//atop();
new table(){{

View File

@@ -24,7 +24,7 @@ public class Vars{
//how much the zoom changes every zoom button press
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
public static boolean debug = false;
public static boolean debug = true;
//number of save slots-- increasing may lead to layout issues
public static final int saveSlots = 4;

View File

@@ -30,7 +30,8 @@ public class Conveyor extends Block{
public void draw(Tile tile){
ConveyorEntity entity = tile.entity();
Draw.rect(name() + (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
Draw.rect(name() +
(Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && accept(Item.stone, tile, null) ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
for(ItemPos pos : entity.convey){
vector.set(tilesize, 0).rotate(tile.rotation * 90);
@@ -44,19 +45,39 @@ public class Conveyor extends Block{
@Override
public void update(Tile tile){
ConveyorEntity entity = tile.entity();
entity.minitem = 1f;
entity.convey.begin();
for(ItemPos pos : entity.convey){
pos.pos += speed * Mathf.delta();
pos.y = MathUtils.lerp(pos.y, 0, 0.14f * Mathf.delta());
boolean canmove = true;
for(int i = 0; i < entity.convey.size; i ++){
ItemPos other = entity.convey.get(i);
if(other.pos > pos.pos && other.pos-pos.pos < 0.14){
canmove = false;
break;
}
}
if(canmove){
pos.pos += speed * Mathf.delta();
pos.y = MathUtils.lerp(pos.y, 0, 0.14f * Mathf.delta());
}else{
pos.y = MathUtils.lerp(pos.y, pos.seed/128f/3f, 0.1f * Mathf.delta());
}
if(pos.pos >= 1f && offloadDir(tile, pos.item)){
entity.convey.removeValue(pos, true);
continue;
}
pos.pos = Mathf.clamp(pos.pos);
if(pos.pos < entity.minitem)
entity.minitem = pos.pos;
}
entity.convey.end();
@@ -69,7 +90,7 @@ public class Conveyor extends Block{
@Override
public boolean accept(Item item, Tile dest, Tile source){
return true;
return dest.<ConveyorEntity>entity().minitem > 0.05f;
}
@Override
@@ -83,7 +104,7 @@ public class Conveyor extends Block{
int ang = ((source.relativeTo(tile.x, tile.y) - tile.rotation));
float pos = ch == 0 ? 0 : ch%2 == 1 ? 0.5f : 1f;
float pos = ch == 0 ? 0 : ch % 2 == 1 ? 0.5f : 1f;
float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
ConveyorEntity entity = tile.entity();
@@ -92,6 +113,7 @@ public class Conveyor extends Block{
public static class ConveyorEntity extends TileEntity{
DelayedRemovalArray<ItemPos> convey = new DelayedRemovalArray<>();
float minitem = 1;
@Override
public void write(DataOutputStream stream) throws IOException{
@@ -120,13 +142,15 @@ public class Conveyor extends Block{
}
static class ItemPos{
public Item item;
public float pos, y;
Item item;
float pos, y;
byte seed;
public ItemPos(Item item, float pos, float y){
this.item = item;
this.pos = pos;
this.y = y;
seed = (byte)MathUtils.random(255);
}
}

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.Inventory;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -11,7 +12,7 @@ public class ProductionBlocks{
core = new Block("core"){
{
health = 300;
health = Vars.debug ? 999999999 : 300;
solid = true;
update = true;
}

View File

@@ -6,6 +6,8 @@ import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
public class RepairTurret extends Turret{
@@ -21,9 +23,10 @@ public class RepairTurret extends Turret{
entity.target = World.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
if(entity.target != null){
entity.rotation = entity.angleTo(entity.target);
float target = entity.angleTo(entity.target);
entity.rotation = Mathf.slerp(entity.rotation, target, 0.2f*Mathf.delta());
if(Timers.get(tile, reload)){
if(Timers.get(tile, reload) && Angles.angleDist(target, entity.rotation) < 12){
entity.target.health++;
}
}

View File

@@ -1,6 +1,4 @@
package io.anuke.mindustry.world.blocks;
import static io.anuke.mindustry.Vars.tilesize;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -8,6 +6,7 @@ import java.io.IOException;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.Renderer;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
@@ -20,6 +19,7 @@ import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
public class Turret extends Block{
@@ -28,6 +28,7 @@ public class Turret extends Block{
protected String shootsound = "shoot";
protected BulletType bullet;
protected Item ammo;
protected int maxammo = 400;
public Turret(String name) {
super(name);
@@ -51,29 +52,38 @@ public class Turret extends Block{
Draw.color("green");
Draw.dashcircle(tile.worldx(), tile.worldy(), range);
Draw.reset();
TurretEntity entity = tile.entity();
float fract = (float)entity.ammo/maxammo;
if(fract > 0)
fract = Mathf.clamp(fract, 0.24f, 1f);
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
}
@Override
public void drawOverlay(Tile tile){
/*
TurretEntity entity = tile.entity();
if(entity.ammo <= 0 && ammo != null){
Draw.tcolor(Color.SCARLET);
Draw.tscl(1 / 8f);
Draw.text("No ammo!", tile.worldx(), tile.worldy() + tilesize);
//Draw.text("No ammo!", tile.worldx(), tile.worldy() + tilesize);
}else if(ammo != null){
Draw.tscl(1 / 8f);
Draw.tcolor(Color.GREEN);
Draw.text("Ammo: " + entity.ammo, tile.worldx(), tile.worldy() - tilesize);
//Draw.text("Ammo: " + entity.ammo, tile.worldx(), tile.worldy() - tilesize);
}
Draw.tscl(Vars.fontscale);
*/
}
@Override
public boolean accept(Item item, Tile dest, Tile source){
return item == ammo;
return item == ammo && dest.<TurretEntity>entity().ammo < maxammo;
}
@Override
@@ -96,7 +106,9 @@ public class Turret extends Block{
});
if(enemy != null){
entity.rotation = MathUtils.lerpAngleDeg(entity.rotation, Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed - 0.1f), 0.2f);
entity.rotation = MathUtils.lerpAngleDeg(entity.rotation,
Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed - 0.1f),
0.2f*Mathf.delta());
float reload = Vars.multiplier*this.reload;
if(Timers.get(tile, reload)){
Effects.sound(shootsound, entity);