Commit 20809bc9 authored by Viktor Lidholt's avatar Viktor Lidholt

Merge pull request #1047 from vlidholt/master

Adds power bar and movements to boss fights in demo game
parents d0ad775e dfe80a53
......@@ -17,3 +17,17 @@ class ActionCircularMove extends ActionInterval {
setter(pos);
}
}
class ActionOscillate extends ActionInterval {
ActionOscillate(this.setter, this.center, this.radius, double duration) : super(duration);
final Function setter;
final Point center;
final double radius;
void update(double t) {
double rad = radians(t * 360.0);
Offset offset = new Offset(math.sin(rad) * radius, 0.0);
setter(center + offset);
}
}
......@@ -17,5 +17,6 @@ part 'game_demo_node.dart';
part 'game_objects.dart';
part 'game_object_factory.dart';
part 'player_state.dart';
part 'power_bar.dart';
part 'repeated_image.dart';
part 'star_field.dart';
......@@ -426,9 +426,15 @@ class EnemyBoss extends Obstacle {
maxDamage = 40.0;
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);
}
Sprite _sprt;
PowerBar _powerBar;
int _countDown = randomInt(120) + 240;
......@@ -436,18 +442,49 @@ class EnemyBoss extends Obstacle {
_countDown -= 1;
if (_countDown <= 0) {
// Shoot at player
EnemyLaser laser = new EnemyLaser(f, rotation, 5.0, new Color(0xffffe38e));
laser.position = position;
f.level.addChild(laser);
fire(10.0);
fire(0.0);
fire(-10.0);
_countDown = 60 + randomInt(120);
}
_powerBar.rotation = -rotation;
}
void fire(double r) {
r += rotation;
EnemyLaser laser = new EnemyLaser(f, r, 5.0, new Color(0xffffe38e));
double rad = radians(r);
Offset startOffset = new Offset(math.cos(rad) * 30.0, math.sin(rad) * 30.0);
laser.position = position + startOffset;
f.level.addChild(laser);
}
void setupActions() {
ActionOscillate oscillate = new ActionOscillate((a) => position = a, position, 120.0, 3.0);
actions.run(new ActionRepeatForever(oscillate));
}
void destroy() {
f.playerState.boss = null;
super.destroy();
}
set damage(double d) {
super.damage = d;
_sprt.actions.stopAll();
_sprt.actions.run(new ActionTween(
(a) =>_sprt.colorOverlay = a,
new Color.fromARGB(180, 255, 3, 86),
new Color(0x00000000),
0.3
));
_powerBar.power = (1.0 - (damage / maxDamage)).clamp(0.0, 1.0);
}
}
class Collectable extends GameObject {
......
part of game;
class PowerBar extends NodeWithSize {
PowerBar(Size size, [this.power = 1.0]) : super(size);
double power;
Paint _paintFill = new Paint()
..color = new Color(0xffffffff);
Paint _paintOutline = new Paint()
..color = new Color(0xffffffff)
..strokeWidth = 1.0
..setStyle(sky.PaintingStyle.stroke);
void paint(PaintingCanvas canvas) {
applyTransformForPivot(canvas);
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width - 0.0, size.height - 0.0), _paintOutline);
canvas.drawRect(new Rect.fromLTRB(2.0, 2.0, (size.width - 2.0) * power, size.height - 2.0), _paintFill);
}
}
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