Sprite cleanup / Bullets
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user