Sprite cleanup / Bullets
This commit is contained in:
@@ -12,8 +12,9 @@ public class UnitTypes implements ContentList{
|
||||
crawler, titan, fortress, eruptor, chaosArray, eradicator;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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){{
|
||||
flying = true;
|
||||
|
||||
@@ -54,16 +54,14 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
|
||||
}
|
||||
|
||||
public void each(Cons<T> cons){
|
||||
T[] items = array.items;
|
||||
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){
|
||||
T[] items = array.items;
|
||||
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.math.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
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){
|
||||
|
||||
//TODO assign type damage is damage <0, else assign provided damage
|
||||
|
||||
//TODO implement
|
||||
return null;
|
||||
/*
|
||||
Bullet bullet = Pools.obtain(Bullet.class, Bullet::new);
|
||||
bullet.type = type;
|
||||
bullet.owner = owner;
|
||||
bullet.data = data;
|
||||
|
||||
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());
|
||||
Bulletc bullet = BulletEntity.create();
|
||||
bullet.type(this);
|
||||
bullet.owner(owner);
|
||||
bullet.team(team);
|
||||
bullet.vel().trns(angle, speed * velocityScl);
|
||||
bullet.set(x - bullet.vel().x * Time.delta(), y - bullet.vel().y * Time.delta());
|
||||
bullet.lifetime(lifetime * lifetimeScl);
|
||||
bullet.data(data);
|
||||
bullet.drag(drag);
|
||||
bullet.hitSize(hitSize);
|
||||
bullet.damage(damage < 0 ? this.damage : damage);
|
||||
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){
|
||||
|
||||
@@ -11,20 +11,19 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
|
||||
private float lifeScl;
|
||||
|
||||
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc, DrawLayerBulletsc{
|
||||
Object data;
|
||||
BulletType type;
|
||||
float damage;
|
||||
|
||||
@Override
|
||||
public void drawBullets(){
|
||||
type.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(){
|
||||
type.init(this);
|
||||
|
||||
drag(type.drag);
|
||||
hitSize(type.hitSize);
|
||||
lifetime(lifeScl * type.lifetime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,11 +31,6 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
type.despawned(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLifetime(){
|
||||
return type.lifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float damageMultiplier(){
|
||||
if(owner() instanceof Unitc){
|
||||
@@ -58,7 +52,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
|
||||
@Override
|
||||
public float damage(){
|
||||
return type.damage * damageMultiplier();
|
||||
return damage * damageMultiplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ import mindustry.world.blocks.*;
|
||||
import static mindustry.Vars.net;
|
||||
|
||||
@Component
|
||||
abstract class FlyingComp implements Posc, Velc, Healthc{
|
||||
abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
|
||||
transient float x, y;
|
||||
transient Vec2 vel;
|
||||
|
||||
@@ -34,8 +34,8 @@ abstract class FlyingComp implements Posc, Velc, Healthc{
|
||||
public void update(){
|
||||
Floor floor = floorOn();
|
||||
|
||||
if(isGrounded() && floor.isLiquid && !vel.isZero(0.01f)){
|
||||
if((splashTimer += vel.len()) >= 7f){
|
||||
if(isGrounded() && floor.isLiquid){
|
||||
if((splashTimer += Mathf.dst(deltaX(), deltaY())) >= 7f){
|
||||
floor.walkEffect.at(x, y, 0, floor.color);
|
||||
splashTimer = 0f;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import mindustry.gen.*;
|
||||
abstract class TimedComp implements Entityc, Scaled{
|
||||
float time, lifetime;
|
||||
|
||||
//called last so pooling and removal happens then.
|
||||
@MethodPriority(100)
|
||||
@Override
|
||||
public void update(){
|
||||
time = Math.min(time + Time.delta(), lifetime);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
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. */
|
||||
void aim(Unitc unit, float x, float y){
|
||||
void aim(float x, float y){
|
||||
Tmp.v1.set(x, y).sub(this.x, this.y);
|
||||
if(Tmp.v1.len() < minAimDst) Tmp.v1.setLength(minAimDst);
|
||||
|
||||
@@ -49,18 +61,18 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
|
||||
Weapon weapon = mount.weapon;
|
||||
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){
|
||||
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
|
||||
//TODO only shoot if angle is reached, don't shoot inaccurately
|
||||
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);
|
||||
float shootX = mountX + Angles.trnsx(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);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ public class WeaponMount{
|
||||
public boolean side;
|
||||
/** whether to shoot right now */
|
||||
public boolean shoot = false;
|
||||
/** whether to rotate to face the target right now */
|
||||
public boolean rotate = false;
|
||||
|
||||
public WeaponMount(Weapon weapon){
|
||||
this.weapon = weapon;
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.*;
|
||||
import arc.scene.event.*;
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -495,14 +496,24 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
protected void updateMovement(Unitc unit){
|
||||
boolean canMove = !(Core.scene.getKeyboardFocus() instanceof TextField);
|
||||
|
||||
boolean omni = !(unit instanceof WaterMovec);
|
||||
float speed = unit.type().speed;
|
||||
float xa = Core.input.axis(Binding.move_x);
|
||||
float ya = Core.input.axis(Binding.move_y);
|
||||
|
||||
unit.vel().add(Tmp.v1.set(speed * xa, speed * ya).limit(speed));
|
||||
unit.lookAt(Angles.mouseAngle(unit.x(), unit.y()));
|
||||
Vec2 movement = Tmp.v1.set(speed * xa, speed * ya).limit(speed);
|
||||
|
||||
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();
|
||||
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Weapon{
|
||||
/** whether to rotate toward the target independently of unit */
|
||||
public boolean rotate = false;
|
||||
/** rotation speed of weapon when rotation is enabled, in degrees/t*/
|
||||
public float rotateSpeed = 2f;
|
||||
public float rotateSpeed = 20f;
|
||||
/** weapon reload in frames */
|
||||
public float reload;
|
||||
/** amount of shots per fire */
|
||||
|
||||
Reference in New Issue
Block a user