mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-13 12:16:53 +07:00
Re-structured Renderer, bugfixes, implemented EnemySpawn system
This commit is contained in:
parent
446e70c52b
commit
b3ef1e2f2f
@ -79,7 +79,7 @@ project(":core") {
|
||||
apply plugin: "java"
|
||||
|
||||
dependencies {
|
||||
compile 'com.github.anuken:ucore:42a04f8cb4'
|
||||
compile 'com.github.anuken:ucore:bded68dbb2'
|
||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
|
||||
}
|
||||
|
@ -22,16 +22,15 @@ import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.ucore.UCore;
|
||||
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.ControlModule;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Control extends ControlModule{
|
||||
public class Control extends Module{
|
||||
int targetscale = baseCameraScale;
|
||||
|
||||
boolean showedTutorial;
|
||||
@ -53,9 +52,6 @@ public class Control extends ControlModule{
|
||||
Vars.debug = true;
|
||||
}
|
||||
|
||||
Core.cameraScale = baseCameraScale;
|
||||
pixelate();
|
||||
|
||||
Gdx.input.setCatchBackKey(true);
|
||||
|
||||
if(android){
|
||||
@ -65,9 +61,7 @@ public class Control extends ControlModule{
|
||||
|
||||
Effects.setShakeFalloff(10000f);
|
||||
|
||||
Draw.addSurface("shadow", Core.cameraScale);
|
||||
|
||||
atlas = new Atlas("sprites.atlas");
|
||||
Core.atlas = new Atlas("sprites.atlas");
|
||||
|
||||
Sounds.load("shoot.wav", "place.wav", "explosion.wav", "enemyshoot.wav",
|
||||
"corexplode.wav", "break.wav", "spawn.wav", "flame.wav", "die.wav",
|
||||
@ -95,19 +89,19 @@ public class Control extends ControlModule{
|
||||
}
|
||||
|
||||
player = new Player();
|
||||
|
||||
spawns = Array.with(
|
||||
new EnemySpawn(Enemy.class){{
|
||||
|
||||
}}
|
||||
);
|
||||
|
||||
printEnemies(100);
|
||||
}
|
||||
/*
|
||||
public void setCameraScale(int scale){
|
||||
Core.cameraScale = scale;
|
||||
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
setCamera(player.x, player.y);
|
||||
Draw.getSurface("pixel").setScale(Core.cameraScale);
|
||||
Draw.getSurface("shadow").setScale(Core.cameraScale);
|
||||
}
|
||||
*/
|
||||
|
||||
public void reset(){
|
||||
weapons.clear();
|
||||
Renderer.clearTiles();
|
||||
Vars.renderer.clearTiles();
|
||||
|
||||
weapons.add(Weapon.blaster);
|
||||
player.weapon = weapons.first();
|
||||
@ -131,12 +125,12 @@ public class Control extends ControlModule{
|
||||
}
|
||||
|
||||
public void play(){
|
||||
Renderer.clearTiles();
|
||||
Vars.renderer.clearTiles();
|
||||
|
||||
player.x = World.core.worldx();
|
||||
player.y = World.core.worldy() - 8f - ((int)(Gdx.graphics.getWidth() / (float)Core.cameraScale * 2) % 2 == 0 ? 0.5f : 0);
|
||||
|
||||
control.camera.position.set(player.x, player.y, 0);
|
||||
Core.camera.position.set(player.x, player.y, 0);
|
||||
|
||||
//multiplying by 2 so you start with more time in the beginning
|
||||
wavetime = waveSpacing()*2;
|
||||
@ -210,12 +204,22 @@ public class Control extends ControlModule{
|
||||
wavetime = waveSpacing();
|
||||
}
|
||||
|
||||
void printEnemies(int wave){
|
||||
for(EnemySpawn spawn : spawns){
|
||||
int spawnamount = spawn.evaluate(wave, 0);
|
||||
|
||||
if(spawnamount > 0){
|
||||
UCore.log(ClassReflection.getSimpleName(spawn.type) + " x" + spawnamount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enemyDeath(){
|
||||
enemies --;
|
||||
}
|
||||
|
||||
public void coreDestroyed(){
|
||||
Effects.shake(5, 6, camera.position.x, camera.position.y);
|
||||
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
|
||||
Sounds.play("corexplode");
|
||||
Tile core = World.core;
|
||||
for(int i = 0; i < 16; i ++){
|
||||
@ -260,21 +264,6 @@ public class Control extends ControlModule{
|
||||
return wave;
|
||||
}
|
||||
|
||||
public void setCameraScale(int amount){
|
||||
targetscale = amount;
|
||||
clampScale();
|
||||
Draw.getSurface("pixel").setScale(targetscale);
|
||||
Draw.getSurface("shadow").setScale(targetscale);
|
||||
}
|
||||
|
||||
public void scaleCamera(int amount){
|
||||
setCameraScale(targetscale + amount);
|
||||
}
|
||||
|
||||
public void clampScale(){
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.inPixels(3)), Math.round(Unit.dp.inPixels((5))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
Musics.shuffleAll();
|
||||
@ -293,14 +282,6 @@ public class Control extends ControlModule{
|
||||
|
||||
if(debug){
|
||||
|
||||
if(Inputs.keyUp(Keys.PLUS)){
|
||||
scaleCamera(1);
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.MINUS)){
|
||||
scaleCamera(-1);
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.SPACE))
|
||||
Effects.sound("shoot", World.core.worldx(), World.core.worldy());
|
||||
|
||||
@ -314,7 +295,7 @@ public class Control extends ControlModule{
|
||||
Timers.mark();
|
||||
SaveIO.load(Gdx.files.local("mapsave.mins"));
|
||||
log("Load time taken: " + Timers.elapsed());
|
||||
Renderer.clearTiles();
|
||||
Vars.renderer.clearTiles();
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.C)){
|
||||
@ -333,25 +314,8 @@ public class Control extends ControlModule{
|
||||
}
|
||||
}
|
||||
|
||||
if(Core.cameraScale != targetscale){
|
||||
float targetzoom = (float)Core.cameraScale / targetscale;
|
||||
camera.zoom = Mathf.lerp(camera.zoom, targetzoom, 0.2f*Timers.delta());
|
||||
|
||||
if(Mathf.in(camera.zoom, targetzoom, 0.005f)){
|
||||
camera.zoom = 1f;
|
||||
Core.cameraScale = targetscale;
|
||||
//super.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
camera.viewportWidth = Gdx.graphics.getWidth() / Core.cameraScale;
|
||||
camera.viewportHeight = Gdx.graphics.getHeight() / Core.cameraScale;
|
||||
|
||||
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
||||
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
||||
}
|
||||
}
|
||||
|
||||
if(GameState.is(State.menu)){
|
||||
clearScreen();
|
||||
}else{
|
||||
if(!GameState.is(State.menu)){
|
||||
|
||||
if(Inputs.keyUp("menu")){
|
||||
if(GameState.is(State.paused)){
|
||||
@ -391,74 +355,13 @@ public class Control extends ControlModule{
|
||||
}else{
|
||||
AndroidInput.doInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(World.core.block() == ProductionBlocks.core){
|
||||
smoothCamera(player.x, player.y, android ? 0.3f : 0.14f);
|
||||
}else{
|
||||
smoothCamera(World.core.worldx(), World.core.worldy(), 0.4f);
|
||||
}
|
||||
|
||||
float prex = camera.position.x, prey = camera.position.y;
|
||||
|
||||
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);
|
||||
|
||||
float deltax = camera.position.x - prex, deltay = camera.position.y - prey;
|
||||
|
||||
if(android){
|
||||
player.x += camera.position.x-prevx;
|
||||
player.y += camera.position.y-prevy;
|
||||
}
|
||||
|
||||
float lastx = camera.position.x, lasty = camera.position.y;
|
||||
|
||||
if(android){
|
||||
camera.position.set((int)camera.position.x, (int)camera.position.y, 0);
|
||||
|
||||
if(Gdx.graphics.getHeight()/Core.cameraScale % 2 == 1){
|
||||
camera.position.add(0, -0.5f, 0);
|
||||
}
|
||||
}
|
||||
|
||||
drawDefault();
|
||||
|
||||
camera.position.set(lastx - deltax, lasty - deltay, 0);
|
||||
|
||||
if(Vars.debug){
|
||||
record();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!GameState.is(State.paused)){
|
||||
Inputs.update();
|
||||
Timers.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Renderer.renderTiles();
|
||||
Entities.draw();
|
||||
Renderer.renderPixelOverlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
super.dispose();
|
||||
World.disposeMaps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height){
|
||||
super.resize(width, height);
|
||||
|
||||
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
||||
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
||||
camera.position.set(player.x, player.y, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.modules.ModuleCore;
|
||||
|
||||
public class Mindustry extends ModuleCore {
|
||||
@ -8,6 +11,7 @@ public class Mindustry extends ModuleCore {
|
||||
@Override
|
||||
public void init(){
|
||||
add(Vars.control = new Control());
|
||||
add(Vars.renderer = new Renderer());
|
||||
add(Vars.ui = new UI());
|
||||
}
|
||||
|
||||
@ -26,5 +30,10 @@ public class Mindustry extends ModuleCore {
|
||||
//Gdx.app.getClipboard().setContents(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(!GameState.is(State.paused)){
|
||||
Inputs.update();
|
||||
Timers.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -20,16 +23,103 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.graphics.Cache;
|
||||
import io.anuke.ucore.graphics.Caches;
|
||||
import io.anuke.ucore.modules.RendererModule;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.GridMap;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
public class Renderer{
|
||||
private static int chunksize = 32;
|
||||
private static GridMap<Cache> caches = new GridMap<>();
|
||||
public class Renderer extends RendererModule{
|
||||
int targetscale = baseCameraScale;
|
||||
int chunksize = 32;
|
||||
GridMap<Cache> caches = new GridMap<>();
|
||||
|
||||
public static void renderTiles(){
|
||||
public Renderer(){
|
||||
Core.cameraScale = baseCameraScale;
|
||||
pixelate();
|
||||
|
||||
Draw.addSurface("shadow", Core.cameraScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(Core.cameraScale != targetscale){
|
||||
float targetzoom = (float)Core.cameraScale / targetscale;
|
||||
camera.zoom = Mathf.lerp(camera.zoom, targetzoom, 0.2f*Timers.delta());
|
||||
|
||||
if(Mathf.in(camera.zoom, targetzoom, 0.005f)){
|
||||
camera.zoom = 1f;
|
||||
Core.cameraScale = targetscale;
|
||||
camera.viewportWidth = Gdx.graphics.getWidth() / Core.cameraScale;
|
||||
camera.viewportHeight = Gdx.graphics.getHeight() / Core.cameraScale;
|
||||
|
||||
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
||||
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
||||
}
|
||||
}
|
||||
|
||||
if(GameState.is(State.menu)){
|
||||
clearScreen();
|
||||
}else{
|
||||
|
||||
if(World.core.block() == ProductionBlocks.core){
|
||||
smoothCamera(player.x, player.y, android ? 0.3f : 0.14f);
|
||||
}else{
|
||||
smoothCamera(World.core.worldx(), World.core.worldy(), 0.4f);
|
||||
}
|
||||
|
||||
float prex = camera.position.x, prey = camera.position.y;
|
||||
|
||||
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);
|
||||
|
||||
float deltax = camera.position.x - prex, deltay = camera.position.y - prey;
|
||||
|
||||
if(android){
|
||||
player.x += camera.position.x-prevx;
|
||||
player.y += camera.position.y-prevy;
|
||||
}
|
||||
|
||||
float lastx = camera.position.x, lasty = camera.position.y;
|
||||
|
||||
if(android){
|
||||
camera.position.set((int)camera.position.x, (int)camera.position.y, 0);
|
||||
|
||||
if(Gdx.graphics.getHeight()/Core.cameraScale % 2 == 1){
|
||||
camera.position.add(0, -0.5f, 0);
|
||||
}
|
||||
}
|
||||
|
||||
drawDefault();
|
||||
|
||||
camera.position.set(lastx - deltax, lasty - deltay, 0);
|
||||
|
||||
if(Vars.debug){
|
||||
record();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
renderTiles();
|
||||
Entities.draw();
|
||||
renderPixelOverlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height){
|
||||
super.resize(width, height);
|
||||
|
||||
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
||||
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
||||
camera.position.set(player.x, player.y, 0);
|
||||
}
|
||||
|
||||
void renderTiles(){
|
||||
int chunksx = World.width()/chunksize, chunksy = World.height()/chunksize;
|
||||
|
||||
//render the entire map
|
||||
@ -48,7 +138,7 @@ public class Renderer{
|
||||
}
|
||||
}
|
||||
|
||||
OrthographicCamera camera = control.camera;
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
Draw.end();
|
||||
|
||||
@ -105,14 +195,14 @@ public class Renderer{
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearTiles(){
|
||||
public void clearTiles(){
|
||||
for(Cache cache : caches.values())
|
||||
cache.dispose();
|
||||
|
||||
caches.clear();
|
||||
}
|
||||
|
||||
public static void renderPixelOverlay(){
|
||||
void renderPixelOverlay(){
|
||||
|
||||
if(player.recipe != null && Inventory.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android)){
|
||||
float x = 0;
|
||||
@ -202,11 +292,11 @@ public class Renderer{
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawHealth(float x, float y, float health, float maxhealth){
|
||||
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){
|
||||
public void drawBar(Color color, float x, float y, float fraction){
|
||||
float len = 3;
|
||||
float offset = 7;
|
||||
|
||||
@ -226,4 +316,20 @@ public class Renderer{
|
||||
Draw.line(x - len + 1, y - offset, x - len + w, y - offset);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
public void setCameraScale(int amount){
|
||||
targetscale = amount;
|
||||
clampScale();
|
||||
Draw.getSurface("pixel").setScale(targetscale);
|
||||
Draw.getSurface("shadow").setScale(targetscale);
|
||||
}
|
||||
|
||||
public void scaleCamera(int amount){
|
||||
setCameraScale(targetscale + amount);
|
||||
}
|
||||
|
||||
public void clampScale(){
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.inPixels(3)), Math.round(Unit.dp.inPixels((5))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -285,15 +285,15 @@ public class UI extends SceneModule{
|
||||
|
||||
end();
|
||||
}}.right().bottom().uniformX();
|
||||
|
||||
/*
|
||||
row();
|
||||
|
||||
if(!android){
|
||||
new button("Upgrades", ()->{
|
||||
upgrades.show();
|
||||
}).uniformX().fillX();
|
||||
}
|
||||
get().setVisible(play);
|
||||
}*/
|
||||
visible(play);
|
||||
|
||||
}}.end();
|
||||
|
||||
|
@ -35,6 +35,7 @@ public class Vars{
|
||||
public static final int tilesize = 8;
|
||||
|
||||
public static Control control;
|
||||
public static Renderer renderer;
|
||||
public static UI ui;
|
||||
|
||||
public static Player player;
|
||||
|
@ -6,13 +6,17 @@ public class EnemySpawn{
|
||||
public final Class<? extends Enemy> type;
|
||||
int before = Integer.MAX_VALUE;
|
||||
int after;
|
||||
int spacing;
|
||||
int spacing = 1;
|
||||
float scaling = 9999f;
|
||||
|
||||
public EnemySpawn(Class<? extends Enemy> type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int evaluate(int wave, int lane){
|
||||
return 0;
|
||||
if(wave < after || wave > before || wave % spacing != 0){
|
||||
return 0;
|
||||
}
|
||||
return 1 * Math.max((int)((wave / spacing) / scaling), 1);
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class GestureHandler extends GestureAdapter{
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(player.recipe == null){
|
||||
player.x -= deltaX*control.camera.zoom/Core.cameraScale;
|
||||
player.y += deltaY*control.camera.zoom/Core.cameraScale;
|
||||
player.x -= deltaX*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
}else{
|
||||
AndroidInput.mousex += deltaX;
|
||||
AndroidInput.mousey += deltaY;
|
||||
@ -57,8 +57,8 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
||||
|
||||
player.x -= vec.x*control.camera.zoom/Core.cameraScale;
|
||||
player.y += vec.y*control.camera.zoom/Core.cameraScale;
|
||||
player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
pinch1.set(pointer1);
|
||||
pinch2.set(pointer2);
|
||||
@ -74,7 +74,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
if(Math.abs(distance - initzoom) > Unit.dp.inPixels(100f) && !zoomed){
|
||||
int amount = (distance > initzoom ? 1 : -1);
|
||||
control.scaleCamera(Math.round(Unit.dp.inPixels(amount)));
|
||||
renderer.scaleCamera(Math.round(Unit.dp.inPixels(amount)));
|
||||
initzoom = distance;
|
||||
zoomed = true;
|
||||
return true;
|
||||
|
@ -23,7 +23,7 @@ public class Input{
|
||||
if(player.health <= 0) return;
|
||||
|
||||
if(Inputs.scrolled()){
|
||||
Vars.control.scaleCamera(Inputs.scroll());
|
||||
Vars.renderer.scaleCamera(Inputs.scroll());
|
||||
//TODO
|
||||
/*
|
||||
int index = currentWeapon();
|
||||
|
@ -14,7 +14,8 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@ -22,6 +23,7 @@ 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.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
@ -85,16 +87,17 @@ public class SaveIO{
|
||||
private static FormatProvider provider = null;
|
||||
|
||||
//TODO automatic registration of types?
|
||||
private static final ObjectMap<Class<? extends Enemy>, Byte> enemyIDs = new ObjectMap<Class<? extends Enemy>, Byte>(){{
|
||||
put(Enemy.class, (byte)0);
|
||||
put(FastEnemy.class, (byte)1);
|
||||
put(BossEnemy.class, (byte)2);
|
||||
put(FlameEnemy.class, (byte)3);
|
||||
}};
|
||||
private static final Array<Class<? extends Enemy>> enemyIDs = Array.with(
|
||||
Enemy.class,
|
||||
FastEnemy.class,
|
||||
BossEnemy.class,
|
||||
FlameEnemy.class
|
||||
);
|
||||
|
||||
private static final ObjectMap<Byte, Class<? extends Enemy>> idEnemies = new ObjectMap<Byte, Class<? extends Enemy>>(){{
|
||||
for(Class<? extends Enemy> value : enemyIDs.keys())
|
||||
put(enemyIDs.get(value), value);
|
||||
private static final ObjectMap<Class<? extends Enemy>, Byte> idEnemies = new ObjectMap<Class<? extends Enemy>, Byte>(){{
|
||||
for(int i = 0; i < enemyIDs.size; i ++){
|
||||
put(enemyIDs.get(i), (byte)i);
|
||||
}
|
||||
}};
|
||||
|
||||
public static void saveToSlot(int slot){
|
||||
@ -179,7 +182,7 @@ public class SaveIO{
|
||||
for(Entity entity : Entities.all()){
|
||||
if(entity instanceof Enemy){
|
||||
Enemy enemy = (Enemy)entity;
|
||||
stream.writeByte(enemyIDs.get(enemy.getClass())); //type
|
||||
stream.writeByte(idEnemies.get(enemy.getClass())); //type
|
||||
stream.writeByte(enemy.spawn); //lane
|
||||
stream.writeFloat(enemy.x); //x
|
||||
stream.writeFloat(enemy.y); //y
|
||||
@ -266,7 +269,7 @@ public class SaveIO{
|
||||
Vars.player.x = playerx;
|
||||
Vars.player.y = playery;
|
||||
Vars.player.health = playerhealth;
|
||||
Vars.control.camera.position.set(playerx, playery, 0);
|
||||
Core.camera.position.set(playerx, playery, 0);
|
||||
|
||||
//weapons
|
||||
|
||||
@ -308,7 +311,7 @@ public class SaveIO{
|
||||
int health = stream.readInt();
|
||||
|
||||
try{
|
||||
Enemy enemy = (Enemy)ClassReflection.getConstructor(idEnemies.get(type), int.class).newInstance(lane);
|
||||
Enemy enemy = (Enemy)ClassReflection.getConstructor(enemyIDs.get(type), int.class).newInstance(lane);
|
||||
enemy.health = health;
|
||||
enemy.x = x;
|
||||
enemy.y = y;
|
||||
@ -331,7 +334,7 @@ public class SaveIO{
|
||||
int tiles = stream.readInt();
|
||||
|
||||
World.loadMap(mapid, seed);
|
||||
Renderer.clearTiles();
|
||||
Vars.renderer.clearTiles();
|
||||
|
||||
for(Enemy enemy : enemiesToUpdate){
|
||||
enemy.findClosestNode();
|
||||
|
@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
import io.anuke.mindustry.Renderer;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
@ -62,7 +62,7 @@ public class Purifier extends Conduit{
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
float fract = (float)tile.entity.items.get(input, 0) / itemCapacity;
|
||||
|
||||
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.mindustry.Renderer;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -47,7 +47,7 @@ public class Router extends Block{
|
||||
|
||||
float fract = (float)tile.entity.totalItems()/maxitems;
|
||||
|
||||
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,7 +6,6 @@ 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;
|
||||
@ -65,7 +64,7 @@ public class Turret extends Block{
|
||||
if(fract > 0)
|
||||
fract = Mathf.clamp(fract, 0.24f, 1f);
|
||||
|
||||
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user