Skip to content

Commit c8f8d93

Browse files
committed
Re-implement independent x and y accel
1 parent 0243182 commit c8f8d93

File tree

7 files changed

+259
-148
lines changed

7 files changed

+259
-148
lines changed

src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java

+1-97
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
import arc.graphics.g2d.*;
55
import arc.math.*;
66
import arc.util.*;
7-
import mindustry.entities.bullet.*;
87
import mindustry.gen.*;
98
import progressed.graphics.*;
10-
import progressed.util.*;
119

1210
import static progressed.graphics.Draw3D.*;
1311

14-
public class ArcBasicBulletType extends ArcBulletType{
12+
public abstract class ArcBasicBulletType extends ArcBulletType{
1513
public String sprite;
1614
public boolean bloomSprite = true;
1715
public boolean drawShadow = false, spinShade = true;
@@ -43,16 +41,6 @@ public void load(){
4341
shadowRegion = Core.atlas.find(sprite + "-shadow", region);
4442
}
4543

46-
@Override
47-
public ArcBulletData createData(){
48-
return new BasicArcBulletData();
49-
}
50-
51-
@Override
52-
public ArcBulletData createData(float z, float zVel, float gravity){
53-
return new BasicArcBulletData(z, zVel, gravity);
54-
}
55-
5644
@Override
5745
public void draw(Bullet b){
5846
drawTargetZone(b);
@@ -101,88 +89,4 @@ public void draw(Bullet b){
10189

10290
drawHomingDebug(b);
10391
}
104-
105-
public static class BasicArcBulletData extends ArcBulletData{
106-
public float accel;
107-
108-
public BasicArcBulletData(float z, float zVel, float gravity){
109-
super(z, zVel, gravity);
110-
}
111-
112-
public BasicArcBulletData(){
113-
super();
114-
}
115-
116-
@Override
117-
public void backMove(Bullet b){
118-
float vSub = accel * Time.delta;
119-
if(vSub > b.vel.len()){
120-
b.vel.setLength(0); //Prevent rotation from being reversed
121-
}else{
122-
b.vel.sub(Tmp.v1.trns(b.rotation(), vSub));
123-
}
124-
125-
super.backMove(b);
126-
}
127-
128-
@Override
129-
public void updateAccel(Bullet b){
130-
float life = b.lifetime() - b.time();
131-
float d = Mathf.dst(b.x, b.y, b.aimX, b.aimY);
132-
accel = (2 * (d - b.vel.len() * life)) / (life * life);
133-
}
134-
135-
@Override
136-
public void update(Bullet b){
137-
b.vel.add(Tmp.v1.trns(b.rotation(), accel * Time.delta));
138-
super.update(b);
139-
}
140-
141-
@Override
142-
public void updateHoming(Bullet b, Teamc target){
143-
BulletType type = b.type;
144-
145-
Tmp.v31.set(b.vel, zVel); //Current velocity
146-
147-
float v2 = Tmp.v31.len();
148-
float pitch = Math3D.homingPitch(b.x, b.y, z, target.x(), target.y(), v2, accel, gravity); //Find target pitch between -pi/2 and pi/2
149-
150-
float polar = Mathf.pi - (pitch + Mathf.halfPi); //0 = up, pi - down. Convert -pi/2-pi/2 -> pi-0
151-
152-
Tmp.v32.setFromSpherical(b.angleTo(target) * Mathf.degRad, polar).setLength2(v2); //Target velocity
153-
154-
float angle = (float)Math.acos(Tmp.v31.dot(Tmp.v32) / v2) * Mathf.radDeg;
155-
156-
float h = type.homingPower * Time.delta;
157-
if(angle <= h){
158-
Tmp.v31.set(Tmp.v32);
159-
}else{
160-
//idk what I'm doing, but https://stackoverflow.com/questions/22099490/calculate-vector-after-rotating-it-towards-another-by-angle-θ-in-3d-space
161-
Tmp.v33.set(Tmp.v31).crs(Tmp.v32).crs(Tmp.v31).nor();
162-
163-
float c = Mathf.cosDeg(h);
164-
float s = Mathf.sinDeg(h);
165-
Tmp.v31.scl(c).add(Tmp.v33.scl(s));
166-
}
167-
168-
b.vel.set(Tmp.v31);
169-
zVel = Tmp.v31.z;
170-
}
171-
172-
@Override
173-
public ArcBulletData setAccel(float a){
174-
accel = a;
175-
return this;
176-
}
177-
178-
@Override
179-
public float xAccel(Bullet b){
180-
return accel * Mathf.cosDeg(b.rotation());
181-
}
182-
183-
@Override
184-
public float yAccel(Bullet b){
185-
return accel * Mathf.sinDeg(b.rotation());
186-
}
187-
}
18892
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package progressed.entities.bullet.pseudo3d;
2+
3+
import arc.util.*;
4+
import mindustry.entities.bullet.*;
5+
import mindustry.game.*;
6+
import mindustry.gen.*;
7+
import progressed.util.*;
8+
9+
public class ArcBoltBulletType extends ArcBasicBulletType{
10+
public ArcBoltBulletType(float speed, float damage, String sprite){
11+
super(speed, damage, sprite);
12+
}
13+
14+
public ArcBoltBulletType(float speed, float damage){
15+
this(speed, damage, "bullet");
16+
17+
spinShade = drawZone = drawTarget = drawProgress = false;
18+
}
19+
20+
public ArcBoltBulletType(float speed){
21+
this(speed, 0f);
22+
}
23+
24+
@Override
25+
public ArcBulletData createData(){
26+
return new ArcBoltData();
27+
}
28+
29+
@Override
30+
public ArcBulletData createData(float z, float zVel, float gravity){
31+
return new ArcBoltData(z, zVel, gravity);
32+
}
33+
34+
/** Assuming accel and gravity stay constant, the bullet travels in a straight trajectory, */
35+
public Bullet create3DStraight(Entityc owner, Team team, float x, float y, float z, float angle, float tilt, float vel, float accel){
36+
Math3D.rotate(Tmp.v31, vel, angle, 0f, tilt);
37+
Math3D.rotate(Tmp.v32, accel, angle, 0f, tilt);
38+
Tmp.v1.set(Tmp.v31.x, Tmp.v31.y);
39+
40+
ArcBoltData data = new ArcBoltData(z, Tmp.v31.z, -Tmp.v32.z);
41+
data.xAccel = Tmp.v32.x;
42+
data.yAccel = Tmp.v32.y;
43+
44+
Bullet bullet = beginBulletCreate(owner, team, x, y);
45+
bullet.vel.set(Tmp.v1);
46+
bullet.rotation(Tmp.v1.angle());
47+
if(backMove){
48+
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
49+
data.backMove(bullet);
50+
}else{
51+
bullet.set(x, y);
52+
}
53+
bullet.data = data;
54+
bullet.drag = drag;
55+
bullet.hitSize = hitSize;
56+
if(bullet.trail != null){
57+
bullet.trail.clear();
58+
}
59+
data.updateLifetime(bullet);
60+
data.updateAimPos(bullet);
61+
bullet.add();
62+
return bullet;
63+
}
64+
65+
public static class ArcBoltData extends ArcBulletData{
66+
public float xAccel, yAccel;
67+
68+
public ArcBoltData(float z, float zVel, float gravity){
69+
super(z, zVel, gravity);
70+
}
71+
72+
public ArcBoltData(float z, float zVel){
73+
this(z, zVel, 1f);
74+
}
75+
76+
public ArcBoltData(){
77+
this(0, 0);
78+
}
79+
80+
@Override
81+
public void backMove(Bullet b){
82+
b.vel.sub(xAccel * Time.delta, yAccel * Time.delta);
83+
super.backMove(b);
84+
}
85+
86+
@Override
87+
public void updateAccel(Bullet b){
88+
float life = b.lifetime() - b.time();
89+
//Calculate accels
90+
float dx = b.aimX - b.x;
91+
xAccel = (2 * (dx - b.vel.x * life)) / (life * life);
92+
float dy = b.aimY - b.y;
93+
yAccel = (2 * (dy - b.vel.y * life)) / (life * life);
94+
}
95+
96+
@Override
97+
public void updateHoming(Bullet b, Teamc target){
98+
BulletType type = b.type;
99+
100+
Tmp.v1.set(b.aimX, b.aimY).approachDelta(Tmp.v2.set(target), type.homingPower);
101+
b.aimX = Tmp.v1.x;
102+
b.aimY = Tmp.v1.y;
103+
updateAccel(b);
104+
}
105+
106+
@Override
107+
public void update(Bullet b){
108+
b.vel.add(xAccel * Time.delta, yAccel * Time.delta);
109+
super.update(b);
110+
}
111+
112+
@Override
113+
public ArcBulletData setAccel(float a){
114+
Tmp.v1.set(xAccel, yAccel).setLength(a);
115+
xAccel = Tmp.v1.x;
116+
yAccel = Tmp.v1.y;
117+
return this;
118+
}
119+
120+
@Override
121+
public float xAccel(Bullet b){
122+
return xAccel;
123+
}
124+
125+
@Override
126+
public float yAccel(Bullet b){
127+
return yAccel;
128+
}
129+
}
130+
}

src/progressed/entities/bullet/pseudo3d/ArcBulletType.java

+18-42
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class ArcBulletType extends BulletType{
3535

3636
public boolean bloomTrail = true;
3737

38-
public boolean drawZone = false;
38+
public boolean drawZone = false, drawTarget = true, drawProgress = true;
3939
public float zoneLayer = Layer.bullet;
4040
public float targetRadius = 12f, zoneRadius = 3f * 8f, progressRadius = -1f;
4141
public float spikesWidth1 = -1f, spikesLength1 = -1f;
@@ -307,19 +307,24 @@ public void drawTargetZone(Bullet b){
307307
}
308308
}
309309

310-
float fin = b.fin() / lifetimeScl;
311-
float pR = split ? Mathf.lerp(splitFrom.progressRadius, progressRadius, grow) * fout : progressRadius * scl;
312-
PMDrawf.progressRing(x, y, pR, pR + 4f, fin);
313-
314-
float tR = split ? Mathf.lerp(splitFrom.targetRadius, targetRadius, grow) * fout : targetRadius * scl,
315-
sW = split ? Mathf.lerp(splitFrom.spokeWidth, spokeWidth, grow) * fout : spokeWidth * scl,
316-
sL = split ? Mathf.lerp(splitFrom.spokeLength, spokeLength, grow) * fout : spokeLength * scl;
317-
PMDrawf.ring(x, y, tR, tR + 2);
318-
Lines.stroke(sW);
319-
for(int i = 0; i < 4; i++){
320-
float a = -ang + 90 * i;
321-
Lines.lineAngleCenter(x + Angles.trnsx(a, tR), y + Angles.trnsy(a, tR), a, sL, false);
310+
if(drawProgress){
311+
float fin = b.fin() / lifetimeScl;
312+
float pR = split ? Mathf.lerp(splitFrom.progressRadius, progressRadius, grow) * fout : progressRadius * scl;
313+
PMDrawf.progressRing(x, y, pR, pR + 4f, fin);
322314
}
315+
316+
if(drawTarget){
317+
float tR = split ? Mathf.lerp(splitFrom.targetRadius, targetRadius, grow) * fout : targetRadius * scl,
318+
sW = split ? Mathf.lerp(splitFrom.spokeWidth, spokeWidth, grow) * fout : spokeWidth * scl,
319+
sL = split ? Mathf.lerp(splitFrom.spokeLength, spokeLength, grow) * fout : spokeLength * scl;
320+
PMDrawf.ring(x, y, tR, tR + 2);
321+
Lines.stroke(sW);
322+
for(int i = 0; i < 4; i++){
323+
float a = -ang + 90 * i;
324+
Lines.lineAngleCenter(x + Angles.trnsx(a, tR), y + Angles.trnsy(a, tR), a, sL, false);
325+
}
326+
}
327+
323328
Draw.color();
324329
}
325330

@@ -418,35 +423,6 @@ public Bullet create3DVel(Entityc owner, Team team, float x, float y, float z, f
418423
return bullet;
419424
}
420425

421-
public Bullet create3DStraight(Entityc owner, Team team, float x, float y, float z, float angle, float tilt, float vel, float accel){
422-
Math3D.rotate(Tmp.v31, vel, angle, 0f, tilt);
423-
Math3D.rotate(Tmp.v32, accel, angle, 0f, tilt);
424-
Tmp.v1.set(Tmp.v31.x, Tmp.v31.y);
425-
426-
ArcBulletData data = createData(z, Tmp.v31.z, -Tmp.v32.z);
427-
data.setAccel(Tmp.v32.len());
428-
429-
Bullet bullet = beginBulletCreate(owner, team, x, y);
430-
bullet.vel.set(Tmp.v1);
431-
bullet.rotation(Tmp.v1.angle());
432-
if(backMove){
433-
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
434-
data.backMove(bullet);
435-
}else{
436-
bullet.set(x, y);
437-
}
438-
bullet.data = data;
439-
bullet.drag = drag;
440-
bullet.hitSize = hitSize;
441-
if(bullet.trail != null){
442-
bullet.trail.clear();
443-
}
444-
data.updateLifetime(bullet);
445-
data.updateAimPos(bullet);
446-
bullet.add();
447-
return bullet;
448-
}
449-
450426
public Bullet create3DInherit(Bullet b, float angle, float inaccCone){
451427
return create3DInherit(b, angle, inaccCone, gravity);
452428
}

0 commit comments

Comments
 (0)