Commit d1a56611 authored by Viktor Lidholt's avatar Viktor Lidholt

Merge pull request #1050 from vlidholt/master

Demo game improvements
parents 7d11cfa4 eb3f30ab
......@@ -426,9 +426,13 @@ class EnemyBoss extends Obstacle {
constraints = [new ConstraintRotationToNode(f.level.ship, dampening: 0.05)];
_powerBar = new PowerBar(new Size(60.0, 10.0));
_powerBar.position = new Point(-80.0, 0.0);
_powerBar.pivot = new Point(0.5, 0.5);
addChild(_powerBar);
f.level.addChild(_powerBar);
_powerBar.constraints = [new ConstraintPositionToNode(
this,
dampening: 0.5,
offset: new Offset(0.0, -70.0)
)];
}
Sprite _sprt;
......@@ -446,8 +450,6 @@ class EnemyBoss extends Obstacle {
_countDown = 60 + randomInt(120);
}
_powerBar.rotation = -rotation;
}
void fire(double r) {
......@@ -468,7 +470,27 @@ class EnemyBoss extends Obstacle {
void destroy() {
f.playerState.boss = null;
_powerBar.removeFromParent();
// Flash the screen
NodeWithSize screen = f.playerState.parent;
screen.addChild(new Flash(screen.size, 1.0));
super.destroy();
// Add coins
for (int i = 0; i < 20; i++) {
Coin coin = new Coin(f);
Point pos = new Point(
randomSignedDouble() * 160,
position.y + randomSignedDouble() * 160.0);
f.addGameObject(coin, pos);
}
}
Explosion createExplosion() {
ExplosionBig explo = new ExplosionBig(f.sheet);
explo.scale = 1.5;
return explo;
}
set damage(double d) {
......
......@@ -70,3 +70,34 @@ class ConstraintRotationToNode extends Constraint {
node.rotation = _dampenRotation(node.rotation, target, dampening);
}
}
class ConstraintPositionToNode extends Constraint {
ConstraintPositionToNode(this.targetNode, {this.dampening, this.offset: Offset.zero});
final Node targetNode;
final Offset offset;
final double dampening;
void constrain(Node node, double dt) {
Point targetPosition;
if (targetNode.spriteBox != node.spriteBox || node.parent == null) {
// The target node is in another sprite box or has been removed
return;
}
if (targetNode.parent == node.parent) {
targetPosition = targetNode.position;
} else {
targetPosition = node.parent.convertPointFromNode(Point.origin, targetNode);
}
if (offset != null)
targetPosition += offset;
if (dampening == null)
node.position = targetPosition;
else
node.position = GameMath.filterPoint(node.position, targetPosition, dampening);
}
}
......@@ -101,4 +101,8 @@ class GameMath {
static double filter (double a, double b, double filterFactor) {
return (a * (1-filterFactor)) + b * filterFactor;
}
static Point filterPoint(Point a, Point b, double filterFactor) {
return new Point(filter(a.x, b.x, filterFactor), filter(a.y, b.y, filterFactor));
}
}
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