Skip to content
Browse files

Reworked yaw code to be give more control to the DCPU.

  • Loading branch information...
1 parent e4b55fd commit 0226ec0ced3cfa3f881e57406ec72c00bf97b80d @sticksoft committed Apr 13, 2012
Showing with 77 additions and 34 deletions.
  1. +26 −14 move.dasm
  2. +26 −14 res/raw/move.dasm
  3. +25 −6 src/uk/co/sticksoft/adce/ship2d/PlayerShip.java
View
40 move.dasm
@@ -1,25 +1,37 @@
:forward
-set [0xad00], 0x1000
+ set [0xad00], 0x1000 ; Set throttle to 0x1000 / 0x7fff
-set I, 500
+ set I, 500 ; Begin loop of 500 iterations
:loop1
-sub I, 1
-ifg I, 0
-set pc, loop1
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop1 ; Back to loop start
-set [0xad00], 0
-set [0xad02], 0xd000
+ set [0xad00], 0 ; Set throttle all stop
+ set [0xad02], 0xd000 ; Start turning to port (fire starboard thruster)
- set I, 200
+
+ set I, 200 ; Begin loop of 200 iterations
:loop2
-sub I, 1
-ifg I, 0
-set pc, loop2
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop2 ; Back to loop start
+
+
+ set [0xad02], 0x3000 ; Start turning to starboard (fire port thruster)
+
+
+ set I, 200 ; Begin loop of 200 iterations
+:loop3
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop3 ; Back to loop start
-set [0xad02], 0
+ set [0xad02], 0 ; Stop turning at all
+
-set pc, forward
+ set pc, forward ; Rinse and repeat!
:crash
-set pc, crash
+ set pc, crash
View
40 res/raw/move.dasm
@@ -1,25 +1,37 @@
:forward
-set [0xad00], 0x1000
+ set [0xad00], 0x1000 ; Set throttle to 0x1000 / 0x7fff
-set I, 500
+ set I, 500 ; Begin loop of 500 iterations
:loop1
-sub I, 1
-ifg I, 0
-set pc, loop1
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop1 ; Back to loop start
-set [0xad00], 0
-set [0xad02], 0xd000
+ set [0xad00], 0 ; Set throttle all stop
+ set [0xad02], 0xd000 ; Start turning to port (fire starboard thruster)
- set I, 200
+
+ set I, 200 ; Begin loop of 200 iterations
:loop2
-sub I, 1
-ifg I, 0
-set pc, loop2
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop2 ; Back to loop start
+
+
+ set [0xad02], 0x3000 ; Start turning to starboard (fire port thruster)
+
+
+ set I, 200 ; Begin loop of 200 iterations
+:loop3
+ sub I, 1 ; Decrement I
+ ifg I, 0 ; Check for loop end
+ set pc, loop3 ; Back to loop start
-set [0xad02], 0
+ set [0xad02], 0 ; Stop turning at all
+
-set pc, forward
+ set pc, forward ; Rinse and repeat!
:crash
-set pc, crash
+ set pc, crash
View
31 src/uk/co/sticksoft/adce/ship2d/PlayerShip.java
@@ -24,7 +24,6 @@
public Vector2 position, velocity;
public float rotation, angularMomentum;
public float hull, shields;
- public float yawFiring;
public CPU cpu;
private Bitmap bmp;
@@ -90,6 +89,7 @@ public void update(float seconds)
final float maxYawChange = 1.0f; // per second
// These are all scalar values between -1 and 1 inclusive
+ /*
yawFiring = yawControl - angularMomentum;
if (yawFiring > maxYawChange) yawFiring = maxYawChange;
else if (yawFiring < -maxYawChange) yawFiring = -maxYawChange;
@@ -99,10 +99,13 @@ public void update(float seconds)
angularMomentum = yawControl;
else
angularMomentum += yawFiring * seconds;
+ */
+
+ angularMomentum += yawControl * seconds;
rotation += angularMomentum * seconds;
- angularMomentum *= 0.99f - (0.05f * seconds);
+ //angularMomentum *= 0.99f - (0.05f * seconds);
float speed = 100.0f;
@@ -153,22 +156,22 @@ private void drawMainThruster(Canvas canvas, float w, float h)
private void drawYawThrusters(Canvas canvas, float w, float h)
{
- if (yawFiring == 0)
+ if (yawControl == 0)
return;
- if (yawFiring > 0)
+ if (yawControl > 0)
{
flamePath.reset();
flamePath.moveTo(w * 0.3f, h * -0.1f);
- flamePath.lineTo(w * 0.35f, h * -(0.3f + (0.3f + 0.3f * rand.nextFloat()) * yawFiring));
+ flamePath.lineTo(w * 0.35f, h * -(0.3f + (0.3f + 0.3f * rand.nextFloat()) * yawControl));
flamePath.lineTo(w * 0.4f, h * -0.1f);
flamePath.close();
}
else
{
flamePath.reset();
flamePath.moveTo(w * 0.3f, h * 0.1f);
- flamePath.lineTo(w * 0.35f, h * (0.3f + (0.3f + 0.3f * rand.nextFloat()) * -yawFiring));
+ flamePath.lineTo(w * 0.35f, h * (0.3f + (0.3f + 0.3f * rand.nextFloat()) * -yawControl));
flamePath.lineTo(w * 0.4f, h * 0.1f);
flamePath.close();
}
@@ -187,6 +190,10 @@ private void drawYawThrusters(Canvas canvas, float w, float h)
public final int NAVI_YAW = NAVI_START + 2;
public final int NAVI_ROLL = NAVI_START + 3;
+ public final int NAVI_PITCH_GYRO = NAVI_START + 4;
+ public final int NAVI_YAW_GYRO = NAVI_START + 5;
+ public final int NAVI_ROLL_GYRO = NAVI_START + 6;
+
public final int SENS_START = 0xAD10;
public final int SENS_CONTROL = SENS_START + 0;
public final int SENS_INDEX = SENS_START + 1;
@@ -215,16 +222,27 @@ private static float unsignedToScalar(char c)
return (float)(-0x10000 + (int)c + 1) / (float)0x7fff;
}
+ private static char scalarToUnsigned(float f)
+ {
+ if (f >= 0)
+ return (char)(0x7fff * Math.min(f,1.0f));
+ else
+ return (char)(0xffff + 0x7ffff * Math.max(f,-1.0f));
+ }
+
private ArrayList<Asteroid> blips;
private final static float RADAR_RANGE = 100.0f;
@Override
public void onCpuExecution(CPU cpu)
{
+ // Navigation
throttleControl = unsignedToScalar(cpu.RAM[NAVI_THROTTLE]);
yawControl = unsignedToScalar(cpu.RAM[NAVI_YAW]);
+ cpu.RAM[NAVI_YAW_GYRO] = scalarToUnsigned(angularMomentum);
+ // Sensors
int control = cpu.RAM[SENS_CONTROL];
if (control == 0xFFFF)
{
@@ -242,6 +260,7 @@ else if (control > 0 && control <= blips.size())
Asteroid blip = blips.get(control-1);
blip.position.sub(temp, position);
+ // Write blip data into memory
}
}
}

0 comments on commit 0226ec0

Please sign in to comment.
Something went wrong with that request. Please try again.