System for controlling bullet movement
This commit is contained in:
9
core/src/mindustry/entities/Mover.java
Normal file
9
core/src/mindustry/entities/Mover.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package mindustry.entities;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
/** Applies custom movement to a bullet. */
|
||||
public interface Mover{
|
||||
float move(Bullet bullet);
|
||||
}
|
||||
@@ -501,6 +501,11 @@ public class BulletType extends Content implements Cloneable{
|
||||
return create(owner, team, x, y, angle, -1, velocityScl, lifetimeScl, null);
|
||||
}
|
||||
|
||||
|
||||
public @Nullable Bullet create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Mover mover){
|
||||
return create(owner, team, x, y, angle, -1, velocityScl, lifetimeScl, null, mover);
|
||||
}
|
||||
|
||||
public @Nullable Bullet create(Bullet parent, float x, float y, float angle){
|
||||
return create(parent.owner, parent.team, x, y, angle);
|
||||
}
|
||||
@@ -514,6 +519,10 @@ public class BulletType extends Content implements Cloneable{
|
||||
}
|
||||
|
||||
public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data){
|
||||
return create(owner, team, x, y, angle, damage, velocityScl, lifetimeScl, data, null);
|
||||
}
|
||||
|
||||
public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover){
|
||||
if(spawnUnit != null){
|
||||
//don't spawn units clientside!
|
||||
if(!net.client()){
|
||||
@@ -548,6 +557,7 @@ public class BulletType extends Content implements Cloneable{
|
||||
bullet.data = data;
|
||||
bullet.drag = drag;
|
||||
bullet.hitSize = hitSize;
|
||||
bullet.mover = mover;
|
||||
bullet.damage = (damage < 0 ? this.damage : damage) * bullet.damageMultiplier();
|
||||
//reset trail
|
||||
if(bullet.trail != null){
|
||||
|
||||
@@ -2,12 +2,14 @@ package mindustry.entities.comp;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.game.Teams.*;
|
||||
@@ -35,6 +37,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
@ReadOnly
|
||||
private float rotation;
|
||||
|
||||
transient @Nullable Mover mover;
|
||||
transient boolean absorbed, hit;
|
||||
transient @Nullable Trail trail;
|
||||
|
||||
@@ -119,6 +122,12 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(mover != null){
|
||||
float v = mover.move(self()) * Time.delta;
|
||||
float ang = vel.angle();
|
||||
vel.add(Angles.trnsx(ang, 0f, v), Angles.trnsy(ang, 0f, v)).limit(type.speed);
|
||||
}
|
||||
|
||||
type.update(self());
|
||||
|
||||
if(type.collidesTiles && type.collides && type.collidesGround){
|
||||
|
||||
Reference in New Issue
Block a user