Added TeslaOrb entity and implemented tesla turrets

This commit is contained in:
Anuken
2017-09-21 14:07:58 -04:00
parent d3b613feb2
commit ec0b4b5dc4
38 changed files with 557 additions and 315 deletions
@@ -108,6 +108,17 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Draw.reset();
}
},
plasmaflame = new BulletType(0.8f, 15){
{
lifetime = 65f;
}
public void draw(Bullet b){
Draw.color(Color.valueOf("c2efd7"), Color.valueOf("72deaf"), b.time/lifetime);
float size = 7f-b.time/lifetime*6f;
Draw.rect("circle", b.x, b.y, size, size);
Draw.reset();
}
},
flameshot = new BulletType(0.5f, 3){
public void draw(Bullet b){
Draw.color(Color.ORANGE, Color.SCARLET, b.time/lifetime);
@@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.util.Angles;
@@ -0,0 +1,5 @@
package io.anuke.mindustry.entities;
public enum StatusEffect{
none;
}
@@ -1,99 +0,0 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public enum Weapon{
blaster(15, BulletType.shot, "Shoots a slow, weak bullet."){
{
unlocked = true;
}
@Override
public void shoot(Player p){
super.shoot(p);
Effects.effect("shoot3", p.x + vector.x, p.y+vector.y);
}
},
trishot(13, BulletType.shot, "Shoots 3 bullets in a spread.", stack(Item.iron, 40)){
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
float space = 12;
bullet(p, p.x, p.y, ang);
bullet(p, p.x, p.y, ang+space);
bullet(p, p.x, p.y, ang-space);
Effects.effect("shoot", p.x + vector.x, p.y+vector.y);
}
},
multigun(6, BulletType.shot2, "Shoots inaccurate bullets with a high\nrate of fire.", stack(Item.iron, 60), stack(Item.steel, 20)){
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
bullet(p, p.x, p.y, ang + Mathf.range(8));
Effects.effect("shoot2", p.x + vector.x, p.y+vector.y);
}
},
flamethrower(5, BulletType.flame, "Shoots a stream of fire.", stack(Item.steel, 60), stack(Item.coal, 60)){
{
shootsound = "flame2";
}
@Override
public void shoot(Player p){
float ang = mouseAngle(p);
//????
MathUtils.random.setSeed(Gdx.graphics.getFrameId());
bullet(p, p.x, p.y, ang + Mathf.range(12));
}
};
float reload;
BulletType type;
public String shootsound = "shoot";
public boolean unlocked;
public ItemStack[] requirements;
public String description = "no desc for you";
Vector2 vector = new Vector2();
private Weapon(float reload, BulletType type, String desc, ItemStack... requirements){
this.reload = reload;
this.type = type;
this.requirements = requirements;
this.description = desc;
}
public void shoot(Player p){
bullet(p, p.x, p.y, mouseAngle(p));
}
float mouseAngle(Entity owner){
return Angles.mouseAngle(owner.x, owner.y);
}
void bullet(Entity owner, float x, float y, float angle){
vector.set(3, 0).rotate(mouseAngle(owner));
new Bullet(type, owner, x+vector.x, y+vector.y, angle).add();
}
private static ItemStack stack(Item item, int amount){
return new ItemStack(item, amount);
}
}
@@ -0,0 +1,127 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public class TeslaOrb extends Entity{
private Array<Vector2> points = new Array<>();
private ObjectSet<Enemy> hit = new ObjectSet<>();
private int damage = 0;
private float range = 0;
private float lifetime = 30f;
private float life = 0f;
public TeslaOrb(float x, float y, float range, int damage){
set(x, y);
this.damage = damage;
this.range = range;
}
void shock(){
float stopchance = 0.1f;
float curx = x, cury = y;
float shake = 3f;
outer:
while(true){
if(Mathf.chance(stopchance)){
break;
}
Array<SolidEntity> enemies = Entities.getNearby(curx, cury, range);
for(SolidEntity entity : enemies){
if(entity instanceof Enemy && entity.distanceTo(curx, cury) < range
&& !hit.contains((Enemy)entity)){
hit.add((Enemy)entity);
points.add(new Vector2(entity.x + Mathf.range(shake), entity.y + Mathf.range(shake)));
damageEnemy((Enemy)entity);
curx = entity.x;
cury = entity.y;
continue outer;
}
}
break;
}
if(points.size == 0){
remove();
}
}
void damageEnemy(Enemy enemy){
//TODO
enemy.damage(damage);
Effects.effect("laserhit", enemy.x + Mathf.range(2f), enemy.y + Mathf.range(2f));
}
@Override
public void update(){
life += Timers.delta();
if(life >= lifetime){
remove();
}
}
@Override
public void drawOver(){
if(points.size == 0) return;
float range = 1f;
Vector2 previous = Tmp.v1.set(x, y);
for(Vector2 enemy : points){
float x1 = previous.x + Mathf.range(range),
y1 = previous.y + Mathf.range(range),
x2 = enemy.x + Mathf.range(range),
y2 = enemy.y + Mathf.range(range);
Draw.color(Color.WHITE);
Draw.alpha(1f-life/lifetime);
Draw.thick(3f - life/lifetime*2f);
Draw.line(x1, y1, x2, y2);
float rad = 7f - life/lifetime*5f;
Draw.rect("circle", x2, y2, rad, rad);
if(previous.epsilonEquals(x, y, 0.001f)){
Draw.rect("circle", x, y, rad, rad);
}
//Draw.color(Color.WHITE);
//Draw.thick(2f - life/lifetime*2f);
//Draw.line(x1, y1, x2, y2);
Draw.reset();
previous = enemy;
}
}
@Override
public void added(){
Timers.run(1f, ()->{
shock();
});
}
}
@@ -4,9 +4,7 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.Draw;
@@ -30,6 +28,7 @@ public class Enemy extends DestructibleEntity{
public Vector2 direction = new Vector2();
public float xvelocity, yvelocity;
public Entity target;
public StatusEffect effect = StatusEffect.none;
public Enemy(int spawn){