Removed all usage of drawBullet, switched to BasicBulletType

This commit is contained in:
Anuken
2018-05-27 15:49:01 -04:00
parent 0b28f97d8f
commit 736552f3b1
2 changed files with 35 additions and 58 deletions

View File

@ -7,6 +7,7 @@ import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.content.fx.EnvironmentFx;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.bullet.BasicBulletType;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.effect.DamageArea;
@ -21,7 +22,6 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
@ -71,72 +71,46 @@ public class TurretBullets {
}
},
basicIron = new BulletType(3f, 5) {
@Override
public void draw(Bullet b) {
drawBullet(Palette.bulletYellow, Palette.bulletYellowBack,
"bullet", b.x, b.y, 9f, 5f + b.fout()*7f, b.angle() - 90);
basicIron = new BasicBulletType(3f, 5) {
{
bulletWidth = 7f;
bulletHeight = 9f;
}
},
basicSteel = new BulletType(6f, 0) {
basicSteel = new BasicBulletType(6f, 0) {
{
hiteffect = BulletFx.hitBulletBig;
knockback = 0.5f;
}
@Override
public void draw(Bullet b) {
drawBullet(Palette.bulletYellow, Palette.bulletYellowBack,
"bullet", b.x, b.y, 11f, 9f + b.fout()*8f, b.angle() - 90);
bulletWidth = 9f;
bulletHeight = 11f;
}
},
basicLeadFragShell = new BulletType(3f, 0) {
basicLeadFragShell = new BasicBulletType(3f, 0) {
{
hiteffect = BulletFx.flakExplosion;
knockback = 0.8f;
lifetime = 90f;
drag = 0.01f;
}
@Override
public void draw(Bullet b) {
drawBullet(Palette.bulletYellow, Palette.bulletYellowBack,
"shell", b.x, b.y, 9f, 9f, b.angle() - 90);
}
@Override
public void hit(Bullet b, float x, float y) {
super.hit(b, x, y);
for(int i = 0; i < 9; i ++){
float len = Mathf.random(1f, 7f);
float a = Mathf.random(360f);
Bullet bullet = Bullet.create(TurretBullets.basicLeadFrag, b,
x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a);
bullet.velocity.scl(Mathf.random(0.2f, 1f));
}
}
@Override
public void despawned(Bullet b) {
hit(b);
bulletWidth = bulletHeight = 9f;
fragBullet = basicLeadFrag;
bulletSprite = "frag";
bulletShrink = 0.1f;
}
},
basicLeadFrag = new BulletType(3f, 0) {
basicLeadFrag = new BasicBulletType(3f, 0) {
{
drag = 0.1f;
hiteffect = Fx.none;
despawneffect = Fx.none;
hitsize = 4;
lifetime = 20f;
}
@Override
public void draw(Bullet b) {
drawBullet(Palette.bulletYellow, Palette.bulletYellowBack,
"bullet", b.x, b.y, 7f + b.fout()*3f, 1f + b.fout()*11f, b.angle() - 90);
bulletWidth = 9f;
bulletHeight = 11f;
bulletShrink = 1f;
//todo scaling
}
},
@ -239,14 +213,6 @@ public class TurretBullets {
}
};
private static void drawBullet(Color first, Color second, String name, float x, float y, float w, float h, float rot){
Draw.color(second);
Draw.rect(name + "-back", x, y, w, h, rot);
Draw.color(first);
Draw.rect(name, x, y, w, h, rot);
Draw.color();
}
private abstract static class LiquidShot extends BulletType{
Liquid liquid;

View File

@ -1,31 +1,42 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
/**A BulletType for most ammo-based bullets shot from turrets and units.*/
public abstract class BasicBulletType extends BulletType {
public class BasicBulletType extends BulletType {
public Color backColor = Palette.bulletYellowBack, frontColor = Palette.bulletYellow;
public String bulletSprite = "bullet";
public float bulletWidth = 5f, bulletHeight = 7f;
public float bulletShrink = 0.5f;
public boolean frag;
public int fragBullets = 9;
public float fragVelocityMin = 0.2f, fragVelocityMax = 1f;
public BulletType fragBullet = TurretBullets.basicLeadFrag;
public BulletType fragBullet = null;
public BasicBulletType(float speed, float damage) {
super(speed, damage);
}
@Override
public void draw(Bullet b) {
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);
Draw.rect(bulletSprite + "-back", b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.color(frontColor);
Draw.rect(bulletSprite, b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.color();
}
@Override
public void hit(Bullet b, float x, float y) {
super.hit(b, x, y);
if(frag) {
if(fragBullet != null) {
for (int i = 0; i < fragBullets; i++) {
float len = Mathf.random(1f, 7f);
float a = Mathf.random(360f);
@ -38,7 +49,7 @@ public abstract class BasicBulletType extends BulletType {
@Override
public void despawned(Bullet b) {
if(frag){
if(fragBullet != null){
hit(b);
}
}