Implemented many new weapons (still broken)

This commit is contained in:
Anuken
2018-01-08 16:14:32 -05:00
parent c5d13d26ea
commit 0e82a4491f
30 changed files with 427 additions and 186 deletions
@@ -1,7 +1,6 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.effect.DamageArea;
import io.anuke.mindustry.entities.effect.EMP;
import io.anuke.mindustry.entities.enemies.Enemy;
@@ -10,17 +9,12 @@ import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.BaseBulletType;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public abstract class BulletType extends BaseBulletType<Bullet>{
static Color glowy = Color.valueOf("fdc056");
static Color lightGold = Hue.mix(Color.GOLD, Color.WHITE, 0.4f);
static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
static Color lightOrange = Color.valueOf("f68021");
static Color whiteOrange = Hue.mix(lightOrange, Color.WHITE, 0.6f);
static Color whiteYellow = Hue.mix(Color.YELLOW, Color.WHITE, 0.6f);
import static io.anuke.mindustry.graphics.Fx.*;
public abstract class BulletType extends BaseBulletType<Bullet>{
public static final BulletType
@@ -88,9 +82,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
}
public void removed(Bullet b){
Timers.run(5f, ()->{
new EMP(b.x, b.y, b.getDamage()).add();
});
Timers.run(5f, ()-> new EMP(b.x, b.y, b.getDamage()).add());
Effects.effect(Fx.empshockwave, b);
Effects.shake(3f, 3f, b);
}
@@ -220,12 +212,6 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
public void draw(Bullet b){}
},
shellshot = new BulletType(1.5f, 6){
{
lifetime = 7f;
}
public void draw(Bullet b){}
},
blastshot = new BulletType(1.6f, 6){
{
lifetime = 7f;
@@ -255,7 +241,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Draw.reset();
}
},
flame = new BulletType(0.6f, 5){
flame = new BulletType(0.6f, 5){ //for turrets
public void draw(Bullet b){
Draw.color(Color.YELLOW, Color.SCARLET, b.time/lifetime);
float size = 6f-b.time/lifetime*5f;
@@ -274,7 +260,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Draw.reset();
}
},
flameshot = new BulletType(0.5f, 3){
flameshot = new BulletType(0.5f, 3){ //for enemies
public void draw(Bullet b){
Draw.color(Color.ORANGE, Color.SCARLET, b.time/lifetime);
float size = 6f-b.time/lifetime*5f;
@@ -294,9 +280,9 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Draw.reset();
}
},
spread = new BulletType(2.4f, 6) {
spread = new BulletType(2.4f, 7) {
{
lifetime = 50;
lifetime = 70;
}
public void draw(Bullet b) {
@@ -308,15 +294,132 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Draw.reset();
}
},
multishot = new BulletType(2.5f, 3){
cluster = new BulletType(4.4f, 13){
{
lifetime = 40;
lifetime = 60;
drag = 0.06f;
}
public void draw(Bullet b){
Draw.color(Color.SKY);
Draw.rect("bullet", b.x, b.y, b.angle());
Draw.thick(2f);
Draw.color(lightOrange);
Draw.circle(b.x, b.y, 1.6f);
Draw.thick(1f);
Draw.color(Color.WHITE, lightOrange, b.ifract()/2f);
Draw.alpha(b.ifract());
Draw.spikes(b.x, b.y, 1.5f, 2f, 6);
Draw.reset();
}
public void despawned(Bullet b){
removed(b);
}
public void removed(Bullet b){
Effects.shake(1f, 1f, b);
Effects.effect(Fx.clusterbomb, b);
DamageArea.damage(!(b.owner instanceof Enemy), b.x, b.y, 22f, damage);
}
},
rail = new BulletType(4.5f, 11) {
{
lifetime = 50;
}
public void init(Bullet b) {
Timers.reset(b, "smoke", Mathf.random(4f));
}
public void draw(Bullet b){
Draw.color(lightGray);
Draw.thick(1f);
Draw.lineAngleCenter(b.x, b.y, b.angle(), 2f);
Draw.reset();
}
public void update(Bullet b){
if(Timers.get(b, "smoke", 4)){
Effects.effect(Fx.chainsmoke, b.x, b.y);
}
}
},
shotgun = new BulletType(5.4f, 10) {
{
drag = 0.03f;
lifetime = 30f;
}
public void init(Bullet b) {
b.velocity.scl(Mathf.random(0.5f, 1f));
}
public void draw(Bullet b) {
Draw.color(Color.WHITE, Color.ORANGE, b.ifract());
Draw.thick(2f);
Draw.lineAngleCenter(b.x, b.y, b.angle(), b.fract()*5f);
Draw.reset();
}
public void despawned(Bullet b) {
removed(b);
}
public void removed(Bullet b) {
for(int i = 0; i < 4; i ++){
Bullet bullet = new Bullet(scrap, b.owner, b.x, b.y, b.angle() + Mathf.range(80f));
bullet.add();
}
}
},
scrap = new BulletType(2f, 3) {
{
drag = 0.06f;
lifetime = 30f;
}
public void init(Bullet b) {
b.velocity.scl(Mathf.random(0.5f, 1f));
}
public void draw(Bullet b) {
Draw.color(Color.WHITE, Color.ORANGE, b.ifract());
Draw.thick(1f);
Draw.lineAngleCenter(b.x, b.y, b.angle(), b.fract()*4f);
Draw.reset();
}
},
beamlaser = new BulletType(0.001f, 35) {
float length = 230f;
{
drawSize = length*2f+20f;
lifetime = 15f;
}
public void init(Bullet b) {
DamageArea.damageLine(true, Fx.beamhit, b.x, b.y, b.angle(), length, damage);
}
public void draw(Bullet b) {
float f = b.fract()*1.5f;
Draw.color(beam);
Draw.rect("circle", b.x, b.y, 6f*f, 6f*f);
Draw.thick(3f * f);
Draw.lineAngle(b.x, b.y, b.angle(), length);
Draw.thick(2f * f);
Draw.lineAngle(b.x, b.y, b.angle(), length + 6f);
Draw.thick(1f * f);
Draw.lineAngle(b.x, b.y, b.angle(), length + 12f);
Draw.color(beamLight);
Draw.thick(1.5f * f);
Draw.rect("circle", b.x, b.y, 3f*f, 3f*f);
Draw.lineAngle(b.x, b.y, b.angle(), length);
}
};
private BulletType(float speed, int damage){
@@ -1,22 +1,66 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.*;
//TODO
public class DamageArea{
private static Rectangle rect = new Rectangle();
//only for entities, not tiles (yet!)
public static void damageLine(boolean enemies, Effect effect, float x, float y, float angle, float length, int damage){
Angles.translation(angle, length);
rect.setPosition(x, y).setSize(Angles.x(), Angles.y());
float x2 = Angles.x() + x, y2 = Angles.y() + y;
if(rect.width < 0){
rect.x += rect.width;
rect.width *= -1;
}
if(rect.height < 0){
rect.y += rect.height;
rect.height *= -1;
}
float expand = 3f;
rect.y -= expand;
rect.x -= expand;
rect.width += expand*2;
rect.height += expand*2;
if(enemies){
Entities.getNearby(Vars.control.enemyGroup, rect, e -> {
Enemy enemy = (Enemy)e;
Rectangle other = enemy.hitbox.getRect(enemy.x, enemy.y);
other.y -= expand;
other.x -= expand;
other.width += expand*2;
other.height += expand*2;
Vector2 vec = Physics.raycastRect(x, y, x2, y2, other);
if(vec != null){
Effects.effect(effect, vec.x, vec.y);
enemy.damage(damage);
}
});
}//TODO else damage players and blocks?
}
public static void damageEntities(float x, float y, float radius, int damage){
damage(true, x, y, radius, damage);
if(!Vars.android && Vars.player.distanceTo(x, y) < radius){
Player player = Vars.player;
for(Player player : Vars.control.playerGroup.all()){
if(player.isAndroid) continue;
int amount = calculateDamage(x, y, player.x, player.y, radius, damage);
player.damage(amount);
}
@@ -28,6 +28,7 @@ public class Enemy extends DestructibleEntity implements Syncable{
public float angle;
public Vector2 velocity = new Vector2();
public Entity target;
public float hitTime;
public int tier = 1;
public Enemy(EnemyType type){
@@ -59,6 +60,12 @@ public class Enemy extends DestructibleEntity implements Syncable{
return (other instanceof Bullet) && !(((Bullet) other).owner instanceof Enemy);
}
@Override
public void damage(int amount){
super.damage(amount);
hitTime = EnemyType.hitDuration;
}
@Override
public void onDeath(){
type.onDeath(this);
@@ -31,6 +31,7 @@ public class EnemyType {
public final static int maxtier = 4;
public final static float maxIdle = 60*1.5f;
public final static float maxIdleLife = 60f*13f; //13 seconds idle = death
public final static float hitDuration = 5f;
public final String name;
public final byte id;
@@ -65,6 +66,7 @@ public class EnemyType {
String region = name + "-t" + Mathf.clamp(enemy.tier, 1, 3);
Shaders.outline.color.set(tierColors[enemy.tier - 1]);
Shaders.outline.lighten = Mathf.clamp(enemy.hitTime/hitDuration);
Shaders.outline.region = Draw.region(region);
Shaders.outline.apply();
@@ -73,12 +75,16 @@ public class EnemyType {
Draw.color();
Graphics.flush();
Shaders.outline.lighten = 0f;
}
public void drawOver(Enemy enemy){ }
public void update(Enemy enemy){
float lastx = enemy.x, lasty = enemy.y;
if(enemy.hitTime > 0){
enemy.hitTime -= Timers.delta();
}
move(enemy);
@@ -27,7 +27,7 @@ public class TitanType extends EnemyType {
if(Timers.getTime(enemy, "salvo") < 60){
if(Timers.get(enemy, "salvoShoot", 6)){
enemy.shoot(BulletType.flame, Mathf.range(20f));
enemy.shoot(BulletType.flameshot, Mathf.range(20f));
}
}