Major restructuring of Vars class- made global state less messy
This commit is contained in:
@@ -6,12 +6,15 @@ import com.badlogic.gdx.Application.ApplicationType;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input.Keys;
|
import com.badlogic.gdx.Input.Keys;
|
||||||
import com.badlogic.gdx.input.GestureDetector;
|
import com.badlogic.gdx.input.GestureDetector;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.GameState.State;
|
||||||
|
import io.anuke.mindustry.ai.Pathfind;
|
||||||
|
import io.anuke.mindustry.entities.*;
|
||||||
import io.anuke.mindustry.input.AndroidInput;
|
import io.anuke.mindustry.input.AndroidInput;
|
||||||
import io.anuke.mindustry.input.GestureHandler;
|
import io.anuke.mindustry.input.GestureHandler;
|
||||||
import io.anuke.mindustry.input.Input;
|
import io.anuke.mindustry.input.Input;
|
||||||
import io.anuke.mindustry.world.Generator;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||||
import io.anuke.ucore.core.*;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
@@ -23,6 +26,19 @@ import io.anuke.ucore.util.Timers;
|
|||||||
public class Control extends RendererModule{
|
public class Control extends RendererModule{
|
||||||
public int rangex = 10, rangey = 10;
|
public int rangex = 10, rangey = 10;
|
||||||
public float targetzoom = 1f;
|
public float targetzoom = 1f;
|
||||||
|
|
||||||
|
boolean showedTutorial;
|
||||||
|
boolean hiscore = false;
|
||||||
|
|
||||||
|
final Array<Weapon> weapons = new Array<>();
|
||||||
|
//final ObjectMap<Weapon, Boolean> weapons = new ObjectMap<Weapon, Boolean>();
|
||||||
|
|
||||||
|
int wave = 1;
|
||||||
|
float wavetime;
|
||||||
|
int enemies = 0;
|
||||||
|
|
||||||
|
float respawntime;
|
||||||
|
|
||||||
//GifRecorder recorder = new GifRecorder(batch);
|
//GifRecorder recorder = new GifRecorder(batch);
|
||||||
|
|
||||||
public Control(){
|
public Control(){
|
||||||
@@ -46,7 +62,7 @@ public class Control extends RendererModule{
|
|||||||
|
|
||||||
Musics.load("1.mp3", "2.mp3", "3.mp3");
|
Musics.load("1.mp3", "2.mp3", "3.mp3");
|
||||||
|
|
||||||
Generator.loadMaps();
|
World.loadMaps();
|
||||||
|
|
||||||
KeyBinds.defaults(
|
KeyBinds.defaults(
|
||||||
"up", Keys.W,
|
"up", Keys.W,
|
||||||
@@ -67,6 +83,163 @@ public class Control extends RendererModule{
|
|||||||
player = new Player();
|
player = new Player();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset(){
|
||||||
|
weapons.clear();
|
||||||
|
|
||||||
|
weapons.add(Weapon.blaster);
|
||||||
|
player.weapon = weapons.first();
|
||||||
|
|
||||||
|
wave = 1;
|
||||||
|
wavetime = waveSpacing();
|
||||||
|
Entities.clear();
|
||||||
|
enemies = 0;
|
||||||
|
|
||||||
|
if(!android)
|
||||||
|
player.add();
|
||||||
|
|
||||||
|
player.heal();
|
||||||
|
Inventory.clearItems();
|
||||||
|
World.spawnpoints.clear();
|
||||||
|
respawntime = -1;
|
||||||
|
hiscore = false;
|
||||||
|
|
||||||
|
ui.updateItems();
|
||||||
|
ui.updateWeapons();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play(){
|
||||||
|
player.x = World.core.worldx();
|
||||||
|
player.y = World.core.worldy()-8;
|
||||||
|
|
||||||
|
control.camera.position.set(player.x, player.y, 0);
|
||||||
|
|
||||||
|
wavetime = waveSpacing();
|
||||||
|
|
||||||
|
if(showedTutorial || !Settings.getBool("tutorial")){
|
||||||
|
GameState.set(State.playing);
|
||||||
|
}else{
|
||||||
|
GameState.set(State.paused);
|
||||||
|
ui.showTutorial();
|
||||||
|
showedTutorial = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasWeapon(Weapon weapon){
|
||||||
|
return weapons.contains(weapon, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWeapon(Weapon weapon){
|
||||||
|
weapons.add(weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Array<Weapon> getWeapons(){
|
||||||
|
return weapons;
|
||||||
|
}
|
||||||
|
|
||||||
|
void runWave(){
|
||||||
|
int amount = wave;
|
||||||
|
Sounds.play("spawn");
|
||||||
|
|
||||||
|
Pathfind.updatePath();
|
||||||
|
|
||||||
|
for(int i = 0; i < amount; i ++){
|
||||||
|
int pos = i;
|
||||||
|
|
||||||
|
for(int w = 0; w < World.spawnpoints.size; w ++){
|
||||||
|
int point = w;
|
||||||
|
Tile tile = World.spawnpoints.get(w);
|
||||||
|
|
||||||
|
Timers.run(i*30f, ()->{
|
||||||
|
|
||||||
|
Enemy enemy = null;
|
||||||
|
|
||||||
|
if(wave%5 == 0 & pos < wave/5){
|
||||||
|
enemy = new BossEnemy(point);
|
||||||
|
}else if(wave > 3 && pos < amount/2){
|
||||||
|
enemy = new FastEnemy(point);
|
||||||
|
}else if(wave > 8 && pos % 3 == 0 && wave%2==1){
|
||||||
|
enemy = new FlameEnemy(point);
|
||||||
|
}else{
|
||||||
|
enemy = new Enemy(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
enemy.set(tile.worldx(), tile.worldy());
|
||||||
|
Effects.effect("spawn", enemy);
|
||||||
|
enemy.add();
|
||||||
|
});
|
||||||
|
|
||||||
|
enemies ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wave ++;
|
||||||
|
|
||||||
|
int last = Settings.getInt("hiscore"+maps[World.getMap()]);
|
||||||
|
|
||||||
|
if(wave > last){
|
||||||
|
Settings.putInt("hiscore"+maps[World.getMap()], wave);
|
||||||
|
Settings.save();
|
||||||
|
hiscore = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wavetime = waveSpacing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enemyDeath(){
|
||||||
|
enemies --;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void coreDestroyed(){
|
||||||
|
Effects.shake(5, 6);
|
||||||
|
Sounds.play("corexplode");
|
||||||
|
Tile core = World.core;
|
||||||
|
for(int i = 0; i < 16; i ++){
|
||||||
|
Timers.run(i*2, ()->{
|
||||||
|
Effects.effect("explosion", core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Effects.effect("coreexplosion", core.worldx(), core.worldy());
|
||||||
|
|
||||||
|
Timers.run(60, ()->{
|
||||||
|
ui.showRestart();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
float waveSpacing(){
|
||||||
|
int scale = Settings.getInt("difficulty");
|
||||||
|
float out = (scale == 0 ? 2f : scale == 1f ? 1f : 0.5f);
|
||||||
|
return wavespace*out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clampZoom(){
|
||||||
|
targetzoom = Mathf.clamp(targetzoom, 0.5f, 2f);
|
||||||
|
camera.zoom = Mathf.clamp(camera.zoom, 0.5f, 2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHighScore(){
|
||||||
|
return hiscore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnemiesRemaining(){
|
||||||
|
return enemies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getWaveCountdown(){
|
||||||
|
return wavetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRespawnTime(){
|
||||||
|
return respawntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRespawnTime(float respawntime){
|
||||||
|
this.respawntime = respawntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWave(){
|
||||||
|
return wave;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
Musics.shuffleAll();
|
Musics.shuffleAll();
|
||||||
@@ -80,11 +253,6 @@ public class Control extends RendererModule{
|
|||||||
EffectLoader.create();
|
EffectLoader.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clampZoom(){
|
|
||||||
targetzoom = Mathf.clamp(targetzoom, 0.5f, 2f);
|
|
||||||
camera.zoom = Mathf.clamp(camera.zoom, 0.5f, 2f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
@@ -94,30 +262,30 @@ public class Control extends RendererModule{
|
|||||||
//camera.zoom = MathUtils.lerp(camera.zoom, targetzoom, 0.5f*delta());
|
//camera.zoom = MathUtils.lerp(camera.zoom, targetzoom, 0.5f*delta());
|
||||||
|
|
||||||
if(Inputs.keyUp(Keys.SPACE) && debug)
|
if(Inputs.keyUp(Keys.SPACE) && debug)
|
||||||
Effects.sound("shoot", core.worldx(), core.worldy());
|
Effects.sound("shoot", World.core.worldx(), World.core.worldy());
|
||||||
|
|
||||||
if(!playing){
|
if(GameState.is(State.menu)){
|
||||||
clearScreen();
|
clearScreen();
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
if(Inputs.keyUp("menu")){
|
if(Inputs.keyUp("menu")){
|
||||||
if(paused){
|
if(GameState.is(State.paused)){
|
||||||
ui.hideMenu();
|
ui.hideMenu();
|
||||||
paused = false;
|
GameState.set(State.paused);
|
||||||
}else{
|
}else{
|
||||||
ui.showMenu();
|
ui.showMenu();
|
||||||
paused = true;
|
GameState.set(State.paused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!paused){
|
if(!GameState.is(State.paused)){
|
||||||
|
|
||||||
if(respawntime > 0){
|
if(respawntime > 0){
|
||||||
|
|
||||||
respawntime -= delta();
|
respawntime -= delta();
|
||||||
|
|
||||||
if(respawntime <= 0){
|
if(respawntime <= 0){
|
||||||
player.set(core.worldx(), core.worldy()-8);
|
player.set(World.core.worldx(), World.core.worldy()-8);
|
||||||
player.heal();
|
player.heal();
|
||||||
player.add();
|
player.add();
|
||||||
Effects.sound("respawn");
|
Effects.sound("respawn");
|
||||||
@@ -128,7 +296,7 @@ public class Control extends RendererModule{
|
|||||||
wavetime -= delta();
|
wavetime -= delta();
|
||||||
|
|
||||||
if(wavetime <= 0 || (debug && Inputs.keyUp(Keys.F))){
|
if(wavetime <= 0 || (debug && Inputs.keyUp(Keys.F))){
|
||||||
GameState.runWave();
|
runWave();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entities.update();
|
Entities.update();
|
||||||
@@ -141,15 +309,15 @@ public class Control extends RendererModule{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(core.block() == ProductionBlocks.core){
|
if(World.core.block() == ProductionBlocks.core){
|
||||||
smoothCamera(player.x, player.y, android ? 0.3f : 0.14f);
|
smoothCamera(player.x, player.y, android ? 0.3f : 0.14f);
|
||||||
}else{
|
}else{
|
||||||
smoothCamera(core.worldx(), core.worldy(), 0.4f);
|
smoothCamera(World.core.worldx(), World.core.worldy(), 0.4f);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateShake(0.5f);
|
updateShake(0.5f);
|
||||||
float prevx = camera.position.x, prevy = camera.position.y;
|
float prevx = camera.position.x, prevy = camera.position.y;
|
||||||
clampCamera(-tilesize / 2f, -tilesize / 2f, pixsize - tilesize / 2f, pixsize - tilesize / 2f);
|
clampCamera(-tilesize / 2f, -tilesize / 2f, World.pixsize - tilesize / 2f, World.pixsize - tilesize / 2f);
|
||||||
|
|
||||||
if(android){
|
if(android){
|
||||||
player.x += camera.position.x-prevx;
|
player.x += camera.position.x-prevx;
|
||||||
@@ -178,7 +346,7 @@ public class Control extends RendererModule{
|
|||||||
//recorder.update();
|
//recorder.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!paused){
|
if(!GameState.is(State.paused)){
|
||||||
Inputs.update();
|
Inputs.update();
|
||||||
Timers.update(Gdx.graphics.getDeltaTime()*60f);
|
Timers.update(Gdx.graphics.getDeltaTime()*60f);
|
||||||
}
|
}
|
||||||
@@ -201,4 +369,5 @@ public class Control extends RendererModule{
|
|||||||
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
|
||||||
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,130 +1,17 @@
|
|||||||
package io.anuke.mindustry;
|
package io.anuke.mindustry;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.ai.Pathfind;
|
|
||||||
import io.anuke.mindustry.entities.*;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.ucore.core.Effects;
|
|
||||||
import io.anuke.ucore.core.Settings;
|
|
||||||
import io.anuke.ucore.core.Sounds;
|
|
||||||
import io.anuke.ucore.entities.Entities;
|
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
import io.anuke.ucore.util.Timers;
|
|
||||||
|
|
||||||
public class GameState{
|
public class GameState{
|
||||||
|
private static State state = State.menu;
|
||||||
|
|
||||||
public static void reset(){
|
public static void set(State astate){
|
||||||
for(Weapon weapon : Weapon.values()){
|
state = astate;
|
||||||
weapons.put(weapon, weapon.unlocked);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentWeapon = Weapon.blaster;
|
|
||||||
|
|
||||||
wave = 1;
|
|
||||||
wavetime = waveSpacing();
|
|
||||||
Entities.clear();
|
|
||||||
enemies = 0;
|
|
||||||
|
|
||||||
if(!android)
|
|
||||||
player.add();
|
|
||||||
|
|
||||||
player.heal();
|
|
||||||
Inventory.clearItems();
|
|
||||||
spawnpoints.clear();
|
|
||||||
respawntime = -1;
|
|
||||||
hiscore = false;
|
|
||||||
|
|
||||||
ui.updateItems();
|
|
||||||
ui.updateWeapons();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void play(){
|
public static boolean is(State astate){
|
||||||
player.x = core.worldx();
|
return state == astate;
|
||||||
player.y = core.worldy()-8;
|
|
||||||
|
|
||||||
control.camera.position.set(player.x, player.y, 0);
|
|
||||||
|
|
||||||
wavetime = waveSpacing();
|
|
||||||
|
|
||||||
if(showedTutorial || !Settings.getBool("tutorial")){
|
|
||||||
playing = true;
|
|
||||||
paused = false;
|
|
||||||
}else{
|
|
||||||
playing = true;
|
|
||||||
paused = true;
|
|
||||||
ui.showTutorial();
|
|
||||||
showedTutorial = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runWave(){
|
public static enum State{
|
||||||
int amount = wave;
|
paused, playing, menu, dead
|
||||||
Sounds.play("spawn");
|
|
||||||
|
|
||||||
Pathfind.updatePath();
|
|
||||||
|
|
||||||
for(int i = 0; i < amount; i ++){
|
|
||||||
int pos = i;
|
|
||||||
|
|
||||||
for(int w = 0; w < spawnpoints.size; w ++){
|
|
||||||
int point = w;
|
|
||||||
Tile tile = spawnpoints.get(w);
|
|
||||||
|
|
||||||
Timers.run(i*30f, ()->{
|
|
||||||
|
|
||||||
Enemy enemy = null;
|
|
||||||
|
|
||||||
if(wave%5 == 0 & pos < wave/5){
|
|
||||||
enemy = new BossEnemy(point);
|
|
||||||
}else if(wave > 3 && pos < amount/2){
|
|
||||||
enemy = new FastEnemy(point);
|
|
||||||
}else if(wave > 8 && pos % 3 == 0 && wave%2==1){
|
|
||||||
enemy = new FlameEnemy(point);
|
|
||||||
}else{
|
|
||||||
enemy = new Enemy(point);
|
|
||||||
}
|
|
||||||
|
|
||||||
enemy.set(tile.worldx(), tile.worldy());
|
|
||||||
Effects.effect("spawn", enemy);
|
|
||||||
enemy.add();
|
|
||||||
});
|
|
||||||
|
|
||||||
enemies ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wave ++;
|
|
||||||
|
|
||||||
int last = Settings.getInt("hiscore"+maps[currentMap]);
|
|
||||||
|
|
||||||
if(wave > last){
|
|
||||||
Settings.putInt("hiscore"+maps[currentMap], wave);
|
|
||||||
Settings.save();
|
|
||||||
hiscore = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
wavetime = waveSpacing();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void coreDestroyed(){
|
|
||||||
Effects.shake(5, 6);
|
|
||||||
Sounds.play("corexplode");
|
|
||||||
for(int i = 0; i < 16; i ++){
|
|
||||||
Timers.run(i*2, ()->{
|
|
||||||
Effects.effect("explosion", core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Effects.effect("coreexplosion", core.worldx(), core.worldy());
|
|
||||||
|
|
||||||
Timers.run(60, ()->{
|
|
||||||
ui.showRestart();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float waveSpacing(){
|
|
||||||
int scale = Settings.getInt("difficulty");
|
|
||||||
float out = (scale == 0 ? 2f : scale == 1f ? 1f : 0.5f);
|
|
||||||
return wavespace*out;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package io.anuke.mindustry;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.resource.ItemStack;
|
import io.anuke.mindustry.resource.ItemStack;
|
||||||
|
|
||||||
public class Inventory{
|
public class Inventory{
|
||||||
|
final static ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||||
|
|
||||||
public static void clearItems(){
|
public static void clearItems(){
|
||||||
items.clear();
|
items.clear();
|
||||||
@@ -20,6 +23,14 @@ public class Inventory{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Iterable<Item> getItemTypes(){
|
||||||
|
return items.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAmount(Item item){
|
||||||
|
return items.get(item, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public static void addItem(Item item, int amount){
|
public static void addItem(Item item, int amount){
|
||||||
items.put(item, items.get(item, 0)+amount);
|
items.put(item, items.get(item, 0)+amount);
|
||||||
ui.updateItems();
|
ui.updateItems();
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ public class Mindustry extends Core {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postInit(){
|
public void postInit(){
|
||||||
GameState.reset();
|
Vars.control.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ import io.anuke.ucore.entities.Entity;
|
|||||||
import io.anuke.ucore.graphics.Cache;
|
import io.anuke.ucore.graphics.Cache;
|
||||||
import io.anuke.ucore.graphics.Caches;
|
import io.anuke.ucore.graphics.Caches;
|
||||||
import io.anuke.ucore.scene.utils.Cursors;
|
import io.anuke.ucore.scene.utils.Cursors;
|
||||||
import io.anuke.ucore.util.GridMap;
|
import io.anuke.ucore.util.*;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
import io.anuke.ucore.util.Timers;
|
|
||||||
|
|
||||||
public class Renderer{
|
public class Renderer{
|
||||||
private static int chunksize = 32;
|
private static int chunksize = 32;
|
||||||
@@ -82,8 +80,8 @@ public class Renderer{
|
|||||||
int worldx = Mathf.scl(camera.position.x, tilesize) + x;
|
int worldx = Mathf.scl(camera.position.x, tilesize) + x;
|
||||||
int worldy = Mathf.scl(camera.position.y, tilesize) + y;
|
int worldy = Mathf.scl(camera.position.y, tilesize) + y;
|
||||||
|
|
||||||
if(Mathf.inBounds(worldx, worldy, tiles)){
|
if( World.tile(worldx, worldy) != null){
|
||||||
Tile tile = tiles[worldx][worldy];
|
Tile tile = World.tile(worldx, worldy);
|
||||||
if(l == 0){
|
if(l == 0){
|
||||||
if(tile.block() != Blocks.air)
|
if(tile.block() != Blocks.air)
|
||||||
Draw.rect(tile.block().shadow, worldx * tilesize, worldy * tilesize);
|
Draw.rect(tile.block().shadow, worldx * tilesize, worldy * tilesize);
|
||||||
@@ -106,7 +104,7 @@ public class Renderer{
|
|||||||
|
|
||||||
public static void renderPixelOverlay(){
|
public static void renderPixelOverlay(){
|
||||||
|
|
||||||
if(recipe != null && (!ui.hasMouse() || android)){
|
if(player.recipe != null && (!ui.hasMouse() || android)){
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
|
|
||||||
@@ -126,21 +124,21 @@ public class Renderer{
|
|||||||
tiley = World.tiley();
|
tiley = World.tiley();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean valid = World.validPlace(tilex, tiley, recipe.result);
|
boolean valid = World.validPlace(tilex, tiley, player.recipe.result);
|
||||||
|
|
||||||
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
|
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
|
||||||
Draw.thickness(2f);
|
Draw.thickness(2f);
|
||||||
Draw.square(x, y, tilesize / 2 + MathUtils.sin(Timers.time() / 6f) + 1);
|
Draw.square(x, y, tilesize / 2 + MathUtils.sin(Timers.time() / 6f) + 1);
|
||||||
|
|
||||||
if(recipe.result.rotate){
|
if(player.recipe.result.rotate){
|
||||||
Draw.color("orange");
|
Draw.color("orange");
|
||||||
vector.set(7, 0).rotate(rotation * 90);
|
Tmp.v1.set(7, 0).rotate(player.rotation * 90);
|
||||||
Draw.line(x, y, x + vector.x, y + vector.y);
|
Draw.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.thickness(1f);
|
Draw.thickness(1f);
|
||||||
Draw.color("scarlet");
|
Draw.color("scarlet");
|
||||||
for(Tile spawn : spawnpoints){
|
for(Tile spawn : World.spawnpoints){
|
||||||
Draw.dashcircle(spawn.worldx(), spawn.worldy(), enemyspawnspace);
|
Draw.dashcircle(spawn.worldx(), spawn.worldy(), enemyspawnspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,23 +154,23 @@ public class Renderer{
|
|||||||
if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear()){
|
if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear()){
|
||||||
Tile tile = World.cursorTile();
|
Tile tile = World.cursorTile();
|
||||||
if(tile.breakable() && tile.block() != ProductionBlocks.core){
|
if(tile.breakable() && tile.block() != ProductionBlocks.core){
|
||||||
Draw.color(Color.YELLOW, Color.SCARLET, breaktime / tile.block().breaktime);
|
Draw.color(Color.YELLOW, Color.SCARLET, player.breaktime / tile.block().breaktime);
|
||||||
Draw.square(tile.worldx(), tile.worldy(), 4);
|
Draw.square(tile.worldx(), tile.worldy(), 4);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(android && breaktime > 0){
|
if(android && player.breaktime > 0){
|
||||||
Tile tile = AndroidInput.selected();
|
Tile tile = AndroidInput.selected();
|
||||||
if(tile.breakable() && tile.block() != ProductionBlocks.core){
|
if(tile.breakable() && tile.block() != ProductionBlocks.core){
|
||||||
float fract = breaktime / tile.block().breaktime;
|
float fract = player.breaktime / tile.block().breaktime;
|
||||||
Draw.color(Color.YELLOW, Color.SCARLET, fract);
|
Draw.color(Color.YELLOW, Color.SCARLET, fract);
|
||||||
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f-fract)*26);
|
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f-fract)*26);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(recipe == null && !ui.hasMouse()){
|
if(player.recipe == null && !ui.hasMouse()){
|
||||||
Tile tile = World.cursorTile();
|
Tile tile = World.cursorTile();
|
||||||
|
|
||||||
if(tile != null && tile.block() != Blocks.air){
|
if(tile != null && tile.block() != Blocks.air){
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.badlogic.gdx.utils.Array;
|
|||||||
import com.badlogic.gdx.utils.Timer;
|
import com.badlogic.gdx.utils.Timer;
|
||||||
import com.badlogic.gdx.utils.Timer.Task;
|
import com.badlogic.gdx.utils.Timer.Task;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Weapon;
|
import io.anuke.mindustry.entities.Weapon;
|
||||||
import io.anuke.mindustry.input.AndroidInput;
|
import io.anuke.mindustry.input.AndroidInput;
|
||||||
import io.anuke.mindustry.resource.*;
|
import io.anuke.mindustry.resource.*;
|
||||||
@@ -40,9 +41,9 @@ public class UI extends SceneModule{
|
|||||||
Dialog about, menu, restart, tutorial, levels, upgrades;
|
Dialog about, menu, restart, tutorial, levels, upgrades;
|
||||||
Tooltip tooltip;
|
Tooltip tooltip;
|
||||||
|
|
||||||
VisibilityProvider play = () -> playing;
|
VisibilityProvider play = () -> !GameState.is(State.menu);
|
||||||
|
|
||||||
VisibilityProvider nplay = () -> !playing;
|
VisibilityProvider nplay = () -> GameState.is(State.menu);
|
||||||
|
|
||||||
public UI() {
|
public UI() {
|
||||||
Dialog.setShowAction(()-> sequence(Actions.moveToAligned(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight(), Align.center),
|
Dialog.setShowAction(()-> sequence(Actions.moveToAligned(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight(), Align.center),
|
||||||
@@ -95,7 +96,7 @@ public class UI extends SceneModule{
|
|||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
if(!playing){
|
if(nplay.visible()){
|
||||||
scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
scene.getBatch().begin();
|
scene.getBatch().begin();
|
||||||
|
|
||||||
@@ -142,11 +143,11 @@ public class UI extends SceneModule{
|
|||||||
public Dialog show(Scene scene){
|
public Dialog show(Scene scene){
|
||||||
super.show(scene);
|
super.show(scene);
|
||||||
restart.content().clearChildren();
|
restart.content().clearChildren();
|
||||||
if(hiscore){
|
if(control.isHighScore()){
|
||||||
restart.content().add("[YELLOW]New highscore!").pad(6);
|
restart.content().add("[YELLOW]New highscore!").pad(6);
|
||||||
restart.content().row();
|
restart.content().row();
|
||||||
}
|
}
|
||||||
restart.content().add("You lasted until wave [GREEN]" + wave + "[].").pad(6);
|
restart.content().add("You lasted until wave [GREEN]" + control.getWave() + "[].").pad(6);
|
||||||
restart.pack();
|
restart.pack();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -154,8 +155,8 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
restart.getButtonTable().addButton("Back to menu", ()->{
|
restart.getButtonTable().addButton("Back to menu", ()->{
|
||||||
restart.hide();
|
restart.hide();
|
||||||
playing = false;
|
GameState.set(State.menu);
|
||||||
GameState.reset();
|
control.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
weapontable = fill();
|
weapontable = fill();
|
||||||
@@ -209,7 +210,7 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
image.clicked(()->{
|
image.clicked(()->{
|
||||||
if(Inventory.hasItems(r.requirements))
|
if(Inventory.hasItems(r.requirements))
|
||||||
recipe = r;
|
player.recipe = r;
|
||||||
});
|
});
|
||||||
|
|
||||||
table.add(image).size(size+8).pad(4).units(Unit.dp);
|
table.add(image).size(size+8).pad(4).units(Unit.dp);
|
||||||
@@ -219,7 +220,7 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
boolean has = Inventory.hasItems(r.requirements);
|
boolean has = Inventory.hasItems(r.requirements);
|
||||||
image.setDisabled(!has);
|
image.setDisabled(!has);
|
||||||
image.setChecked(recipe == r && has);
|
image.setChecked(player.recipe == r && has);
|
||||||
//image.setTouchable(has ? Touchable.enabled : Touchable.disabled);
|
//image.setTouchable(has ? Touchable.enabled : Touchable.disabled);
|
||||||
image.getImage().setColor(has ? Color.WHITE : Color.GRAY);
|
image.getImage().setColor(has ? Color.WHITE : Color.GRAY);
|
||||||
});
|
});
|
||||||
@@ -242,7 +243,7 @@ public class UI extends SceneModule{
|
|||||||
ItemStack[] req = r.requirements;
|
ItemStack[] req = r.requirements;
|
||||||
for(ItemStack s : req){
|
for(ItemStack s : req){
|
||||||
tiptable.row();
|
tiptable.row();
|
||||||
int amount = Math.min(items.get(s.item, 0), s.amount);
|
int amount = Math.min(Inventory.getAmount(s.item), s.amount);
|
||||||
tiptable.add(
|
tiptable.add(
|
||||||
(amount >= s.amount ? "[YELLOW]" : "[RED]")
|
(amount >= s.amount ? "[YELLOW]" : "[RED]")
|
||||||
+s.item + ": " + amount + " / " +s.amount, fontscale).left();
|
+s.item + ": " + amount + " / " +s.amount, fontscale).left();
|
||||||
@@ -345,12 +346,12 @@ public class UI extends SceneModule{
|
|||||||
new table(){{
|
new table(){{
|
||||||
get().background("button");
|
get().background("button");
|
||||||
|
|
||||||
new label(()->"[YELLOW]Wave " + wave).scale(fontscale*2f).left();
|
new label(()->"[YELLOW]Wave " + control.getWave()).scale(fontscale*2f).left();
|
||||||
|
|
||||||
row();
|
row();
|
||||||
|
|
||||||
new label(()->enemies > 0 ?
|
new label(()-> control.getEnemiesRemaining() > 0 ?
|
||||||
enemies + " Enemies remaining" : "New wave in " + (int) (wavetime / 60f))
|
control.getEnemiesRemaining() + " Enemies remaining" : "New wave in " + (int) (control.getWaveCountdown() / 60f))
|
||||||
.minWidth(150);
|
.minWidth(150);
|
||||||
|
|
||||||
get().pad(Unit.dp.inPixels(12));
|
get().pad(Unit.dp.inPixels(12));
|
||||||
@@ -440,26 +441,26 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
new label("Respawning in"){{
|
new label("Respawning in"){{
|
||||||
get().update(()->{
|
get().update(()->{
|
||||||
get().setText("[yellow]Respawning in " + (int)(respawntime/60));
|
get().setText("[yellow]Respawning in " + (int)(control.getRespawnTime()/60));
|
||||||
});
|
});
|
||||||
|
|
||||||
get().setFontScale(0.75f);
|
get().setFontScale(0.75f);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
visible(()->{
|
visible(()->{
|
||||||
return respawntime > 0 && playing;
|
return control.getRespawnTime() > 0 && !GameState.is(State.menu);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
tools = new Table();
|
tools = new Table();
|
||||||
tools.addIButton("icon-cancel", Unit.dp.inPixels(42), ()->{
|
tools.addIButton("icon-cancel", Unit.dp.inPixels(42), ()->{
|
||||||
recipe = null;
|
player.recipe = null;
|
||||||
});
|
});
|
||||||
tools.addIButton("icon-rotate", Unit.dp.inPixels(42), ()->{
|
tools.addIButton("icon-rotate", Unit.dp.inPixels(42), ()->{
|
||||||
rotation++;
|
player.rotation++;
|
||||||
|
|
||||||
rotation %= 4;
|
player.rotation %= 4;
|
||||||
});
|
});
|
||||||
tools.addIButton("icon-check", Unit.dp.inPixels(42), ()->{
|
tools.addIButton("icon-check", Unit.dp.inPixels(42), ()->{
|
||||||
AndroidInput.place();
|
AndroidInput.place();
|
||||||
@@ -469,7 +470,7 @@ public class UI extends SceneModule{
|
|||||||
scene.add(tools);
|
scene.add(tools);
|
||||||
|
|
||||||
tools.setVisible(()->{
|
tools.setVisible(()->{
|
||||||
return playing && android && recipe != null;
|
return !GameState.is(State.menu) && android && player.recipe != null;
|
||||||
});
|
});
|
||||||
|
|
||||||
tools.update(()->{
|
tools.update(()->{
|
||||||
@@ -484,32 +485,33 @@ public class UI extends SceneModule{
|
|||||||
public void updateWeapons(){
|
public void updateWeapons(){
|
||||||
weapontable.clearChildren();
|
weapontable.clearChildren();
|
||||||
|
|
||||||
for(Weapon weapon : Weapon.values()){
|
for(Weapon weapon : control.getWeapons()){
|
||||||
if(weapons.get(weapon) == Boolean.TRUE){
|
ImageButton button = new ImageButton(Draw.region("weapon-"+weapon.name()), "static");
|
||||||
ImageButton button = new ImageButton(Draw.region("weapon-"+weapon.name()), "static");
|
button.getImageCell().size(40);
|
||||||
button.getImageCell().size(40);
|
button.setDisabled(true);
|
||||||
button.setDisabled(true);
|
|
||||||
if(weapon != currentWeapon)
|
|
||||||
button.setColor(Color.GRAY);
|
|
||||||
weapontable.add(button).size(48, 52);
|
|
||||||
|
|
||||||
Table tiptable = new Table();
|
if(weapon != player.weapon)
|
||||||
String description = weapon.description;
|
button.setColor(Color.GRAY);
|
||||||
|
|
||||||
tiptable.background("button");
|
weapontable.add(button).size(48, 52);
|
||||||
tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f);
|
|
||||||
|
|
||||||
tiptable.row();
|
Table tiptable = new Table();
|
||||||
tiptable.row();
|
String description = weapon.description;
|
||||||
tiptable.add("[ORANGE]" + description).left();
|
|
||||||
tiptable.pad(10f);
|
|
||||||
|
|
||||||
Tooltip tip = new Tooltip(tiptable);
|
tiptable.background("button");
|
||||||
|
tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f);
|
||||||
|
|
||||||
tip.setInstant(true);
|
tiptable.row();
|
||||||
|
tiptable.row();
|
||||||
|
tiptable.add("[ORANGE]" + description).left();
|
||||||
|
tiptable.pad(10f);
|
||||||
|
|
||||||
|
Tooltip tip = new Tooltip(tiptable);
|
||||||
|
|
||||||
|
tip.setInstant(true);
|
||||||
|
|
||||||
|
button.addListener(tip);
|
||||||
|
|
||||||
button.addListener(tip);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,9 +547,9 @@ public class UI extends SceneModule{
|
|||||||
public void updateItems(){
|
public void updateItems(){
|
||||||
itemtable.clear();
|
itemtable.clear();
|
||||||
|
|
||||||
for(Item stack : items.keys()){
|
for(Item stack : Inventory.getItemTypes()){
|
||||||
Image image = new Image(Draw.region("icon-" + stack.name()));
|
Image image = new Image(Draw.region("icon-" + stack.name()));
|
||||||
Label label = new Label("" + items.get(stack));
|
Label label = new Label("" + Inventory.getAmount(stack));
|
||||||
label.setFontScale(fontscale*2f);
|
label.setFontScale(fontscale*2f);
|
||||||
itemtable.add(image).size(32).units(Unit.dp);
|
itemtable.add(image).size(32).units(Unit.dp);
|
||||||
itemtable.add(label);
|
itemtable.add(label);
|
||||||
|
|||||||
@@ -2,17 +2,8 @@ package io.anuke.mindustry;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Application.ApplicationType;
|
import com.badlogic.gdx.Application.ApplicationType;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.Weapon;
|
|
||||||
import io.anuke.mindustry.resource.Item;
|
|
||||||
import io.anuke.mindustry.resource.Recipe;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
|
|
||||||
/**ick, global state*/
|
/**ick, global state*/
|
||||||
@@ -23,52 +14,23 @@ public class Vars{
|
|||||||
public static final float respawnduration = 60*4;
|
public static final float respawnduration = 60*4;
|
||||||
public static final float wavespace = 20*60*(android ? 2 : 1);
|
public static final float wavespace = 20*60*(android ? 2 : 1);
|
||||||
public static final float enemyspawnspace = 65;
|
public static final float enemyspawnspace = 65;
|
||||||
public static boolean debug = false;
|
public static final float fontscale = Unit.dp.inPixels(1f)/2f;
|
||||||
public static float fontscale = Unit.dp.inPixels(1f)/2f;
|
|
||||||
public static final int baseCameraScale = Math.round(Unit.dp.inPixels(4));
|
public static final int baseCameraScale = Math.round(Unit.dp.inPixels(4));
|
||||||
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
|
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
|
||||||
|
|
||||||
public static int multiplier = android ? 2 : 1;
|
//not marked as final, because of warnings
|
||||||
public static final Vector2 vector = new Vector2();
|
public static boolean debug = false;
|
||||||
|
|
||||||
|
public static final int multiplier = android ? 2 : 1;
|
||||||
|
|
||||||
public static final int tilesize = 8;
|
public static final int tilesize = 8;
|
||||||
|
|
||||||
public static Control control;
|
public static Control control;
|
||||||
public static UI ui;
|
public static UI ui;
|
||||||
|
|
||||||
public static final ObjectMap<Item, Integer> items = new ObjectMap<>();
|
|
||||||
public static final ObjectMap<Weapon, Boolean> weapons = new ObjectMap<Weapon, Boolean>();
|
|
||||||
public static Weapon currentWeapon;
|
|
||||||
|
|
||||||
public static Player player;
|
public static Player player;
|
||||||
|
|
||||||
public static float breaktime = 0;
|
|
||||||
|
|
||||||
public static final String[] maps = {"delta", "canyon", "pit", "maze"};
|
public static final String[] maps = {"delta", "canyon", "pit", "maze"};
|
||||||
public static Pixmap[] mapPixmaps;
|
|
||||||
public static Texture[] mapTextures;
|
|
||||||
public static int currentMap;
|
|
||||||
public static int worldsize = 128;
|
|
||||||
public static int pixsize = worldsize*tilesize;
|
|
||||||
public static Tile[][] tiles = new Tile[worldsize][worldsize];
|
|
||||||
|
|
||||||
public static boolean hiscore = false;
|
|
||||||
|
|
||||||
public static Recipe recipe;
|
|
||||||
public static int rotation;
|
|
||||||
|
|
||||||
public static int wave = 1;
|
|
||||||
public static float wavetime;
|
|
||||||
public static int enemies = 0;
|
|
||||||
|
|
||||||
public static float respawntime;
|
|
||||||
|
|
||||||
public static Tile core;
|
|
||||||
public static Array<Tile> spawnpoints = new Array<Tile>();
|
|
||||||
|
|
||||||
public static boolean playing = false;
|
|
||||||
public static boolean paused = false;
|
|
||||||
public static boolean showedTutorial = false;
|
|
||||||
|
|
||||||
public static String[] aboutText = {
|
public static String[] aboutText = {
|
||||||
"Made by [ROYAL]Anuken[] for the" + "\nGDL Metal Monstrosity jam.",
|
"Made by [ROYAL]Anuken[] for the" + "\nGDL Metal Monstrosity jam.",
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ package io.anuke.mindustry;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import io.anuke.mindustry.ai.Pathfind;
|
import io.anuke.mindustry.ai.Pathfind;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
@@ -20,20 +24,34 @@ import io.anuke.ucore.entities.SolidEntity;
|
|||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
public class World{
|
public class World{
|
||||||
|
public static int worldsize = 128;
|
||||||
|
public static int pixsize = worldsize*tilesize;
|
||||||
|
|
||||||
|
private static Pixmap[] mapPixmaps;
|
||||||
|
private static Texture[] mapTextures;
|
||||||
|
private static int currentMap;
|
||||||
|
private static Tile[][] tiles = new Tile[worldsize][worldsize];
|
||||||
private static Tile[] temptiles = new Tile[4];
|
private static Tile[] temptiles = new Tile[4];
|
||||||
|
|
||||||
|
public static Tile core;
|
||||||
|
public static Array<Tile> spawnpoints = new Array<Tile>();
|
||||||
|
|
||||||
public static boolean solid(int x, int y){
|
public static boolean solid(int x, int y){
|
||||||
Tile tile = tile(x, y);
|
Tile tile = tile(x, y);
|
||||||
|
|
||||||
return tile == null || tile.block().solid || (tile.floor().solid && (tile.block() == Blocks.air));
|
return tile == null || tile.block().solid || (tile.floor().solid && (tile.block() == Blocks.air));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getMap(){
|
||||||
|
return currentMap;
|
||||||
|
}
|
||||||
|
|
||||||
public static int width(){
|
public static int width(){
|
||||||
return Vars.mapPixmaps[Vars.currentMap].getWidth();
|
return mapPixmaps[currentMap].getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int height(){
|
public static int height(){
|
||||||
return Vars.mapPixmaps[Vars.currentMap].getHeight();
|
return mapPixmaps[currentMap].getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tile tile(int x, int y){
|
public static Tile tile(int x, int y){
|
||||||
@@ -53,6 +71,21 @@ public class World{
|
|||||||
return temptiles;
|
return temptiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Texture getTexture(int map){
|
||||||
|
return mapTextures[map];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadMaps(){
|
||||||
|
mapPixmaps = new Pixmap[maps.length];
|
||||||
|
mapTextures = new Texture[maps.length];
|
||||||
|
|
||||||
|
for(int i = 0; i < maps.length; i ++){
|
||||||
|
Pixmap pix = new Pixmap(Gdx.files.internal("maps/"+maps[i]+".png"));
|
||||||
|
mapPixmaps[i] = pix;
|
||||||
|
mapTextures[i] = new Texture(pix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadMap(int id){
|
public static void loadMap(int id){
|
||||||
spawnpoints.clear();
|
spawnpoints.clear();
|
||||||
|
|
||||||
@@ -70,7 +103,7 @@ public class World{
|
|||||||
|
|
||||||
Entities.resizeTree(0, 0, pixsize, pixsize);
|
Entities.resizeTree(0, 0, pixsize, pixsize);
|
||||||
|
|
||||||
Generator.generate(id);
|
Generator.generate(mapPixmaps[id]);
|
||||||
|
|
||||||
Pathfind.reset();
|
Pathfind.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package io.anuke.mindustry.ai;
|
package io.anuke.mindustry.ai;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.worldsize;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.ai.pfa.Connection;
|
import com.badlogic.gdx.ai.pfa.Connection;
|
||||||
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
|
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.World;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
/**Tilegraph that ignores player-made tiles.*/
|
/**Tilegraph that ignores player-made tiles.*/
|
||||||
public class PassTileGraph implements IndexedGraph<Tile>{
|
public class PassTileGraph implements IndexedGraph<Tile>{
|
||||||
@@ -28,11 +27,11 @@ public class PassTileGraph implements IndexedGraph<Tile>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIndex(Tile node){
|
public int getIndex(Tile node){
|
||||||
return node.x+node.y*worldsize;
|
return node.x+node.y*World.worldsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNodeCount(){
|
public int getNodeCount(){
|
||||||
return worldsize*worldsize;
|
return World.worldsize*World.worldsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package io.anuke.mindustry.ai;
|
package io.anuke.mindustry.ai;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
|
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
|
||||||
import com.badlogic.gdx.ai.pfa.PathFinder;
|
import com.badlogic.gdx.ai.pfa.PathFinder;
|
||||||
import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder;
|
import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder;
|
||||||
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 io.anuke.mindustry.World;
|
||||||
import io.anuke.mindustry.entities.Enemy;
|
import io.anuke.mindustry.entities.Enemy;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
public class Pathfind{
|
public class Pathfind{
|
||||||
@@ -52,8 +51,8 @@ public class Pathfind{
|
|||||||
|
|
||||||
static public void updatePath(){
|
static public void updatePath(){
|
||||||
if(paths.size == 0){
|
if(paths.size == 0){
|
||||||
pathSequences = new Tile[spawnpoints.size][0];
|
pathSequences = new Tile[World.spawnpoints.size][0];
|
||||||
for(int i = 0; i < spawnpoints.size; i ++){
|
for(int i = 0; i < World.spawnpoints.size; i ++){
|
||||||
DefaultGraphPath<Tile> path = new DefaultGraphPath<>();
|
DefaultGraphPath<Tile> path = new DefaultGraphPath<>();
|
||||||
paths.add(path);
|
paths.add(path);
|
||||||
}
|
}
|
||||||
@@ -64,8 +63,8 @@ public class Pathfind{
|
|||||||
|
|
||||||
path.clear();
|
path.clear();
|
||||||
passpathfinder.searchNodePath(
|
passpathfinder.searchNodePath(
|
||||||
spawnpoints.get(i),
|
World.spawnpoints.get(i),
|
||||||
core, heuristic, path);
|
World.core, heuristic, path);
|
||||||
|
|
||||||
pathSequences[i] = new Tile[path.getCount()];
|
pathSequences[i] = new Tile[path.getCount()];
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class Enemy extends DestructibleEntity{
|
|||||||
@Override
|
@Override
|
||||||
public void removed(){
|
public void removed(){
|
||||||
if(!dead)
|
if(!dead)
|
||||||
Vars.enemies --;
|
Vars.control.enemyDeath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,16 +7,21 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.resource.Recipe;
|
||||||
import io.anuke.ucore.core.*;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.entities.DestructibleEntity;
|
import io.anuke.ucore.entities.DestructibleEntity;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
import io.anuke.ucore.util.Timers;
|
import io.anuke.ucore.util.Timers;
|
||||||
|
|
||||||
public class Player extends DestructibleEntity{
|
public class Player extends DestructibleEntity{
|
||||||
Vector2 direction = new Vector2();
|
public Weapon weapon;
|
||||||
float speed = 1f;
|
public float breaktime = 0;
|
||||||
float rotation;
|
|
||||||
float reload;
|
public Recipe recipe;
|
||||||
|
public int rotation;
|
||||||
|
|
||||||
|
private Vector2 direction = new Vector2();
|
||||||
|
private float speed = 1f;
|
||||||
|
|
||||||
public Player(){
|
public Player(){
|
||||||
hitsize = 5;
|
hitsize = 5;
|
||||||
@@ -32,7 +37,7 @@ public class Player extends DestructibleEntity{
|
|||||||
Effects.shake(4f, 5f);
|
Effects.shake(4f, 5f);
|
||||||
Effects.sound("die", this);
|
Effects.sound("die", this);
|
||||||
|
|
||||||
respawntime = respawnduration;
|
Vars.control.setRespawnTime(respawnduration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,14 +67,11 @@ public class Player extends DestructibleEntity{
|
|||||||
if(Inputs.keyDown("right"))
|
if(Inputs.keyDown("right"))
|
||||||
vector.x += speed;
|
vector.x += speed;
|
||||||
|
|
||||||
reload -= delta;
|
|
||||||
|
|
||||||
boolean shooting = Inputs.buttonDown(Buttons.LEFT) && recipe == null && !ui.hasMouse();
|
boolean shooting = Inputs.buttonDown(Buttons.LEFT) && recipe == null && !ui.hasMouse();
|
||||||
|
|
||||||
if(shooting && reload <= 0){
|
if(shooting && Timers.get(this, "reload", weapon.reload)){
|
||||||
currentWeapon.shoot(this);
|
weapon.shoot(this);
|
||||||
Sounds.play(currentWeapon.shootsound);
|
Sounds.play(weapon.shootsound);
|
||||||
reload = currentWeapon.reload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vector.limit(speed);
|
vector.limit(speed);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.entities;
|
|||||||
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
|
||||||
import io.anuke.mindustry.GameState;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.Blocks;
|
import io.anuke.mindustry.world.blocks.Blocks;
|
||||||
@@ -33,7 +33,7 @@ public class TileEntity extends Entity{
|
|||||||
dead = true;
|
dead = true;
|
||||||
|
|
||||||
if(tile.block() == ProductionBlocks.core){
|
if(tile.block() == ProductionBlocks.core){
|
||||||
GameState.coreDestroyed();
|
Vars.control.coreDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
tile.setBlock(Blocks.air);
|
tile.setBlock(Blocks.air);
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ public class AndroidInput extends InputAdapter{
|
|||||||
|
|
||||||
public static void breakBlock(){
|
public static void breakBlock(){
|
||||||
Tile tile = selected();
|
Tile tile = selected();
|
||||||
breaktime += Mathf.delta();
|
player.breaktime += Mathf.delta();
|
||||||
if(breaktime >= tile.block().breaktime){
|
if(player.breaktime >= tile.block().breaktime){
|
||||||
Effects.effect("break", tile.worldx(), tile.worldy());
|
Effects.effect("break", tile.worldx(), tile.worldy());
|
||||||
Effects.shake(3f, 1f);
|
Effects.shake(3f, 1f);
|
||||||
tile.setBlock(Blocks.air);
|
tile.setBlock(Blocks.air);
|
||||||
breaktime = 0f;
|
player.breaktime = 0f;
|
||||||
Sounds.play("break");
|
Sounds.play("break");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,27 +67,27 @@ public class AndroidInput extends InputAdapter{
|
|||||||
int tilex = Mathf.scl2(vec.x, tilesize);
|
int tilex = Mathf.scl2(vec.x, tilesize);
|
||||||
int tiley = Mathf.scl2(vec.y, tilesize);
|
int tiley = Mathf.scl2(vec.y, tilesize);
|
||||||
|
|
||||||
if(recipe != null &&
|
if(player.recipe != null &&
|
||||||
World.validPlace(tilex, tiley, recipe.result)){
|
World.validPlace(tilex, tiley, player.recipe.result)){
|
||||||
|
|
||||||
Tile tile = World.tile(tilex, tiley);
|
Tile tile = World.tile(tilex, tiley);
|
||||||
|
|
||||||
if(tile == null)
|
if(tile == null)
|
||||||
return; //just in case
|
return; //just in case
|
||||||
|
|
||||||
tile.setBlock(recipe.result);
|
tile.setBlock(player.recipe.result);
|
||||||
tile.rotation = rotation;
|
tile.rotation = player.rotation;
|
||||||
|
|
||||||
Effects.effect("place", tilex*tilesize, tiley*tilesize);
|
Effects.effect("place", tilex*tilesize, tiley*tilesize);
|
||||||
Effects.shake(2f, 2f);
|
Effects.shake(2f, 2f);
|
||||||
Sounds.play("place");
|
Sounds.play("place");
|
||||||
|
|
||||||
for(ItemStack stack : recipe.requirements){
|
for(ItemStack stack : player.recipe.requirements){
|
||||||
Inventory.removeItem(stack);
|
Inventory.removeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Inventory.hasItems(recipe.requirements)){
|
if(!Inventory.hasItems(player.recipe.requirements)){
|
||||||
recipe = null;
|
player.recipe = null;
|
||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ public class AndroidInput extends InputAdapter{
|
|||||||
public static void doInput(){
|
public static void doInput(){
|
||||||
if(Gdx.input.isTouched(0)
|
if(Gdx.input.isTouched(0)
|
||||||
&& Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), 50)
|
&& Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), 50)
|
||||||
&& !ui.hasMouse() && recipe == null){
|
&& !ui.hasMouse() && player.recipe == null){
|
||||||
warmup += Mathf.delta();
|
warmup += Mathf.delta();
|
||||||
|
|
||||||
mousex = Gdx.input.getX(0);
|
mousex = Gdx.input.getX(0);
|
||||||
@@ -107,18 +107,18 @@ public class AndroidInput extends InputAdapter{
|
|||||||
if(sel == null) return;
|
if(sel == null) return;
|
||||||
|
|
||||||
if(warmup > warmupDelay && sel.block() != ProductionBlocks.core && sel.breakable()){
|
if(warmup > warmupDelay && sel.block() != ProductionBlocks.core && sel.breakable()){
|
||||||
breaktime += Mathf.delta();
|
player.breaktime += Mathf.delta();
|
||||||
|
|
||||||
if(breaktime > selected().block().breaktime){
|
if(player.breaktime > selected().block().breaktime){
|
||||||
breakBlock();
|
breakBlock();
|
||||||
breaktime = 0;
|
player.breaktime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
warmup = 0;
|
warmup = 0;
|
||||||
lmousex = Gdx.input.getX(0);
|
lmousex = Gdx.input.getX(0);
|
||||||
lmousey = Gdx.input.getY(0);
|
lmousey = Gdx.input.getY(0);
|
||||||
breaktime = 0;
|
player.breaktime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
@Override
|
@Override
|
||||||
public boolean longPress(float x, float y){
|
public boolean longPress(float x, float y){
|
||||||
Tile tile = World.cursorTile();
|
Tile tile = World.cursorTile();
|
||||||
breaktime += Mathf.delta();
|
player.breaktime += Mathf.delta();
|
||||||
if(breaktime >= tile.block().breaktime){
|
if(player.breaktime >= tile.block().breaktime){
|
||||||
Effects.effect("break", tile.worldx(), tile.worldy());
|
Effects.effect("break", tile.worldx(), tile.worldy());
|
||||||
Effects.shake(3f, 1f);
|
Effects.shake(3f, 1f);
|
||||||
tile.setBlock(Blocks.air);
|
tile.setBlock(Blocks.air);
|
||||||
breaktime = 0f;
|
player.breaktime = 0f;
|
||||||
Sounds.play("break");
|
Sounds.play("break");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -34,7 +34,7 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||||
if(recipe == null){
|
if(player.recipe == null){
|
||||||
player.x -= deltaX*control.camera.zoom/control.cameraScale;
|
player.x -= deltaX*control.camera.zoom/control.cameraScale;
|
||||||
player.y += deltaY*control.camera.zoom/control.cameraScale;
|
player.y += deltaY*control.camera.zoom/control.cameraScale;
|
||||||
}else{
|
}else{
|
||||||
@@ -47,7 +47,7 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||||
if(recipe == null)
|
if(player.recipe == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(pinch1.x < 0){
|
if(pinch1.x < 0){
|
||||||
|
|||||||
@@ -25,71 +25,56 @@ public class Input{
|
|||||||
if(player.health <= 0) return;
|
if(player.health <= 0) return;
|
||||||
|
|
||||||
if(Inputs.scrolled()){
|
if(Inputs.scrolled()){
|
||||||
Weapon[] val = Weapon.values();
|
int index = currentWeapon();
|
||||||
int index = 0;
|
|
||||||
for(int i = 0; i < val.length; i ++)
|
|
||||||
if(val[i] == currentWeapon){
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < val.length; i ++){
|
index -= Inputs.scroll();
|
||||||
index += Inputs.scroll();
|
player.weapon = control.getWeapons().get(Mathf.clamp(index, 0, control.getWeapons().size-1));
|
||||||
if(index >= 0 && index < val.length){
|
|
||||||
if(weapons.get(val[index])){
|
|
||||||
currentWeapon = (val[index]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.updateWeapons();
|
ui.updateWeapons();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyUp("rotate"))
|
if(Inputs.keyUp("rotate"))
|
||||||
rotation++;
|
player.rotation++;
|
||||||
|
|
||||||
rotation %= 4;
|
player.rotation %= 4;
|
||||||
|
|
||||||
if(recipe != null && !Inventory.hasItems(recipe.requirements)){
|
if(player.recipe != null && !Inventory.hasItems(player.recipe.requirements)){
|
||||||
recipe = null;
|
player.recipe = null;
|
||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 9; i ++)
|
for(int i = 0; i < 9; i ++)
|
||||||
if(Inputs.keyUp(Keys.valueOf(""+(i+1))) && getWeapon(i) != null){
|
if(Inputs.keyUp(Keys.valueOf(""+(i+1))) && i < control.getWeapons().size){
|
||||||
currentWeapon = getWeapon(i);
|
player.weapon = control.getWeapons().get(i);
|
||||||
ui.updateWeapons();
|
ui.updateWeapons();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.buttonUp(Buttons.LEFT) && recipe != null &&
|
if(Inputs.buttonUp(Buttons.LEFT) && player.recipe != null &&
|
||||||
World.validPlace(World.tilex(), World.tiley(), recipe.result) && !ui.hasMouse()){
|
World.validPlace(World.tilex(), World.tiley(), player.recipe.result) && !ui.hasMouse()){
|
||||||
Tile tile = World.tile(World.tilex(), World.tiley());
|
Tile tile = World.tile(World.tilex(), World.tiley());
|
||||||
|
|
||||||
if(tile == null)
|
if(tile == null)
|
||||||
return; //just in case
|
return; //just in case
|
||||||
|
|
||||||
tile.setBlock(recipe.result);
|
tile.setBlock(player.recipe.result);
|
||||||
tile.rotation = rotation;
|
tile.rotation = player.rotation;
|
||||||
|
|
||||||
Effects.effect("place", World.roundx(), World.roundy());
|
Effects.effect("place", World.roundx(), World.roundy());
|
||||||
Effects.shake(2f, 2f);
|
Effects.shake(2f, 2f);
|
||||||
Sounds.play("place");
|
Sounds.play("place");
|
||||||
|
|
||||||
for(ItemStack stack : recipe.requirements){
|
for(ItemStack stack : player.recipe.requirements){
|
||||||
Inventory.removeItem(stack);
|
Inventory.removeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Inventory.hasItems(recipe.requirements)){
|
if(!Inventory.hasItems(player.recipe.requirements)){
|
||||||
recipe = null;
|
player.recipe = null;
|
||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
|
if(player.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
|
||||||
recipe = null;
|
player.recipe = null;
|
||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,38 +84,27 @@ public class Input{
|
|||||||
if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear() && cursor.breakable()
|
if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear() && cursor.breakable()
|
||||||
&& cursor.block() != ProductionBlocks.core){
|
&& cursor.block() != ProductionBlocks.core){
|
||||||
Tile tile = cursor;
|
Tile tile = cursor;
|
||||||
breaktime += Mathf.delta();
|
player.breaktime += Mathf.delta();
|
||||||
if(breaktime >= tile.block().breaktime){
|
if(player.breaktime >= tile.block().breaktime){
|
||||||
Effects.effect("break", tile.worldx(), tile.worldy());
|
Effects.effect("break", tile.worldx(), tile.worldy());
|
||||||
Effects.shake(3f, 1f);
|
Effects.shake(3f, 1f);
|
||||||
tile.setBlock(Blocks.air);
|
tile.setBlock(Blocks.air);
|
||||||
breaktime = 0f;
|
player.breaktime = 0f;
|
||||||
Sounds.play("break");
|
Sounds.play("break");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
breaktime = 0f;
|
player.breaktime = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int currentWeapons(){
|
public static int currentWeapon(){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
for(Weapon weapon : control.getWeapons()){
|
||||||
for(Weapon w : Weapon.values())
|
if(player.weapon == weapon)
|
||||||
if(weapons.get(w))
|
return i;
|
||||||
i ++;
|
i ++;
|
||||||
|
}
|
||||||
return i;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
public static Weapon getWeapon(int id){
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for(Weapon w : Weapon.values())
|
|
||||||
if(weapons.get(w))
|
|
||||||
if(i ++ == id)
|
|
||||||
return w;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.io;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
|
public class SaveState{
|
||||||
|
public Tile[][] tiles;
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package io.anuke.mindustry.ui;
|
package io.anuke.mindustry.ui;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.maps;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
import io.anuke.mindustry.GameState;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.World;
|
import io.anuke.mindustry.World;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.scene.ui.*;
|
import io.anuke.ucore.scene.ui.*;
|
||||||
@@ -29,7 +29,7 @@ public class LevelDialog extends Dialog{
|
|||||||
getButtonTable().addButton("Play", ()->{
|
getButtonTable().addButton("Play", ()->{
|
||||||
hide();
|
hide();
|
||||||
World.loadMap(selectedMap);
|
World.loadMap(selectedMap);
|
||||||
GameState.play();
|
Vars.control.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonGroup<ImageButton> mapgroup = new ButtonGroup<>();
|
ButtonGroup<ImageButton> mapgroup = new ButtonGroup<>();
|
||||||
@@ -42,7 +42,7 @@ public class LevelDialog extends Dialog{
|
|||||||
|
|
||||||
for(int i = 0; i < maps.length; i ++){
|
for(int i = 0; i < maps.length; i ++){
|
||||||
int index = i;
|
int index = i;
|
||||||
ImageButton image = new ImageButton(new TextureRegion(mapTextures[i]), "togglemap");
|
ImageButton image = new ImageButton(new TextureRegion(World.getTexture(i)), "togglemap");
|
||||||
mapgroup.add(image);
|
mapgroup.add(image);
|
||||||
image.clicked(()->{
|
image.clicked(()->{
|
||||||
selectedMap = index;
|
selectedMap = index;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package io.anuke.mindustry.ui;
|
package io.anuke.mindustry.ui;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.ui;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.GameState;
|
||||||
|
import io.anuke.mindustry.GameState.State;
|
||||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||||
import io.anuke.ucore.scene.ui.Dialog;
|
import io.anuke.ucore.scene.ui.Dialog;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
@@ -16,7 +18,7 @@ public class MenuDialog extends Dialog{
|
|||||||
void setup(){
|
void setup(){
|
||||||
content().addButton("Back", ()->{
|
content().addButton("Back", ()->{
|
||||||
hide();
|
hide();
|
||||||
paused = false;
|
GameState.set(State.playing);
|
||||||
}).width(200).units(Unit.dp);
|
}).width(200).units(Unit.dp);
|
||||||
|
|
||||||
content().row();
|
content().row();
|
||||||
@@ -33,8 +35,7 @@ public class MenuDialog extends Dialog{
|
|||||||
content().addButton("Back to menu", ()->{
|
content().addButton("Back to menu", ()->{
|
||||||
new ConfirmDialog("Confirm", "Are you sure you want to quit?", ()->{
|
new ConfirmDialog("Confirm", "Are you sure you want to quit?", ()->{
|
||||||
hide();
|
hide();
|
||||||
paused = false;
|
GameState.set(State.menu);
|
||||||
playing = false;
|
|
||||||
}).show();
|
}).show();
|
||||||
}).width(200).units(Unit.dp);
|
}).width(200).units(Unit.dp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package io.anuke.mindustry.ui;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.GameState;
|
||||||
|
import io.anuke.mindustry.GameState.State;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.scene.ui.TextDialog;
|
import io.anuke.ucore.scene.ui.TextDialog;
|
||||||
|
|
||||||
@@ -16,8 +18,7 @@ public class TutorialDialog extends TextDialog{
|
|||||||
setDialog();
|
setDialog();
|
||||||
|
|
||||||
hidden(()->{
|
hidden(()->{
|
||||||
playing = true;
|
GameState.set(State.playing);
|
||||||
paused = false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
getButtonTable().addButton("OK", ()->{
|
getButtonTable().addButton("OK", ()->{
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.GameState;
|
||||||
|
import io.anuke.mindustry.GameState.State;
|
||||||
import io.anuke.mindustry.Inventory;
|
import io.anuke.mindustry.Inventory;
|
||||||
import io.anuke.mindustry.entities.Weapon;
|
import io.anuke.mindustry.entities.Weapon;
|
||||||
import io.anuke.mindustry.resource.ItemStack;
|
import io.anuke.mindustry.resource.ItemStack;
|
||||||
@@ -25,10 +27,10 @@ public class UpgradeDialog extends Dialog{
|
|||||||
addCloseButton();
|
addCloseButton();
|
||||||
|
|
||||||
hidden(()->{
|
hidden(()->{
|
||||||
paused = false;
|
GameState.set(State.playing);
|
||||||
});
|
});
|
||||||
shown(()->{
|
shown(()->{
|
||||||
paused = true;
|
GameState.set(State.paused);
|
||||||
});
|
});
|
||||||
|
|
||||||
getButtonTable().addButton("Ok", ()->{
|
getButtonTable().addButton("Ok", ()->{
|
||||||
@@ -51,7 +53,7 @@ public class UpgradeDialog extends Dialog{
|
|||||||
|
|
||||||
button.update(()->{
|
button.update(()->{
|
||||||
|
|
||||||
if(weapons.get(weapon) == Boolean.TRUE){
|
if(control.hasWeapon(weapon)){
|
||||||
button.setDisabled(true);
|
button.setDisabled(true);
|
||||||
button.setColor(Color.GRAY);
|
button.setColor(Color.GRAY);
|
||||||
button.setTouchable(Touchable.disabled);
|
button.setTouchable(Touchable.disabled);
|
||||||
@@ -80,11 +82,11 @@ public class UpgradeDialog extends Dialog{
|
|||||||
tiptable.background("button");
|
tiptable.background("button");
|
||||||
tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f);
|
tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f);
|
||||||
|
|
||||||
if(weapons.get(weapon) != Boolean.TRUE){
|
if(!control.hasWeapon(weapon)){
|
||||||
ItemStack[] req = weapon.requirements;
|
ItemStack[] req = weapon.requirements;
|
||||||
for(ItemStack s : req){
|
for(ItemStack s : req){
|
||||||
tiptable.row();
|
tiptable.row();
|
||||||
int amount = Math.min(items.get(s.item, 0), s.amount);
|
int amount = Math.min(Inventory.getAmount(s.item), s.amount);
|
||||||
tiptable.add(
|
tiptable.add(
|
||||||
(amount >= s.amount ? "[YELLOW]" : "[RED]")
|
(amount >= s.amount ? "[YELLOW]" : "[RED]")
|
||||||
+s.item + ": " + amount + " / " +s.amount, 0.5f).left();
|
+s.item + ": " + amount + " / " +s.amount, 0.5f).left();
|
||||||
@@ -96,7 +98,7 @@ public class UpgradeDialog extends Dialog{
|
|||||||
tiptable.row();
|
tiptable.row();
|
||||||
tiptable.add("[ORANGE]" + description).left();
|
tiptable.add("[ORANGE]" + description).left();
|
||||||
tiptable.row();
|
tiptable.row();
|
||||||
if(weapons.get(weapon) == Boolean.TRUE)
|
if(control.hasWeapon(weapon))
|
||||||
tiptable.add("[LIME]Purchased!").left();
|
tiptable.add("[LIME]Purchased!").left();
|
||||||
tiptable.pad(10f);
|
tiptable.pad(10f);
|
||||||
};
|
};
|
||||||
@@ -113,7 +115,7 @@ public class UpgradeDialog extends Dialog{
|
|||||||
if(button.isDisabled()) return;
|
if(button.isDisabled()) return;
|
||||||
|
|
||||||
Inventory.removeItems(weapon.requirements);
|
Inventory.removeItems(weapon.requirements);
|
||||||
weapons.put(weapon, true);
|
control.addWeapon(weapon);
|
||||||
ui.updateWeapons();
|
ui.updateWeapons();
|
||||||
run.listen();
|
run.listen();
|
||||||
Effects.sound("purchase");
|
Effects.sound("purchase");
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package io.anuke.mindustry.world;
|
package io.anuke.mindustry.world;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.World;
|
||||||
import io.anuke.mindustry.world.blocks.Blocks;
|
import io.anuke.mindustry.world.blocks.Blocks;
|
||||||
import io.anuke.ucore.graphics.Hue;
|
import io.anuke.ucore.graphics.Hue;
|
||||||
import io.anuke.ucore.noise.Noise;
|
import io.anuke.ucore.noise.Noise;
|
||||||
@@ -29,16 +26,15 @@ public class Generator{
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**Returns world size.*/
|
/**Returns world size.*/
|
||||||
public static void generate(int map){
|
public static void generate(Pixmap pixmap){
|
||||||
Pixmap pix = mapPixmaps[map];
|
|
||||||
|
|
||||||
Noise.setSeed(MathUtils.random(0, 99999));
|
Noise.setSeed(MathUtils.random(0, 99999));
|
||||||
for(int x = 0; x < tiles.length; x ++){
|
for(int x = 0; x < pixmap.getWidth(); x ++){
|
||||||
for(int y = 0; y < tiles.length; y ++){
|
for(int y = 0; y < pixmap.getHeight(); y ++){
|
||||||
Block floor = Blocks.stone;
|
Block floor = Blocks.stone;
|
||||||
Block block = Blocks.air;
|
Block block = Blocks.air;
|
||||||
|
|
||||||
int color = pix.getPixel(x, pix.getHeight()-1-y);
|
int color = pixmap.getPixel(x, pixmap.getHeight()-1-y);
|
||||||
|
|
||||||
if(colors.containsKey(color)){
|
if(colors.containsKey(color)){
|
||||||
//TODO less hacky method
|
//TODO less hacky method
|
||||||
@@ -48,9 +44,9 @@ public class Generator{
|
|||||||
floor = colors.get(color);
|
floor = colors.get(color);
|
||||||
}
|
}
|
||||||
}else if(color == start){
|
}else if(color == start){
|
||||||
core = tiles[x][y];
|
World.core = World.tile(x, y);
|
||||||
}else if(color == spawn){
|
}else if(color == spawn){
|
||||||
spawnpoints.add(tiles[x][y]);
|
World.spawnpoints.add(World.tile(x, y));
|
||||||
floor = Blocks.dirt;
|
floor = Blocks.dirt;
|
||||||
}else{
|
}else{
|
||||||
if(Mathf.chance(0.02)){
|
if(Mathf.chance(0.02)){
|
||||||
@@ -81,23 +77,12 @@ public class Generator{
|
|||||||
block = Blocks.shrub;
|
block = Blocks.shrub;
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles[x][y].setBlock(block);
|
World.tile(x, y).setBlock(block);
|
||||||
tiles[x][y].setFloor(floor);
|
World.tile(x, y).setFloor(floor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadMaps(){
|
|
||||||
mapPixmaps = new Pixmap[maps.length];
|
|
||||||
mapTextures = new Texture[maps.length];
|
|
||||||
|
|
||||||
for(int i = 0; i < maps.length; i ++){
|
|
||||||
Pixmap pix = new Pixmap(Gdx.files.internal("maps/"+maps[i]+".png"));
|
|
||||||
mapPixmaps[i] = pix;
|
|
||||||
mapTextures[i] = new Texture(pix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ObjectMap<Integer, Block> map(Object...objects){
|
private static ObjectMap<Integer, Block> map(Object...objects){
|
||||||
|
|
||||||
ObjectMap<Integer, Block> out = new ObjectMap<>();
|
ObjectMap<Integer, Block> out = new ObjectMap<>();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package io.anuke.mindustry.world;
|
package io.anuke.mindustry.world;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
import io.anuke.mindustry.World;
|
import io.anuke.mindustry.World;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
@@ -36,7 +36,7 @@ public class Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int id(){
|
public int id(){
|
||||||
return x + y * worldsize;
|
return x + y * World.worldsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float worldx(){
|
public float worldx(){
|
||||||
|
|||||||
Reference in New Issue
Block a user