New weapon pattern system
This commit is contained in:
18
core/src/mindustry/entities/pattern/AlternatePattern.java
Normal file
18
core/src/mindustry/entities/pattern/AlternatePattern.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
core/src/mindustry/entities/pattern/MultiPattern.java
Normal file
25
core/src/mindustry/entities/pattern/MultiPattern.java
Normal 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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
26
core/src/mindustry/entities/pattern/SinePattern.java
Normal file
26
core/src/mindustry/entities/pattern/SinePattern.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
core/src/mindustry/entities/pattern/SpreadPattern.java
Normal file
14
core/src/mindustry/entities/pattern/SpreadPattern.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user