New weapon pattern system

This commit is contained in:
Anuken
2022-02-24 20:06:52 -05:00
parent 30787e49ad
commit c3e9a961c5
24 changed files with 219 additions and 126 deletions

View File

@@ -0,0 +1,18 @@
package mindustry.entities.pattern;
public class AlternatePattern extends ShotPattern{
/** number of barrels used for shooting. */
public int barrels = 2;
/** spread between barrels, in world units - not degrees. */
public float spread = 5f;
/** offset of barrel to start on */
public int barrelOffset = 0;
@Override
public void shoot(int totalShots, BulletHandler handler){
for(int i = 0; i < shots; i++){
float index = ((totalShots + i + barrelOffset) % barrels) - (barrels-1)/2f;
handler.shoot(index * spread, 0, 0f, firstShotDelay + shotDelay * i);
}
}
}

View File

@@ -0,0 +1,25 @@
package mindustry.entities.pattern;
public class MultiPattern extends ShotPattern{
public ShotPattern source;
public ShotPattern[] dest = {};
public MultiPattern(ShotPattern source, ShotPattern... dest){
this.source = source;
this.dest = dest;
}
public MultiPattern(){
}
@Override
public void shoot(int totalShots, BulletHandler handler){
source.shoot(totalShots, (x, y, rotation, delay) -> {
for(var pattern : dest){
pattern.shoot(totalShots, (x2, y2, rot2, delay2) -> {
handler.shoot(x + x2, y + y2, rotation + rot2, delay + delay2);
});
}
});
}
}

View File

@@ -1,12 +1,28 @@
package mindustry.entities.pattern;
import arc.func.*;
import arc.math.geom.*;
//TODO
/** Handles different types of bullet patterns for shooting. */
public class ShotPattern{
/** amount of shots per "trigger pull" */
public int shots = 1;
/** delay in ticks before first shot */
public float firstShotDelay = 0;
/** delay in ticks between shots */
public float shotDelay = 0;
public void shoot(float x, float y, Cons<Vec2> positionHandler){
/** Called on a single "trigger pull". This function should call the handler with any bullets that result. */
public void shoot(int totalShots, BulletHandler handler){
for(int i = 0; i < shots; i++){
handler.shoot(0, 0, 0, firstShotDelay + shotDelay * i);
}
}
public interface BulletHandler{
/**
* @param x x offset of bullet, should be transformed by weapon rotation
* @param y y offset of bullet, should be transformed by weapon rotation
* @param rotation rotation offset relative to weapon
* @param delay bullet delay in ticks
* */
void shoot(float x, float y, float rotation, float delay);
}
}

View File

@@ -0,0 +1,26 @@
package mindustry.entities.pattern;
import arc.math.*;
public class SinePattern extends ShotPattern{
/** scaling applied to bullet index */
public float scl = 4f;
/** magnitude of sine curve for position displacement */
public float mag = 20f;
public SinePattern(float scl, float mag){
this.scl = scl;
this.mag = mag;
}
public SinePattern(){
}
@Override
public void shoot(int totalShots, BulletHandler handler){
for(int i = 0; i < shots; i++){
float angleOffset = Mathf.sin(i + totalShots, scl, mag);
handler.shoot(0, 0, angleOffset, firstShotDelay + shotDelay * i);
}
}
}

View File

@@ -0,0 +1,14 @@
package mindustry.entities.pattern;
public class SpreadPattern extends ShotPattern{
/** spread between bullets, in degrees. */
public float spread = 5f;
@Override
public void shoot(int totalShots, BulletHandler handler){
for(int i = 0; i < shots; i++){
float angleOffset = i * spread - (shots - 1) * spread / 2f;
handler.shoot(0, 0, angleOffset, firstShotDelay + shotDelay * i);
}
}
}