Skip to content

Commit a6de4d9

Browse files
committed
Replace xAccel/yAccel with just accel
1 parent 6d3c2e6 commit a6de4d9

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void arcBulletDataInit(Bullet b){
2020
ArcBulletData a = (ArcBulletData)b.data;
2121
a.zVel += zVelOffset;
2222
a.updateLifetime(b);
23-
a.xAccel = a.yAccel = 0f;
23+
a.accel = 0f;
2424
}
2525

2626
@Override

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ public void updateHoming(Bullet b){
269269

270270
b.vel.set(Tmp.v31);
271271
data.zVel = Tmp.v31.z;
272-
Tmp.v1.set(data.xAccel, data.yAccel).setAngle(b.vel.angle()); //TODO make the math take accel into account
273-
data.xAccel = Tmp.v1.x;
274-
data.yAccel = Tmp.v1.y;
275272
}
276273
}
277274
}
@@ -431,10 +428,10 @@ public Bullet create3DVel(Entityc owner, Team team, float x, float y, float z, f
431428
}
432429

433430
public Bullet create3DVel(Entityc owner, Team team, float x, float y, float z, float angle, float zVel, float gravity, float accel, float vel, float aimX, float aimY){
434-
ArcBulletData data = new ArcBulletData(z, zVel, gravity).setAccel(angle, accel);
431+
ArcBulletData data = new ArcBulletData(z, zVel, gravity).setAccel(accel);
435432

436433
Bullet bullet = beginBulletCreate(owner, team, x, y, aimX, aimY);
437-
bullet.initVel(angle, vel);
434+
bullet.initVel(angle, vel); //Non-zero so that rotation is correct
438435
if(backMove){
439436
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
440437
data.backMove(bullet);
@@ -457,8 +454,7 @@ public Bullet create3DStraight(Entityc owner, Team team, float x, float y, float
457454
Tmp.v1.set(Tmp.v31.x, Tmp.v31.y);
458455

459456
ArcBulletData data = new ArcBulletData(z, Tmp.v31.z, -Tmp.v32.z);
460-
data.xAccel = Tmp.v32.x;
461-
data.yAccel = Tmp.v32.y;
457+
data.accel = Tmp.v32.len();
462458

463459
Bullet bullet = beginBulletCreate(owner, team, x, y);
464460
bullet.vel.set(Tmp.v1);
@@ -542,7 +538,7 @@ public Bullet beginBulletCreate(Entityc owner, Team team, float x, float y){
542538
}
543539

544540
public static class ArcBulletData implements Cloneable{
545-
public float xAccel, yAccel;
541+
public float accel;
546542
public float lastZ, z, zVel, gravity;
547543
public float driftYaw, driftPitch;
548544
public ArcBulletType splitFrom;
@@ -562,7 +558,7 @@ public ArcBulletData(){
562558
}
563559

564560
public void backMove(Bullet b){
565-
b.vel.sub(xAccel * Time.delta, yAccel * Time.delta);
561+
b.vel.sub(Tmp.v1.trns(b.rotation(), accel * Time.delta));
566562
z -= zVel * Time.delta;
567563
zVel += gravity * Time.delta;
568564
}
@@ -572,25 +568,22 @@ public void updateLifetime(Bullet b){
572568
b.lifetime(PMMathf.solve(-0.5f * gravity, zVel, z) + b.time);
573569
}
574570

575-
/** Sets constant acceleration in the x and y directions based on distance to target, initial velocity, and lifetime. */
571+
/** Sets constant acceleration in based on distance to target, current velocity, and lifetime. */
576572
public void updateAccel(Bullet b){
577573
float life = b.lifetime() - b.time();
578-
//Calculate accels
579-
float dx = b.aimX - b.x;
580-
xAccel = (2 * (dx - b.vel.x * life)) / (life * life);
581-
float dy = b.aimY - b.y;
582-
yAccel = (2 * (dy - b.vel.y * life)) / (life * life);
574+
float d = Mathf.dst(b.x, b.y, b.aimX, b.aimY);
575+
accel = (2 * (d - b.vel.len() * life)) / (life * life);
583576
}
584577

585578
/** Sets the bullet's aim pos based on accel, initial velocity, and lifetime */
586579
public void updateAimPos(Bullet b){
587580
float life = b.lifetime() - b.time();
588-
b.aimX = 0.5f * xAccel * life * life + b.vel.x * life + b.x;
589-
b.aimY = 0.5f * yAccel * life * life + b.vel.y * life + b.y;
581+
b.aimX = 0.5f * xAccel(b) * life * life + b.vel.x * life + b.x;
582+
b.aimY = 0.5f * yAccel(b) * life * life + b.vel.y * life + b.y;
590583
}
591584

592585
public void update(Bullet b){
593-
b.vel.add(xAccel * Time.delta, yAccel * Time.delta);
586+
b.vel.add(Tmp.v1.trns(b.rotation(), accel * Time.delta));
594587
lastZ = z;
595588
z += zVel * Time.delta;
596589
zVel -= gravity * Time.delta;
@@ -612,12 +605,19 @@ public void update(Bullet b){
612605
if(needUpdate) updateAimPos(b);
613606
}
614607

615-
public ArcBulletData setAccel(float angle, float a){
616-
xAccel = Angles.trnsx(angle, a);
617-
yAccel = Angles.trnsy(angle, a);
608+
public ArcBulletData setAccel(float a){
609+
accel = a;
618610
return this;
619611
}
620612

613+
public float xAccel(Bullet b){
614+
return accel * Mathf.cosDeg(b.rotation());
615+
}
616+
617+
public float yAccel(Bullet b){
618+
return accel * Mathf.sinDeg(b.rotation());
619+
}
620+
621621
public ArcBulletData copy(){
622622
try{
623623
return (ArcBulletData)clone();

0 commit comments

Comments
 (0)