formatting and fixes

This commit is contained in:
Luan Nico
2018-08-28 22:13:47 -03:00
parent a40fbccf9f
commit 5a9a018f6b
6 changed files with 23 additions and 22 deletions

View File

@ -1,9 +1,7 @@
import 'dart:math' as math;
import 'sprite.dart'; import 'sprite.dart';
/// Represents a single animation frame /// Represents a single animation frame
class Frame { class Frame {
/// The [Sprite] to be displayed /// The [Sprite] to be displayed
Sprite sprite; Sprite sprite;
@ -16,7 +14,6 @@ class Frame {
/// Represents an animation, that is, a list of sprites that change with time. /// Represents an animation, that is, a list of sprites that change with time.
class Animation { class Animation {
/// The frames that compose this animation. /// The frames that compose this animation.
List<Frame> frames = []; List<Frame> frames = [];
@ -27,7 +24,7 @@ class Animation {
/// ///
/// It's ticked by the update method. It's reset every frame change. /// It's ticked by the update method. It's reset every frame change.
double clock = 0.0; double clock = 0.0;
/// Wether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done. /// Wether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done.
bool loop = true; bool loop = true;
@ -109,7 +106,7 @@ class Animation {
/// Sets a different step time to each frame. The sizes of the arrays must match. /// Sets a different step time to each frame. The sizes of the arrays must match.
void set variableStepTimes(List<double> stepTimes) { void set variableStepTimes(List<double> stepTimes) {
assert (stepTimes.length == frames.length); assert(stepTimes.length == frames.length);
for (int i = 0; i < frames.length; i++) { for (int i = 0; i < frames.length; i++) {
frames[i].stepTime = stepTimes[i]; frames[i].stepTime = stepTimes[i];
} }

View File

@ -7,7 +7,6 @@ import 'package:synchronized/synchronized.dart';
typedef void Stoppable(); typedef void Stoppable();
class AudioPool { class AudioPool {
AudioCache cache; AudioCache cache;
Map<String, AudioPlayer> currentPlayers = {}; Map<String, AudioPlayer> currentPlayers = {};
List<AudioPlayer> availablePlayers = []; List<AudioPlayer> availablePlayers = [];
@ -18,7 +17,11 @@ class AudioPool {
Lock _lock = new Lock(); Lock _lock = new Lock();
AudioPool(this.sound, { this.repeating = false, this.maxPlayers = 1, this.minPlayers = 1, String prefix = 'audio/sfx/' }) { AudioPool(this.sound,
{this.repeating = false,
this.maxPlayers = 1,
this.minPlayers = 1,
String prefix = 'audio/sfx/'}) {
cache = new AudioCache(prefix: prefix); cache = new AudioCache(prefix: prefix);
} }
@ -28,7 +31,7 @@ class AudioPool {
} }
} }
Future<Stoppable> start({ double volume = 1.0 }) async { Future<Stoppable> start({double volume = 1.0}) async {
return _lock.synchronized(() async { return _lock.synchronized(() async {
if (availablePlayers.isEmpty) { if (availablePlayers.isEmpty) {
availablePlayers.add(await _createNewAudioPlayer()); availablePlayers.add(await _createNewAudioPlayer());

View File

@ -17,7 +17,6 @@ export 'gamepad.dart';
/// You can access shared instances of [AudioCache], [Images] and [Util]. /// You can access shared instances of [AudioCache], [Images] and [Util].
/// Most games should need only one instance of each, and should use this class to manage that reference. /// Most games should need only one instance of each, and should use this class to manage that reference.
class Flame { class Flame {
/// Access a shared instance of the [AudioCache] class. /// Access a shared instance of the [AudioCache] class.
static AudioCache audio = new AudioCache(prefix: 'audio/'); static AudioCache audio = new AudioCache(prefix: 'audio/');

View File

@ -154,7 +154,8 @@ class _GameRenderBox extends RenderBox with WidgetsBindingObserver {
/// It is based on the Component system. /// It is based on the Component system.
abstract class BaseGame extends Game { abstract class BaseGame extends Game {
/// The list of components to be updated and rendered by the base game. /// The list of components to be updated and rendered by the base game.
OrderedSet<Component> components = new OrderedSet(Comparing.on((c) => c.priority())); OrderedSet<Component> components =
new OrderedSet(Comparing.on((c) => c.priority()));
/// Components added by the [addLater] method /// Components added by the [addLater] method
List<Component> _addLater = []; List<Component> _addLater = [];

View File

@ -1,7 +1,7 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
typedef void KeyListener (RawKeyEvent event); typedef void KeyListener(RawKeyEvent event);
typedef void GamepadListener (String evtType, String key); typedef void GamepadListener(String evtType, String key);
const GAMEPAD_BUTTON_UP = "UP"; const GAMEPAD_BUTTON_UP = "UP";
const GAMEPAD_BUTTON_DOWN = "DOWN"; const GAMEPAD_BUTTON_DOWN = "DOWN";
@ -26,13 +26,13 @@ const GAMEPAD_BUTTON_START = "START";
const GAMEPAD_BUTTON_SELECT = "SELECT"; const GAMEPAD_BUTTON_SELECT = "SELECT";
const ANDROID_MAPPING = { const ANDROID_MAPPING = {
19: GAMEPAD_DPAD_UP, 19: GAMEPAD_DPAD_UP,
20: GAMEPAD_DPAD_DOWN, 20: GAMEPAD_DPAD_DOWN,
21: GAMEPAD_DPAD_LEFT, 21: GAMEPAD_DPAD_LEFT,
22: GAMEPAD_DPAD_RIGHT, 22: GAMEPAD_DPAD_RIGHT,
96: GAMEPAD_BUTTON_A, 96: GAMEPAD_BUTTON_A,
97: GAMEPAD_BUTTON_B, 97: GAMEPAD_BUTTON_B,
99: GAMEPAD_BUTTON_X, 99: GAMEPAD_BUTTON_X,
100: GAMEPAD_BUTTON_Y, 100: GAMEPAD_BUTTON_Y,
102: GAMEPAD_BUTTON_L1, 102: GAMEPAD_BUTTON_L1,
103: GAMEPAD_BUTTON_R1, 103: GAMEPAD_BUTTON_R1,
@ -46,12 +46,12 @@ const ANDROID_MAPPING = {
/// ///
/// To use this class, access it via [Flame.gamepad]. /// To use this class, access it via [Flame.gamepad].
class Gamepad { class Gamepad {
KeyListener listener; KeyListener listener;
void addListener(GamepadListener gamepadListener) { void addListener(GamepadListener gamepadListener) {
this.listener = (RawKeyEvent e) { this.listener = (RawKeyEvent e) {
String evtType = e is RawKeyDownEvent ? GAMEPAD_BUTTON_DOWN : GAMEPAD_BUTTON_UP; String evtType =
e is RawKeyDownEvent ? GAMEPAD_BUTTON_DOWN : GAMEPAD_BUTTON_UP;
if (e.data is RawKeyEventDataAndroid) { if (e.data is RawKeyEventDataAndroid) {
RawKeyEventDataAndroid androidEvent = e.data as RawKeyEventDataAndroid; RawKeyEventDataAndroid androidEvent = e.data as RawKeyEventDataAndroid;

View File

@ -114,6 +114,7 @@ class Sprite {
return; return;
} }
size ??= this.size; size ??= this.size;
renderRect(canvas, new Rect.fromLTWH(p.x - size.x/2, p.y - size.y/2, size.x, size.y)); renderRect(canvas,
new Rect.fromLTWH(p.x - size.x / 2, p.y - size.y / 2, size.x, size.y));
} }
} }