diff --git a/core/src/io/anuke/moment/Control.java b/core/src/io/anuke/moment/Control.java index e42d02d6af..9048f3ed0b 100644 --- a/core/src/io/anuke/moment/Control.java +++ b/core/src/io/anuke/moment/Control.java @@ -13,7 +13,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import io.anuke.moment.ai.Pathfind; -import io.anuke.moment.entities.FlameEnemy; +import io.anuke.moment.entities.BossEnemy; import io.anuke.moment.entities.TileEntity; import io.anuke.moment.resource.ItemStack; import io.anuke.moment.world.Tile; @@ -169,8 +169,10 @@ public class Control extends RendererModule{ } //TODO - if(UInput.keyUp(Keys.G)) - new FlameEnemy(0).set(main.player.x, main.player.y).add(); + if(UInput.keyUp(Keys.G)){ + new BossEnemy(0).set(main.player.x, main.player.y).add(); + } + //new FlameEnemy(0).set(main.player.x, main.player.y).add(); if(UInput.buttonUp(Buttons.LEFT) && main.recipe != null && validPlace(tilex(), tiley(), main.recipe.result) && !get(UI.class).hasMouse()){ Tile tile = main.tile(tilex(), tiley()); @@ -386,7 +388,7 @@ public class Control extends RendererModule{ Draw.clear(); } if(tile.entity != null) - drawHealth(tile.entity); + drawHealth(tile.entity.x, tile.entity.y, tile.entity.health, tile.entity.maxhealth); } } @@ -394,25 +396,25 @@ public class Control extends RendererModule{ if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){ DestructibleEntity dest = ((DestructibleEntity) entity); - drawHealth(dest); + drawHealth(dest.x, dest.y, dest.health, dest.maxhealth); } } //Draw.text(Gdx.graphics.getFramesPerSecond() + " FPS", main.player.x, main.player.y); } - void drawHealth(DestructibleEntity dest){ + void drawHealth(float x, float y, float health, float maxhealth){ float len = 3; float offset = 7; Draw.thickness(3f); Draw.color(Color.GRAY); - Draw.line(dest.x - len + 1, dest.y - offset, dest.x + len + 1, dest.y - offset); + Draw.line(x - len + 1, y - offset, x + len + 1, y - offset); Draw.thickness(1f); Draw.color(Color.BLACK); - Draw.line(dest.x - len + 1, dest.y - offset, dest.x + len, dest.y - offset); + Draw.line(x - len + 1, y - offset, x + len, y - offset); Draw.color(Color.RED); - Draw.line(dest.x - len + 1, dest.y - offset, dest.x - len + (int)(len * 2 * ((float) dest.health / dest.maxhealth)), dest.y - offset); + Draw.line(x - len + 1, y - offset, x - len + (int)(len * 2 * ((float) health / maxhealth)), y - offset); Draw.clear(); } diff --git a/core/src/io/anuke/moment/Moment.java b/core/src/io/anuke/moment/Moment.java index 5876b88137..6c30817be9 100644 --- a/core/src/io/anuke/moment/Moment.java +++ b/core/src/io/anuke/moment/Moment.java @@ -5,8 +5,7 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import io.anuke.moment.ai.Pathfind; -import io.anuke.moment.entities.Enemy; -import io.anuke.moment.entities.Player; +import io.anuke.moment.entities.*; import io.anuke.moment.resource.Item; import io.anuke.moment.resource.ItemStack; import io.anuke.moment.resource.Recipe; @@ -32,10 +31,10 @@ public class Moment extends ModuleController{ public Recipe recipe; public int rotation; public float placerange = 60; - public float respawntime = 60*6; + public float respawntime = 60*5; public int wave = 1; - public float wavespace = 60*60; + public float wavespace = 20*60; public float wavetime; public float spawnspace = 65; public Tile core; @@ -71,10 +70,6 @@ public class Moment extends ModuleController{ } } - //items.put(Item.stone, 200); - //items.put(Item.iron, 200); - //items.put(Item.steel, 200); - player = new Player(); } @@ -91,10 +86,13 @@ public class Moment extends ModuleController{ if(!playing) return; - if(Enemy.amount == 0) + if(UInput.keyUp(Keys.Q)) + System.out.println("Enemies: " + Enemy.amount + " Wavetime: " + wavetime + " Wave: " + wave + " Wavespace: " + wavespace); + + if(Enemy.amount <= 0) wavetime -= delta(); - if(wavetime < 0 || UInput.keyUp(Keys.F)){ + if(wavetime <= 0){ runWave(); } } @@ -119,6 +117,10 @@ public class Moment extends ModuleController{ items.put(Item.stone, 20); + //items.put(Item.stone, 200); + //items.put(Item.iron, 200); + //items.put(Item.steel, 200); + if(get(UI.class).about != null) get(UI.class).updateItems(); } @@ -170,18 +172,34 @@ public class Moment extends ModuleController{ } public void runWave(){ - int amount = 3*wave; + int amount = wave; for(int i = 0; i < amount; i ++){ - int point = i%spawnpoints.size; - Tile tile = spawnpoints.get(point); - - Timers.run((int)(i/spawnpoints.size)*40f, ()->{ - Enemy e = new Enemy(point).set(tile.worldx(), tile.worldy()); - Effects.effect("spawn", e); - e.add(); - }); + 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 /*&& point == 1 */&& pos == 0){ + 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(); + }); + } } wave ++; diff --git a/core/src/io/anuke/moment/UI.java b/core/src/io/anuke/moment/UI.java index 3f05180e4b..9aa9f3fefc 100644 --- a/core/src/io/anuke/moment/UI.java +++ b/core/src/io/anuke/moment/UI.java @@ -14,6 +14,7 @@ import io.anuke.moment.world.Tile; import io.anuke.moment.world.TileType; import io.anuke.ucore.core.*; import io.anuke.ucore.modules.SceneModule; +import io.anuke.ucore.scene.Scene; import io.anuke.ucore.scene.builders.*; import io.anuke.ucore.scene.style.Styles; import io.anuke.ucore.scene.ui.*; @@ -118,8 +119,16 @@ public class UI extends SceneModule{ about.getContentTable().add("Made by Anuken for the" + "\nGDL Metal Monstrosity jam." + "\nTools used:"); about.addCloseButton(); - restart = new Dialog("The core was destroyed.", "dialog"); - restart.content().add("You lasted until wave [GREEN]" + main.wave + "[].").pad(6); + restart = new Dialog("The core was destroyed.", "dialog"){ + public Dialog show(Scene scene){ + super.show(scene); + restart.content().clearChildren(); + restart.content().add("You lasted until wave [GREEN]" + main.wave + "[].").pad(6); + restart.pack(); + return this; + } + }; + restart.getButtonTable().addButton("Back to menu", ()->{ restart.hide(); main.playing = false; diff --git a/core/src/io/anuke/moment/entities/BossEnemy.java b/core/src/io/anuke/moment/entities/BossEnemy.java index 0e38a365c2..f146367271 100644 --- a/core/src/io/anuke/moment/entities/BossEnemy.java +++ b/core/src/io/anuke/moment/entities/BossEnemy.java @@ -9,6 +9,7 @@ public class BossEnemy extends Enemy{ reload = 8; bullet = BulletType.smallfast; + rotatespeed = 30f; maxhealth = 260; hitsize = 8; speed = 0.27f; diff --git a/core/src/io/anuke/moment/entities/Bullet.java b/core/src/io/anuke/moment/entities/Bullet.java index 37d88ae300..f769ff859a 100644 --- a/core/src/io/anuke/moment/entities/Bullet.java +++ b/core/src/io/anuke/moment/entities/Bullet.java @@ -1,8 +1,12 @@ package io.anuke.moment.entities; +import io.anuke.moment.Moment; +import io.anuke.moment.world.Tile; +import io.anuke.moment.world.TileType; import io.anuke.ucore.entities.BulletEntity; import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.SolidEntity; +import io.anuke.ucore.util.Mathf; public class Bullet extends BulletEntity{ BulletType type; @@ -18,6 +22,23 @@ public class Bullet extends BulletEntity{ type.draw(this); } + @Override + public void update(){ + + int tilex = Mathf.scl2(x, TileType.tilesize); + int tiley = Mathf.scl2(y, TileType.tilesize); + Tile tile = Moment.i.tile(tilex, tiley); + + if(tile != null && tile.entity != null && + tile.entity.collide(this) && !tile.entity.dead){ + tile.entity.collision(this); + remove(); + type.collide(this); + } + + super.update(); + } + @Override public void collision(SolidEntity other){ super.collision(other); diff --git a/core/src/io/anuke/moment/entities/Enemy.java b/core/src/io/anuke/moment/entities/Enemy.java index 775fff034d..a1a392e602 100644 --- a/core/src/io/anuke/moment/entities/Enemy.java +++ b/core/src/io/anuke/moment/entities/Enemy.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2; import io.anuke.moment.Control; import io.anuke.moment.Moment; import io.anuke.moment.ai.Pathfind; +import io.anuke.moment.world.TileType; import io.anuke.ucore.core.Draw; import io.anuke.ucore.entities.*; import io.anuke.ucore.util.Timers; @@ -22,6 +23,7 @@ public class Enemy extends DestructibleEntity{ public float range = 60; public BulletType bullet = BulletType.small; public float length = 4; + public float rotatespeed = 8f; public Enemy(int spawn){ this.spawn = spawn; @@ -40,9 +42,8 @@ public class Enemy extends DestructibleEntity{ Moment.module(Control.class).tryMove(this, vec.x*delta, vec.y*delta); - target = Entities.getClosest(x, y, range, e->{ - return (e instanceof TileEntity || e instanceof Player); - }); + //if(Timers.get(this, 10)) + target = TileType.findTileTarget(x, y, null, range, false); if(target != null){ if(Timers.get(this, reload)) @@ -84,7 +85,7 @@ public class Enemy extends DestructibleEntity{ if(target == null){ direction.add(xvelocity, yvelocity); - direction.limit(speed*8); + direction.limit(speed*rotatespeed); }else{ float angle = angleTo(target); direction.lerp(vector.set(0, 1).setAngle(angle), 0.25f); diff --git a/core/src/io/anuke/moment/entities/FlameEnemy.java b/core/src/io/anuke/moment/entities/FlameEnemy.java index 9bdc81ef95..0bd3df30f7 100644 --- a/core/src/io/anuke/moment/entities/FlameEnemy.java +++ b/core/src/io/anuke/moment/entities/FlameEnemy.java @@ -6,13 +6,13 @@ public class FlameEnemy extends Enemy{ public FlameEnemy(int spawn) { super(spawn); - speed = 0.25f; + speed = 0.3f; - maxhealth = 100; + maxhealth = 150; reload = 6; bullet = BulletType.flameshot; - range = 30; + range = 40; heal(); } diff --git a/core/src/io/anuke/moment/entities/Player.java b/core/src/io/anuke/moment/entities/Player.java index ff95650f21..1917d30741 100644 --- a/core/src/io/anuke/moment/entities/Player.java +++ b/core/src/io/anuke/moment/entities/Player.java @@ -52,6 +52,9 @@ public class Player extends DestructibleEntity{ @Override public void update(){ + if(health < maxhealth && Timers.get(this, 30)) + health ++; + vector.set(0, 0); if(UInput.keyDown("up")) @@ -74,9 +77,6 @@ public class Player extends DestructibleEntity{ vector.limit(speed); - //x += vector.x*delta; - //y += vector.y*delta; - Moment.module(Control.class).tryMove(this, vector.x*delta, vector.y*delta); if(!shooting){ diff --git a/core/src/io/anuke/moment/entities/TileEntity.java b/core/src/io/anuke/moment/entities/TileEntity.java index 3fe5c73d77..918ef72797 100644 --- a/core/src/io/anuke/moment/entities/TileEntity.java +++ b/core/src/io/anuke/moment/entities/TileEntity.java @@ -8,35 +8,31 @@ import io.anuke.moment.ai.Pathfind; import io.anuke.moment.resource.Item; import io.anuke.moment.world.Tile; import io.anuke.moment.world.TileType; -import io.anuke.ucore.entities.DestructibleEntity; import io.anuke.ucore.entities.Effects; -import io.anuke.ucore.entities.SolidEntity; +import io.anuke.ucore.entities.Entity; -public class TileEntity extends DestructibleEntity{ +public class TileEntity extends Entity{ public final Tile tile; public DelayedRemovalArray convey = new DelayedRemovalArray<>(); public ObjectMap items = new ObjectMap<>(); public int shots; public TileEntity link; public float rotation; + public int maxhealth, health; + public boolean dead = false; public TileEntity(Tile tile){ this.tile = tile; x = tile.worldx(); y = tile.worldy(); - hitsize = TileType.tilesize; maxhealth = tile.block().health; - heal(); + health = maxhealth; } - @Override - public boolean collides(SolidEntity other){ - return (other instanceof Bullet) && ((Bullet)other).owner instanceof Enemy; - } - - @Override public void onDeath(){ + dead = true; + if(tile.block() == TileType.core){ Moment.i.coreDestroyed(); } @@ -46,6 +42,16 @@ public class TileEntity extends DestructibleEntity{ Effects.effect("explosion", this); } + public void collision(Bullet other){ + health -= other.getDamage(); + if(health <= 0) onDeath(); + } + + public boolean collide(Bullet other){ + return other.owner instanceof Enemy; + } + + @Override public void update(){ tile.block().update(tile); diff --git a/core/src/io/anuke/moment/resource/Recipe.java b/core/src/io/anuke/moment/resource/Recipe.java index 1dc1792f5b..694ab3b79b 100644 --- a/core/src/io/anuke/moment/resource/Recipe.java +++ b/core/src/io/anuke/moment/resource/Recipe.java @@ -22,8 +22,8 @@ public enum Recipe{ flameturret(defense, TileType.flameturret, stack(Item.iron, 12), stack(Item.steel, 12)), sniperturret(defense, TileType.sniperturret, stack(Item.iron, 15), stack(Item.steel, 20)), - healturret(defense, TileType.healturret, stack(Item.iron, 30)), - megahealturret(defense, TileType.megahealturret, stack(Item.iron, 30), stack(Item.steel, 30)), + healturret(defense, TileType.healturret, stack(Item.iron, 40)), + megahealturret(defense, TileType.megahealturret, stack(Item.iron, 30), stack(Item.steel, 40)), drill(production, TileType.stonedrill, stack(Item.stone, 5)), irondrill(production, TileType.irondrill, stack(Item.stone, 30)), diff --git a/core/src/io/anuke/moment/world/Generator.java b/core/src/io/anuke/moment/world/Generator.java index 05a1823e5a..68d3e81ee2 100644 --- a/core/src/io/anuke/moment/world/Generator.java +++ b/core/src/io/anuke/moment/world/Generator.java @@ -32,10 +32,11 @@ public class Generator{ floor = TileType.coal; } + + if(color == white){ block = TileType.stoneblock; - }else if(color == blue){ Moment.i.core = tiles[x][y]; }else if(color == red){ diff --git a/core/src/io/anuke/moment/world/Tile.java b/core/src/io/anuke/moment/world/Tile.java index 415efad04c..9e41669bd1 100644 --- a/core/src/io/anuke/moment/world/Tile.java +++ b/core/src/io/anuke/moment/world/Tile.java @@ -64,9 +64,10 @@ public class Tile{ public void changed(){ - //TODO where do the items go? - if(entity != null) + if(entity != null){ entity.remove(); + entity = null; + } if(block.update) entity = new TileEntity(this).add(); diff --git a/core/src/io/anuke/moment/world/TileType.java b/core/src/io/anuke/moment/world/TileType.java index 7a235dbc50..85e750add3 100644 --- a/core/src/io/anuke/moment/world/TileType.java +++ b/core/src/io/anuke/moment/world/TileType.java @@ -106,7 +106,7 @@ public enum TileType{ public void draw(Tile tile){ Draw.rect(name() + (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90); - + vector.set(tilesize, 0).rotate(tile.rotation * 90); vector2.set(-tilesize / 2, 0).rotate(tile.rotation * 90); @@ -190,7 +190,7 @@ public enum TileType{ router(true, true, false){ public void update(Tile tile){ - if(Timers.get(tile, 20) && tile.entity.totalItems() > 0){ + if(Timers.get(tile, 10) && tile.entity.totalItems() > 0){ tryDump(tile, tile.rotation++); tile.rotation %= 4; } @@ -426,7 +426,7 @@ public enum TileType{ * tile.entity.removeItem(ammo, 1); } */ //if(tile.entity.shots > 0){ - tile.entity.link = findTileTarget(tile, range); + tile.entity.link = findTileTarget(tile.worldx(), tile.worldy(), tile, range, true); if(tile.entity.link != null){ tile.entity.rotation = tile.entity.angleTo(tile.entity.link); @@ -475,7 +475,7 @@ public enum TileType{ } public void update(Tile tile){ - tile.entity.link = findTileTarget(tile, range); + tile.entity.link = findTileTarget(tile.worldx(), tile.worldy(), tile, range, true); if(tile.entity.link != null){ tile.entity.rotation = tile.entity.angleTo(tile.entity.link); @@ -557,7 +557,6 @@ public enum TileType{ tile.entity.removeItem(ammo, 1); } - //TODO readd if(tile.entity.shots > 0){ Enemy enemy = findTarget(tile, range); if(enemy != null){ @@ -599,17 +598,26 @@ public enum TileType{ return (Enemy) closest; } - TileEntity findTileTarget(Tile tile, float range){ + public static TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){ Entity closest = null; float dst = 0; - - Array array = Entities.getNearby(tile.worldx(), tile.worldy(), 100); - - for(Entity e : array){ - if(e == tile.entity) continue; - - if(e instanceof TileEntity && ((TileEntity) e).health < ((TileEntity) e).tile.block().health){ - float ndst = Vector2.dst(tile.worldx(), tile.worldy(), e.x, e.y); + + int rad = (int)(range/tilesize)+1; + int tilex = Mathf.scl2(x, tilesize); + int tiley = Mathf.scl2(y, tilesize); + + for(int rx = -rad; rx <= rad; rx ++){ + for(int ry = -rad; ry <= rad; ry ++){ + Tile other = Moment.i.tile(rx+tilex, ry+tiley); + + if(other == null || other.entity == null ||(tile != null && other.entity == tile.entity)) continue; + + TileEntity e = other.entity; + + if(damaged && ((TileEntity) e).health >= ((TileEntity) e).tile.block().health) + continue; + + float ndst = Vector2.dst(x, y, e.x, e.y); if(ndst < range && (closest == null || ndst < dst)){ dst = ndst; closest = e;