1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 14:56:10 +03:00

Added LaserTurret block, minor improvements

This commit is contained in:
Anuken 2017-09-18 21:33:46 -04:00
parent 1b870da997
commit 537641c8a3
24 changed files with 147 additions and 40 deletions

View File

@ -18,6 +18,7 @@ import io.anuke.mindustry.input.GestureHandler;
import io.anuke.mindustry.input.Input;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.Entities;
@ -281,7 +282,6 @@ public class Control extends ControlModule{
public void update(){
if(debug){
if(Inputs.keyUp(Keys.SPACE))
Effects.sound("shoot", World.core.worldx(), World.core.worldy());

View File

@ -15,4 +15,16 @@ public class Mindustry extends ModuleCore {
public void postInit(){
Vars.control.reset();
}
@Override
public void render(){
try{
super.render();
}catch (RuntimeException e){
//TODO
//Gdx.app.getClipboard().setContents(e.getMessage());
throw e;
}
}
}

View File

@ -11,6 +11,7 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;
@ -137,6 +138,8 @@ public class Renderer{
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
Draw.thickness(2f);
Draw.square(x, y, tilesize / 2 + MathUtils.sin(Timers.time() / 6f) + 1);
player.recipe.result.drawPlace(tilex, tiley, valid);
if(player.recipe.result.rotate){
Draw.color("orange");

View File

@ -30,7 +30,7 @@ public class Vars{
public static final int saveSlots = 4;
//turret and enemy shoot speed inverse multiplier
public static final int multiplier = android ? 3 : 1;
public static final float multiplier = android ? 3 : 2;
public static final int tilesize = 8;

View File

@ -4,8 +4,8 @@ import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
/**Tilegraph that ignores player-made tiles.*/
public class PassTileGraph implements IndexedGraph<Tile>{
private Array<Connection<Tile>> tempConnections = new Array<Connection<Tile>>();

View File

@ -7,9 +7,9 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.Effects;
public class Pathfind{
static MHueristic heuristic = new MHueristic();

View File

@ -6,8 +6,8 @@ import com.badlogic.gdx.ai.utils.RaycastCollisionDetector;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;

View File

@ -2,8 +2,8 @@ package io.anuke.mindustry.entities;
import static io.anuke.mindustry.Vars.tilesize;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;

View File

@ -3,12 +3,12 @@ package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.World;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
@ -73,7 +73,7 @@ public class Enemy extends DestructibleEntity{
void shoot(){
vector.set(length, 0).rotate(direction.angle());
Bullet out = new Bullet(bullet, this, x+vector.x, y+vector.y, direction.angle()).add();
out.damage = bullet.damage*Vars.multiplier;
out.damage = (int)(bullet.damage*Vars.multiplier);
}
public void findClosestNode(){

View File

@ -8,9 +8,9 @@ import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Inventory;
import io.anuke.mindustry.World;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;

View File

@ -6,8 +6,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.core.*;

View File

@ -6,10 +6,10 @@ import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import io.anuke.mindustry.Inventory;
import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.Weapon;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;

View File

@ -20,6 +20,7 @@ import io.anuke.mindustry.entities.enemies.*;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;

View File

@ -19,9 +19,6 @@ public enum Recipe{
router(distribution, ProductionBlocks.router, stack(Item.stone, 3)),
junction(distribution, ProductionBlocks.junction, stack(Item.iron, 5)),
conduit(distribution, ProductionBlocks.conduit, stack(Item.steel, 1)),
pump(distribution, ProductionBlocks.pump, stack(Item.steel, 20)),
turret(defense, WeaponBlocks.turret, stack(Item.stone, 6)),
dturret(defense, WeaponBlocks.doubleturret, stack(Item.stone, 12)),
machineturret(defense, WeaponBlocks.machineturret, stack(Item.iron, 15), stack(Item.stone, 20)),
@ -40,7 +37,10 @@ public enum Recipe{
titaniumdrill(production, ProductionBlocks.titaniumdrill, stack(Item.iron, 40), stack(Item.steel, 40)),
omnidrill(production, ProductionBlocks.omnidrill, stack(Item.steel, 50), stack(Item.titanium, 50)),
smelter(production, ProductionBlocks.smelter, stack(Item.stone, 80), stack(Item.iron, 80)),
crucible(production, ProductionBlocks.crucible, stack(Item.titanium, 80), stack(Item.steel, 80));
crucible(production, ProductionBlocks.crucible, stack(Item.titanium, 80), stack(Item.steel, 80)),
conduit(distribution, ProductionBlocks.conduit, stack(Item.steel, 1)),
pump(production, ProductionBlocks.pump, stack(Item.steel, 20));
public Block result;
public ItemStack[] requirements;

View File

@ -5,7 +5,7 @@ import static io.anuke.mindustry.Vars.maps;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.*;

View File

@ -5,7 +5,6 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
@ -47,6 +46,7 @@ public class Block{
public void drawOver(Tile tile){}
public void drawPixelOverlay(Tile tile){}
public void drawOverlay(Tile tile){}
public void drawPlace(int x, int y, boolean valid){}
public String name(){
return name;

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.noise.Noise;
@ -62,6 +61,10 @@ public class Generator{
if(Noise.nnoise(x, y, 6, 1) > 0.242){
floor = Blocks.coal;
}
if(Noise.nnoise(x, y, 5, 1) > 0.2){
floor = Blocks.titanium;
}
}
if(block == Blocks.grassblock){

View File

@ -2,7 +2,6 @@ package io.anuke.mindustry.world;
import static io.anuke.mindustry.Vars.tilesize;
import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.blocks.Blocks;

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.world;
import static io.anuke.mindustry.Vars.*;
@ -12,9 +12,6 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Generator;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.WeaponBlocks;

View File

@ -113,6 +113,8 @@ public class WeaponBlocks{
//TODO
laserturret = new Turret("laserturret"){
{
formalName = "laser turret";
range = 60;

View File

@ -1,5 +1,9 @@
package io.anuke.mindustry.world.blocks.types;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Block;
@ -43,8 +47,6 @@ public class Conduit extends Block{
if(entity.amount > 0.01f && Timers.get(entity, "flow", 3)){
tryMoveLiquid(tile, tile.getNearby()[tile.rotation]);
entity.flowtime = 0f;
}
}
@ -94,6 +96,17 @@ public class Conduit extends Block{
static class ConduitEntity extends TileEntity{
Liquid liquid;
float amount;
float flowtime;
@Override
public void write(DataOutputStream stream) throws IOException{
stream.writeByte(liquid.ordinal());
stream.writeByte((byte)(amount));
}
@Override
public void read(DataInputStream stream) throws IOException{
liquid = Liquid.values()[stream.readByte()];
amount = stream.readByte();
}
}
}

View File

@ -0,0 +1,58 @@
package io.anuke.mindustry.world.blocks.types;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public class LaserTurret extends Turret{
protected Color beamColor = Color.WHITE.cpy();
protected String hiteffect = "hit";
protected int damage = 4;
public LaserTurret(String name) {
super(name);
}
@Override
public void shoot(Tile tile){
TurretEntity entity = tile.entity();
Enemy enemy = entity.target;
enemy.damage(damage);
Effects.effect(hiteffect, enemy.x + Mathf.range(3), enemy.y + Mathf.range(3));
}
@Override
public void drawOver(Tile tile){
TurretEntity entity = tile.entity();
if(entity.target != null){
float x = tile.worldx(), y = tile.worldy();
float x2 = entity.target.x, y2 = entity.target.y;
float lighten = (MathUtils.sin(Timers.time()/1.2f) + 1f) / 10f;
Draw.color(Tmp.c1.set(beamColor).mul(1f + lighten, 1f + lighten, 1f + lighten, 1f));
Draw.alpha(0.3f);
Draw.thickness(4f);
Draw.line(x, y, x2, y2);
Draw.thickness(2f);
Draw.rect("circle", x2, y2, 7f, 7f);
Draw.alpha(1f);
Draw.thickness(2f);
Draw.line(x, y, x2, y2);
Draw.thickness(1f);
Draw.rect("circle", x2, y2, 5f, 5f);
Draw.reset();
}
super.drawOver(tile);
}
}

View File

@ -2,8 +2,8 @@ package io.anuke.mindustry.world.blocks.types;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Hue;
@ -20,8 +20,10 @@ public class RepairTurret extends Turret{
public void update(Tile tile){
TurretEntity entity = tile.entity();
entity.target = World.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
if(Timers.get(entity, "target", targetInterval)){
entity.blockTarget = World.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
}
if(entity.target != null){
float target = entity.angleTo(entity.target);
entity.rotation = Mathf.slerp(entity.rotation, target, 0.16f*Timers.delta());
@ -41,9 +43,9 @@ public class RepairTurret extends Turret{
public void drawOver(Tile tile){
TurretEntity entity = tile.entity();
if(entity.target != null){
if(entity.blockTarget != null){
float x = tile.worldx(), y = tile.worldy();
float x2 = entity.target.x, y2 = entity.target.y;
float x2 = entity.blockTarget.x, y2 = entity.blockTarget.y;
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
Draw.alpha(0.3f);

View File

@ -23,11 +23,14 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public class Turret extends Block{
public static final int targetInterval = 15;
protected float range = 50f;
protected float reload = 10f;
protected String shootsound = "shoot";
protected BulletType bullet;
protected Item ammo;
protected int ammoMultiplier = 20;
protected int maxammo = 400;
public Turret(String name) {
@ -62,6 +65,14 @@ public class Turret extends Block{
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
}
@Override
public void drawPlace(int x, int y, boolean valid){
//TODO?
//Draw.color(Color.PURPLE);
Draw.thick(1f);
Draw.dashcircle(x*Vars.tilesize, y*Vars.tilesize, range);
}
@Override
public boolean accept(Item item, Tile dest, Tile source){
return item == ammo && dest.<TurretEntity>entity().ammo < maxammo;
@ -77,19 +88,24 @@ public class Turret extends Block{
TurretEntity entity = tile.entity();
if(entity.hasItem(ammo)){
entity.ammo += 20;
entity.ammo += ammoMultiplier;
entity.removeItem(ammo, 1);
}
if(entity.ammo > 0){
Enemy enemy = (Enemy)Entities.getClosest(tile.worldx(), tile.worldy(), range, e->{
return e instanceof Enemy;
});
if(enemy != null){
if(Timers.get(entity, "target", targetInterval)){
entity.target = (Enemy)Entities.getClosest(tile.worldx(), tile.worldy(), range, e->{
return e instanceof Enemy;
});
}
if(entity.target != null){
entity.rotation = MathUtils.lerpAngleDeg(entity.rotation,
Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed),
Angles.predictAngle(tile.worldx(), tile.worldy(),
entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed),
0.2f*Timers.delta());
float reload = Vars.multiplier*this.reload;
if(Timers.get(tile, reload)){
Effects.sound(shootsound, entity);
@ -110,18 +126,19 @@ public class Turret extends Block{
vector.set(0, 4).setAngle(entity.rotation);
Bullet out = new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, entity.rotation).add();
out.damage = bullet.damage*Vars.multiplier;
out.damage = (int)(bullet.damage*Vars.multiplier);
}
protected void bullet(Tile tile, float angle){
Bullet out = new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, angle).add();
out.damage = bullet.damage*Vars.multiplier;
out.damage = (int)(bullet.damage*Vars.multiplier);
}
public static class TurretEntity extends TileEntity{
public TileEntity target;
public TileEntity blockTarget;
public int ammo;
public float rotation;
public Enemy target;
@Override
public void write(DataOutputStream stream) throws IOException{