mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Adds power bar and movements to boss fights in demo game
This commit is contained in:
parent
b9f9635cd8
commit
1a6300a20a
@ -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 {
|
||||
|
||||
21
examples/game/lib/power_bar.dart
Normal file
21
examples/game/lib/power_bar.dart
Normal file
@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user