Commit 59817111 authored by Viktor Lidholt's avatar Viktor Lidholt

Fixes nits

parent dec2689c
...@@ -8,6 +8,9 @@ abstract class Constraint { ...@@ -8,6 +8,9 @@ abstract class Constraint {
} }
double _dampenRotation(double src, double dst, double dampening) { double _dampenRotation(double src, double dst, double dampening) {
if (dampening == null)
return dst;
double delta = dst - src; double delta = dst - src;
while (delta > 180.0) delta -= 360; while (delta > 180.0) delta -= 360;
while (delta < -180) delta += 360; while (delta < -180) delta += 360;
...@@ -36,10 +39,7 @@ class ConstraintRotationToMovement { ...@@ -36,10 +39,7 @@ class ConstraintRotationToMovement {
Offset offset = node.position - _lastPosition; Offset offset = node.position - _lastPosition;
double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation; double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation;
if (dampening == null) node.rotation = _dampenRotation(node.rotation, target, dampening);
node.rotation = target;
else
node.rotation = _dampenRotation(node.rotation, target, dampening);
} }
} }
...@@ -62,9 +62,6 @@ class ConstraintRotationToNode { ...@@ -62,9 +62,6 @@ class ConstraintRotationToNode {
double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation; double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation;
if (dampening == null) node.rotation = _dampenRotation(node.rotation, target, dampening);
node.rotation = target;
else
node.rotation = _dampenRotation(node.rotation, target, dampening);
} }
} }
...@@ -394,7 +394,7 @@ abstract class Asteroid extends Obstacle { ...@@ -394,7 +394,7 @@ abstract class Asteroid extends Obstacle {
void setupActions() { void setupActions() {
// Rotate obstacle // Rotate obstacle
int direction = 1; int direction = 1;
if (randomDouble() < 0.5) direction = -1; if (randomBool()) direction = -1;
ActionTween rotate = new ActionTween( ActionTween rotate = new ActionTween(
(a) => _sprt.rotation = a, (a) => _sprt.rotation = a,
0.0, 360.0 * direction, 5.0 + 5.0 * randomDouble()); 0.0, 360.0 * direction, 5.0 + 5.0 * randomDouble());
...@@ -442,21 +442,25 @@ class MovingEnemy extends Obstacle { ...@@ -442,21 +442,25 @@ class MovingEnemy extends Obstacle {
final double _swirlSpacing = 80.0; final double _swirlSpacing = 80.0;
_addRandomSquare(List<Offset> offsets, double x, double y) { _addRandomSquare(List<Offset> offsets, double x, double y) {
double xMove = (randomDouble() < 0.5) ? _swirlSpacing : -_swirlSpacing; double xMove = (randomBool()) ? _swirlSpacing : -_swirlSpacing;
double yMove = (randomDouble() < 0.5) ? _swirlSpacing : -_swirlSpacing; double yMove = (randomBool()) ? _swirlSpacing : -_swirlSpacing;
if (randomDouble() < 0.5) { if (randomBool()) {
offsets.add(new Offset(x, y)); offsets.addAll([
offsets.add(new Offset(xMove + x, y)); new Offset(x, y),
offsets.add(new Offset(xMove + x, yMove + y)); new Offset(xMove + x, y),
offsets.add(new Offset(x, yMove + y)); new Offset(xMove + x, yMove + y),
offsets.add(new Offset(x, y)); new Offset(x, yMove + y),
new Offset(x, y)
]);
} else { } else {
offsets.add(new Offset(x, y)); offsets.addAll([
offsets.add(new Offset(x, y + yMove)); new Offset(x, y),
offsets.add(new Offset(xMove + x, yMove + y)); new Offset(x, y + yMove),
offsets.add(new Offset(xMove + x, y)); new Offset(xMove + x, yMove + y),
offsets.add(new Offset(x, y)); new Offset(xMove + x, y),
new Offset(x, y)
]);
} }
} }
......
...@@ -17,6 +17,10 @@ int randomInt(int max) { ...@@ -17,6 +17,10 @@ int randomInt(int max) {
return _random.nextInt(max); return _random.nextInt(max);
} }
bool randomBool() {
return _random.nextDouble() < 0.5;
}
// atan2 // atan2
class _Atan2Constants { class _Atan2Constants {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment