System for controlling bullet movement
This commit is contained in:
@@ -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);
|
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){
|
public @Nullable Bullet create(Bullet parent, float x, float y, float angle){
|
||||||
return create(parent.owner, parent.team, x, y, 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){
|
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){
|
if(spawnUnit != null){
|
||||||
//don't spawn units clientside!
|
//don't spawn units clientside!
|
||||||
if(!net.client()){
|
if(!net.client()){
|
||||||
@@ -548,6 +557,7 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
bullet.data = data;
|
bullet.data = data;
|
||||||
bullet.drag = drag;
|
bullet.drag = drag;
|
||||||
bullet.hitSize = hitSize;
|
bullet.hitSize = hitSize;
|
||||||
|
bullet.mover = mover;
|
||||||
bullet.damage = (damage < 0 ? this.damage : damage) * bullet.damageMultiplier();
|
bullet.damage = (damage < 0 ? this.damage : damage) * bullet.damageMultiplier();
|
||||||
//reset trail
|
//reset trail
|
||||||
if(bullet.trail != null){
|
if(bullet.trail != null){
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package mindustry.entities.comp;
|
|||||||
|
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.game.Teams.*;
|
import mindustry.game.Teams.*;
|
||||||
@@ -35,6 +37,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||||||
@ReadOnly
|
@ReadOnly
|
||||||
private float rotation;
|
private float rotation;
|
||||||
|
|
||||||
|
transient @Nullable Mover mover;
|
||||||
transient boolean absorbed, hit;
|
transient boolean absorbed, hit;
|
||||||
transient @Nullable Trail trail;
|
transient @Nullable Trail trail;
|
||||||
|
|
||||||
@@ -119,6 +122,12 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
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());
|
type.update(self());
|
||||||
|
|
||||||
if(type.collidesTiles && type.collides && type.collidesGround){
|
if(type.collidesTiles && type.collides && type.collidesGround){
|
||||||
|
|||||||
Reference in New Issue
Block a user