Added more enemies

This commit is contained in:
Anuken
2017-04-30 13:01:29 -04:00
parent 13ac9f2d8f
commit 53008df1d2
19 changed files with 402 additions and 194 deletions

View File

@@ -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.Enemy;
import io.anuke.moment.entities.FlameEnemy;
import io.anuke.moment.entities.TileEntity;
import io.anuke.moment.resource.ItemStack;
import io.anuke.moment.world.Tile;
@@ -89,6 +89,14 @@ public class Control extends RendererModule<Moment>{
Draw.clear();
});
Effect.addDraw("coreexplosion", 13, e -> {
Draw.thickness(3f-e.ifract()*2f);
Draw.color(Hue.mix(Color.ORANGE, Color.WHITE, e.ifract()));
Draw.spikes(e.x, e.y, 5f + e.ifract() * 40f, 6, 6);
Draw.circle(e.x, e.y, 4f + e.ifract() * 40f);
Draw.clear();
});
Effect.addDraw("spawn", 23, e -> {
Draw.thickness(2f);
Draw.color(Hue.mix(Color.DARK_GRAY, Color.SCARLET, e.ifract()));
@@ -102,13 +110,21 @@ public class Control extends RendererModule<Moment>{
Draw.circle(e.x, e.y, 3);
Draw.clear();
});
Effect.addDraw("respawn", main.respawntime, e -> {
Draw.tcolor(Color.SCARLET);
Draw.tscl(0.25f);
Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);
Draw.tscl(0.5f);
Draw.clear();
});
Pathfind.updatePath();
}
public void tryMove(SolidEntity e, float x, float y){
e.getBoundingBox(Rectangle.tmp);
Rectangle.tmp.setSize(Rectangle.tmp.width * 0.5f);
Rectangle.tmp.setSize(4);
if(!overlaps(Rectangle.tmp, e.x + x, e.y)){
e.x += x;
@@ -152,8 +168,9 @@ public class Control extends RendererModule<Moment>{
Cursors.restoreCursor();
}
//TODO
if(UInput.keyUp(Keys.G))
new Enemy(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());
@@ -257,7 +274,10 @@ public class Control extends RendererModule<Moment>{
Entities.update();
input();
camera.position.set(main.player.x, main.player.y, 0f);
if(main.core.block() == TileType.core)
camera.position.set(main.player.x, main.player.y, 0f);
else
camera.position.set(main.core.worldx(), main.core.worldy(), 0f);
clampCamera(-tilesize / 2f, -tilesize / 2f, main.pixsize - tilesize / 2f, main.pixsize - tilesize / 2f);
drawDefault();

View File

@@ -16,6 +16,7 @@ import io.anuke.ucore.core.KeyBinds;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.UInput;
import io.anuke.ucore.entities.Effects;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.modules.ModuleController;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
@@ -30,9 +31,10 @@ public class Moment extends ModuleController<Moment>{
public Recipe recipe;
public int rotation;
public float placerange = 60;
public float respawntime = 60*6;
public int wave = 1;
public float wavespace = 1000;
public float wavespace = 60*60;
public float wavetime = wavespace;
public float spawnspace = 65;
public Tile core;
@@ -68,17 +70,13 @@ public class Moment extends ModuleController<Moment>{
}
}
generate();
items.put(Item.stone, 20);
//items.put(Item.stone, 200);
//items.put(Item.iron, 200);
//items.put(Item.steel, 200);
player = new Player().add();
player = new Player();
player.x = core.worldx();
player.y = core.worldy()+10;
restart();
}
@Override
@@ -100,8 +98,36 @@ public class Moment extends ModuleController<Moment>{
playing = true;
}
public void restart(){
wave = 1;
wavetime = wavespace;
Entities.clear();
Enemy.amount = 0;
player.add();
player.heal();
items.clear();
generate();
player.x = core.worldx();
player.y = core.worldy()+10;
items.put(Item.stone, 20);
}
public void coreDestroyed(){
//TODO "you lose" message or something
Effects.shake(5, 6);
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, ()->{
getModule(UI.class).showRestart();
});
}
void generate(){

View File

@@ -27,7 +27,7 @@ public class UI extends SceneModule<Moment>{
Table itemtable;
PrefsDialog prefs;
KeybindDialog keys;
Dialog about, menu;
Dialog about, menu, restart;
BooleanSupplier play = () -> {
return main.playing;
@@ -65,7 +65,7 @@ public class UI extends SceneModule<Moment>{
Draw.tscl(1 / 8f);
Draw.text(error, tile.worldx(), tile.worldy() + tilesize);
}else if(tile.block().name().contains("turret")){
}else if(tile.block().ammo != null){
Draw.tscl(1 / 8f);
Draw.tcolor(Color.GREEN);
Draw.text("Ammo: " + tile.entity.shots, tile.worldx(), tile.worldy() - tilesize);
@@ -106,6 +106,9 @@ public class UI extends SceneModule<Moment>{
prefs.sliderPref("screenshake", "Screen Shake", 4, 0, 12, i -> {
return (i / 4f) + "x";
});
prefs.checkPref("fps", "Show FPS", false);
keys = new KeybindDialog();
@@ -113,6 +116,14 @@ public class UI extends SceneModule<Moment>{
about.getContentTable().add("Made by Anuken for the" + "\nGDL Metal Monstrosity jam." + "\nTools used:");
about.addCloseButton();
restart = new Dialog("Your core was destroyed.", "dialog");
restart.content().add("You lasted until wave [GREEN]" + main.wave + "[].").pad(6);
restart.getButtonTable().addButton("Back to menu", ()->{
restart.hide();
main.playing = false;
main.restart();
});
menu = new Dialog("Paused", "dialog");
menu.content().addButton("Back", ()->{
menu.hide();
@@ -181,6 +192,7 @@ public class UI extends SceneModule<Moment>{
ImageButton image = new ImageButton(Draw.region(r.result.name()), "select");
image.clicked(()->{
if(main.hasItems(r.requirements))
main.recipe = r;
});
@@ -188,8 +200,12 @@ public class UI extends SceneModule<Moment>{
image.getImageCell().size(size);
image.update(()->{
image.setChecked(main.recipe == r);
image.setDisabled(!main.hasItems(r.requirements));
boolean has = main.hasItems(r.requirements);
image.setDisabled(!has);
image.setChecked(main.recipe == r && has);
//image.setTouchable(has ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Color.GRAY);
});
if(i % rows == rows-1)
@@ -401,6 +417,10 @@ public class UI extends SceneModule<Moment>{
build.end();
}
public void showRestart(){
restart.show(scene);
}
public void updateItems(){
itemtable.clear();

View File

@@ -0,0 +1,25 @@
package io.anuke.moment.entities;
import io.anuke.ucore.core.Draw;
public class BossEnemy extends Enemy{
public BossEnemy(int spawn) {
super(spawn);
reload = 8;
bullet = BulletType.smallfast;
maxhealth = 260;
hitsize = 8;
speed = 0.27f;
heal();
range = 70;
}
@Override
public void draw(){
Draw.rect("bossmech", x, y, direction.angle()-90);
}
}

View File

@@ -34,6 +34,14 @@ public enum BulletType{
Draw.clear();
}
},
smallfast(1.6f, 2){
Color color = new Color(0x8b5ec9ff);
public void draw(Bullet b){
Draw.color(color);
Draw.rect("bullet", b.x, b.y, b.angle());
Draw.clear();
}
},
flame(0.6f, 4){
public void draw(Bullet b){
Draw.color(Color.YELLOW, Color.SCARLET, b.time/lifetime);
@@ -42,6 +50,14 @@ public enum BulletType{
Draw.clear();
}
},
flameshot(0.5f, 3){
public void draw(Bullet b){
Draw.color(Color.ORANGE, Color.SCARLET, b.time/lifetime);
float size = 6f-b.time/lifetime*5f;
Draw.rect("circle", b.x, b.y, size, size);
Draw.clear();
}
},
shot(2.4f, 2){
{lifetime=40;}
public void draw(Bullet b){

View File

@@ -19,6 +19,9 @@ public class Enemy extends DestructibleEntity{
public Entity target;
public int spawn;
public float reload = 40;
public float range = 60;
public BulletType bullet = BulletType.small;
public float length = 4;
public Enemy(int spawn){
this.spawn = spawn;
@@ -37,16 +40,22 @@ public class Enemy extends DestructibleEntity{
Moment.module(Control.class).tryMove(this, vec.x*delta, vec.y*delta);
target = Entities.getClosest(x, y, 60, e->{
target = Entities.getClosest(x, y, range, e->{
return (e instanceof TileEntity || e instanceof Player);
});
if(target != null){
if(Timers.get(this, reload))
new Bullet(BulletType.small, this, x, y, direction.angle()).add();
shoot();
}
}
public void shoot(){
vector.set(length, 0).rotate(direction.angle());
new Bullet(bullet, this, x+vector.x, y+vector.y, direction.angle()).add();
}
@Override
public boolean collides(SolidEntity other){
return (other instanceof Bullet) && !(((Bullet)other).owner instanceof Enemy);

View File

@@ -0,0 +1,22 @@
package io.anuke.moment.entities;
import io.anuke.ucore.core.Draw;
public class FastEnemy extends Enemy{
public FastEnemy(int spawn) {
super(spawn);
speed = 0.7f;
reload = 30;
maxhealth = 20;
heal();
}
@Override
public void draw(){
Draw.rect("fastmech", x, y, direction.angle()-90);
}
}

View File

@@ -0,0 +1,25 @@
package io.anuke.moment.entities;
import io.anuke.ucore.core.Draw;
public class FlameEnemy extends Enemy{
public FlameEnemy(int spawn) {
super(spawn);
speed = 0.25f;
maxhealth = 100;
reload = 6;
bullet = BulletType.flameshot;
range = 30;
heal();
}
@Override
public void draw(){
Draw.rect("firemech", x, y, direction.angle()-90);
}
}

View File

@@ -9,7 +9,9 @@ import io.anuke.moment.UI;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.UInput;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.entities.Effects;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Timers;
public class Player extends DestructibleEntity{
Vector2 direction = new Vector2();
@@ -25,6 +27,20 @@ public class Player extends DestructibleEntity{
heal();
}
@Override
public void onDeath(){
remove();
Effects.effect("explosion", this);
Effects.shake(4f, 5f);
Effects.effect("respawn", this);
Timers.run(Moment.i.respawntime, ()->{
set(Moment.i.core.worldx(), Moment.i.core.worldy()+8);
heal();
add();
});
}
@Override
public void removed(){
}

View File

@@ -14,8 +14,6 @@ public enum Recipe{
fastconveyor(distribution, TileType.steelconveyor, stack(Item.steel, 1)),
router(distribution, TileType.router, stack(Item.stone, 3)),
healturret(defense, TileType.healturret, stack(Item.iron, 30)),
megahealturret(defense, TileType.megahealturret, stack(Item.iron, 30), stack(Item.steel, 30)),
turret(defense, TileType.turret, stack(Item.stone, 4)),
dturret(defense, TileType.doubleturret, stack(Item.stone, 6)),
@@ -24,6 +22,9 @@ 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)),
drill(production, TileType.stonedrill, stack(Item.stone, 5)),
irondrill(production, TileType.irondrill, stack(Item.stone, 30)),
coaldrill(production, TileType.coaldrill, stack(Item.stone, 30), stack(Item.iron, 30)),