Sprite cleanup / Bullets

This commit is contained in:
Anuken
2020-02-08 14:48:04 -05:00
parent f46be924b9
commit 8814dbe29a
33 changed files with 578 additions and 538 deletions
@@ -8,5 +8,6 @@ mindustry.entities.AllEntities.GroundEffectDef=9
mindustry.entities.AllEntities.EffectDef=2 mindustry.entities.AllEntities.EffectDef=2
mindustry.entities.AllEntities.GenericUnitDef=5 mindustry.entities.AllEntities.GenericUnitDef=5
mindustry.entities.AllEntities.TileDef=3 mindustry.entities.AllEntities.TileDef=3
vanguard=10
dagger2=8 dagger2=8
mindustry.entities.AllEntities.DecalDef=1 mindustry.entities.AllEntities.DecalDef=1

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 176 B

Before

Width:  |  Height:  |  Size: 170 B

After

Width:  |  Height:  |  Size: 170 B

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before

Width:  |  Height:  |  Size: 361 B

After

Width:  |  Height:  |  Size: 361 B

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 181 B

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 218 B

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 697 KiB

After

Width:  |  Height:  |  Size: 698 KiB

+18 -1
View File
@@ -12,8 +12,9 @@ public class UnitTypes implements ContentList{
crawler, titan, fortress, eruptor, chaosArray, eradicator; crawler, titan, fortress, eruptor, chaosArray, eradicator;
public static @EntityDef({Unitc.class, Legsc.class}) UnitDef dagger; public static @EntityDef({Unitc.class, Legsc.class}) UnitDef dagger;
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitDef vanguard;
public static UnitDef vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive; public static UnitDef alpha, delta, tau, omega, dart, javelin, trident, glaive;
public static UnitDef starter; public static UnitDef starter;
@@ -35,6 +36,22 @@ public class UnitTypes implements ContentList{
}}); }});
}}; }};
vanguard = new UnitDef("vanguard"){{
speed = 0.3f;
drag = 0.1f;
hitsize = 8f;
mass = 1.75f;
health = 130;
weapons.add(new Weapon("chain-blaster"){{
reload = 10f;
x = 1.25f;
alternate = true;
rotate = true;
ejectEffect = Fx.shellEjectSmall;
bullet = Bullets.standardCopper;
}});
}};
/* /*
draug = new UnitDef("draug", MinerDrone::new){{ draug = new UnitDef("draug", MinerDrone::new){{
flying = true; flying = true;
+2 -4
View File
@@ -54,16 +54,14 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
} }
public void each(Cons<T> cons){ public void each(Cons<T> cons){
T[] items = array.items;
for(index = 0; index < array.size; index++){ for(index = 0; index < array.size; index++){
cons.get(items[index]); cons.get(array.items[index]);
} }
} }
public void each(Boolf<T> filter, Cons<T> cons){ public void each(Boolf<T> filter, Cons<T> cons){
T[] items = array.items;
for(index = 0; index < array.size; index++){ for(index = 0; index < array.size; index++){
if(filter.get(items[index])) cons.get(items[index]); if(filter.get(array.items[index])) cons.get(array.items[index]);
} }
} }
@@ -3,6 +3,7 @@ package mindustry.entities.bullet;
import arc.audio.*; import arc.audio.*;
import arc.math.*; import arc.math.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
@@ -198,30 +199,22 @@ public abstract class BulletType extends Content{
} }
public Bulletc create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data){ public Bulletc create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data){
Bulletc bullet = BulletEntity.create();
//TODO assign type damage is damage <0, else assign provided damage bullet.type(this);
bullet.owner(owner);
//TODO implement bullet.team(team);
return null; bullet.vel().trns(angle, speed * velocityScl);
/* bullet.set(x - bullet.vel().x * Time.delta(), y - bullet.vel().y * Time.delta());
Bullet bullet = Pools.obtain(Bullet.class, Bullet::new); bullet.lifetime(lifetime * lifetimeScl);
bullet.type = type; bullet.data(data);
bullet.owner = owner; bullet.drag(drag);
bullet.data = data; bullet.hitSize(hitSize);
bullet.damage(damage < 0 ? this.damage : damage);
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).vel() : Vec2.ZERO);
}
bullet.team = team;
bullet.type = type;
bullet.lifeScl = lifetimeScl;
bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta());
bullet.add(); bullet.add();
return bullet;*/ //if(keepVelocity && owner instanceof Velc) bullet.vel().add(((Velc)owner).vel());
return bullet;
} }
public void createNet(Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl){ public void createNet(Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl){
@@ -11,20 +11,19 @@ import mindustry.world.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@Component @Component
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc, DrawLayerBulletsc{
private float lifeScl;
Object data; Object data;
BulletType type; BulletType type;
float damage; float damage;
@Override
public void drawBullets(){
type.draw(this);
}
@Override @Override
public void add(){ public void add(){
type.init(this); type.init(this);
drag(type.drag);
hitSize(type.hitSize);
lifetime(lifeScl * type.lifetime);
} }
@Override @Override
@@ -32,11 +31,6 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
type.despawned(this); type.despawned(this);
} }
@Override
public float getLifetime(){
return type.lifetime;
}
@Override @Override
public float damageMultiplier(){ public float damageMultiplier(){
if(owner() instanceof Unitc){ if(owner() instanceof Unitc){
@@ -58,7 +52,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
@Override @Override
public float damage(){ public float damage(){
return type.damage * damageMultiplier(); return damage * damageMultiplier();
} }
@Override @Override
@@ -10,7 +10,7 @@ import mindustry.world.blocks.*;
import static mindustry.Vars.net; import static mindustry.Vars.net;
@Component @Component
abstract class FlyingComp implements Posc, Velc, Healthc{ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
transient float x, y; transient float x, y;
transient Vec2 vel; transient Vec2 vel;
@@ -34,8 +34,8 @@ abstract class FlyingComp implements Posc, Velc, Healthc{
public void update(){ public void update(){
Floor floor = floorOn(); Floor floor = floorOn();
if(isGrounded() && floor.isLiquid && !vel.isZero(0.01f)){ if(isGrounded() && floor.isLiquid){
if((splashTimer += vel.len()) >= 7f){ if((splashTimer += Mathf.dst(deltaX(), deltaY())) >= 7f){
floor.walkEffect.at(x, y, 0, floor.color); floor.walkEffect.at(x, y, 0, floor.color);
splashTimer = 0f; splashTimer = 0f;
} }
@@ -9,6 +9,8 @@ import mindustry.gen.*;
abstract class TimedComp implements Entityc, Scaled{ abstract class TimedComp implements Entityc, Scaled{
float time, lifetime; float time, lifetime;
//called last so pooling and removal happens then.
@MethodPriority(100)
@Override @Override
public void update(){ public void update(){
time = Math.min(time + Time.delta(), lifetime); time = Math.min(time + Time.delta(), lifetime);
@@ -1,6 +1,7 @@
package mindustry.entities.def; package mindustry.entities.def;
import arc.math.*; import arc.math.*;
import arc.math.geom.*;
import arc.util.*; import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.entities.*; import mindustry.entities.*;
@@ -28,8 +29,19 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
} }
} }
void controlWeapons(boolean rotate, boolean shoot){
for(WeaponMount mount : mounts){
mount.rotate = rotate;
mount.shoot = shoot;
}
}
void aim(Position pos){
aim(pos.getX(), pos.getY());
}
/** Aim at something. This will make all mounts point at it. */ /** Aim at something. This will make all mounts point at it. */
void aim(Unitc unit, float x, float y){ void aim(float x, float y){
Tmp.v1.set(x, y).sub(this.x, this.y); Tmp.v1.set(x, y).sub(this.x, this.y);
if(Tmp.v1.len() < minAimDst) Tmp.v1.setLength(minAimDst); if(Tmp.v1.len() < minAimDst) Tmp.v1.setLength(minAimDst);
@@ -49,18 +61,18 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
Weapon weapon = mount.weapon; Weapon weapon = mount.weapon;
mount.reload = Math.max(mount.reload - Time.delta(), 0); mount.reload = Math.max(mount.reload - Time.delta(), 0);
//rotate if applicable
if(weapon.rotate && (mount.rotate || mount.shoot)){
float axisXOffset = weapon.mirror ? 0f : weapon.x;
float axisX = this.x + Angles.trnsx(rotation, axisXOffset, weapon.y),
axisY = this.y + Angles.trnsy(rotation, axisXOffset, weapon.y);
mount.rotation = Angles.moveToward(mount.rotation, Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - rotation(), weapon.rotateSpeed);
}
if(mount.shoot){ if(mount.shoot){
float rotation = this.rotation - 90; float rotation = this.rotation - 90;
//rotate if applicable
if(weapon.rotate){
float axisXOffset = weapon.mirror ? 0f : weapon.x;
float axisX = this.x + Angles.trnsx(rotation, axisXOffset, weapon.y),
axisY = this.y + Angles.trnsy(rotation, axisXOffset, weapon.y);
mount.rotation = Angles.moveToward(mount.rotation, Angles.angle(axisX, axisY, mount.aimX, mount.aimY), weapon.rotateSpeed);
}
//shoot if applicable //shoot if applicable
//TODO only shoot if angle is reached, don't shoot inaccurately //TODO only shoot if angle is reached, don't shoot inaccurately
if(mount.reload <= 0.0001f){ if(mount.reload <= 0.0001f){
@@ -73,7 +85,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
mountY = this.y + Angles.trnsy(rotation, weapon.x * i, weapon.y); mountY = this.y + Angles.trnsy(rotation, weapon.x * i, weapon.y);
float shootX = mountX + Angles.trnsx(weaponRotation, weapon.shootX * i, weapon.shootY), float shootX = mountX + Angles.trnsx(weaponRotation, weapon.shootX * i, weapon.shootY),
shootY = mountY + Angles.trnsy(weaponRotation, weapon.shootX * i, weapon.shootY); shootY = mountY + Angles.trnsy(weaponRotation, weapon.shootX * i, weapon.shootY);
float shootAngle = weapon.rotate ? weaponRotation : Angles.angle(shootX, shootY, mount.aimX, mount.aimY); float shootAngle = weapon.rotate ? weaponRotation + 90 : Angles.angle(shootX, shootY, mount.aimX, mount.aimY);
shoot(weapon, shootX, shootY, shootAngle); shoot(weapon, shootX, shootY, shootAngle);
} }
@@ -15,6 +15,8 @@ public class WeaponMount{
public boolean side; public boolean side;
/** whether to shoot right now */ /** whether to shoot right now */
public boolean shoot = false; public boolean shoot = false;
/** whether to rotate to face the target right now */
public boolean rotate = false;
public WeaponMount(Weapon weapon){ public WeaponMount(Weapon weapon){
this.weapon = weapon; this.weapon = weapon;
+16 -5
View File
@@ -5,6 +5,7 @@ import arc.Graphics.*;
import arc.Graphics.Cursor.*; import arc.Graphics.Cursor.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*;
import arc.scene.*; import arc.scene.*;
import arc.scene.event.*; import arc.scene.event.*;
import arc.scene.ui.*; import arc.scene.ui.*;
@@ -163,7 +164,7 @@ public class DesktopInput extends InputHandler{
} }
} }
if(!player.dead() && !state.isPaused()){ if(!player.dead() && !state.isPaused() && !(Core.scene.getKeyboardFocus() instanceof TextField)){
updateMovement(player.unit()); updateMovement(player.unit());
} }
@@ -495,14 +496,24 @@ public class DesktopInput extends InputHandler{
} }
protected void updateMovement(Unitc unit){ protected void updateMovement(Unitc unit){
boolean canMove = !(Core.scene.getKeyboardFocus() instanceof TextField); boolean omni = !(unit instanceof WaterMovec);
float speed = unit.type().speed; float speed = unit.type().speed;
float xa = Core.input.axis(Binding.move_x); float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y); float ya = Core.input.axis(Binding.move_y);
unit.vel().add(Tmp.v1.set(speed * xa, speed * ya).limit(speed)); Vec2 movement = Tmp.v1.set(speed * xa, speed * ya).limit(speed);
unit.lookAt(Angles.mouseAngle(unit.x(), unit.y()));
if(omni){
unit.vel().add(movement);
unit.lookAt(Angles.mouseAngle(unit.x(), unit.y()));
}else{
if(!unit.vel().isZero(0.01f)) unit.rotation(unit.vel().angle());
unit.vel().add(Tmp.v2.trns(unit.rotation(), movement.len()));
if(!movement.isZero()) unit.vel().rotateTo(movement.angle(), unit.type().rotateSpeed * Time.delta());
}
unit.aim(Core.input.mouseWorld());
unit.controlWeapons(true, isShooting);
/* /*
Tile tile = unit.tileOn(); Tile tile = unit.tileOn();
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown(); boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
+1 -1
View File
@@ -25,7 +25,7 @@ public class Weapon{
/** whether to rotate toward the target independently of unit */ /** whether to rotate toward the target independently of unit */
public boolean rotate = false; public boolean rotate = false;
/** rotation speed of weapon when rotation is enabled, in degrees/t*/ /** rotation speed of weapon when rotation is enabled, in degrees/t*/
public float rotateSpeed = 2f; public float rotateSpeed = 20f;
/** weapon reload in frames */ /** weapon reload in frames */
public float reload; public float reload;
/** amount of shots per fire */ /** amount of shots per fire */
+6 -3
View File
@@ -8,6 +8,7 @@ import arc.struct.*;
import arc.util.*; import arc.util.*;
import arc.util.noise.*; import arc.util.noise.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.tools.ImagePacker.*; import mindustry.tools.ImagePacker.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.ui.*; import mindustry.ui.*;
@@ -190,9 +191,11 @@ public class Generators{
Image image = ImagePacker.get(type.region); Image image = ImagePacker.get(type.region);
image.draw(type.baseRegion); if(type.constructor.get() instanceof Legsc){
image.draw(type.legRegion); image.draw(type.baseRegion);
image.draw(type.legRegion, true, false); image.draw(type.legRegion);
image.draw(type.legRegion, true, false);
}
image.draw(type.region); image.draw(type.region);
for(Weapon weapon : type.weapons){ for(Weapon weapon : type.weapons){