diff --git a/lib/animation.dart b/lib/animation.dart index a105a50bb..bf27414b6 100644 --- a/lib/animation.dart +++ b/lib/animation.dart @@ -41,7 +41,7 @@ class Animation { /// /// All frames have the same [stepTime]. Animation.spriteList(List sprites, {double stepTime, this.loop}) { - this.frames = sprites.map((s) => Frame(s, stepTime)).toList(); + frames = sprites.map((s) => Frame(s, stepTime)).toList(); } /// Creates an animation given a list of frames. @@ -68,7 +68,7 @@ class Animation { double textureHeight, double stepTime = 0.1, }) { - this.frames = List(amount); + frames = List(amount); for (var i = 0; i < amount; i++) { Sprite sprite = Sprite( imagePath, @@ -77,7 +77,7 @@ class Animation { width: textureWidth, height: textureHeight, ); - this.frames[i] = Frame(sprite, stepTime); + frames[i] = Frame(sprite, stepTime); } } @@ -91,7 +91,7 @@ class Animation { double textureWidth, double textureHeight, }) { - this.frames = List(amount); + frames = List(amount); for (var i = 0; i < amount; i++) { Sprite sprite = Sprite( imagePath, @@ -100,7 +100,7 @@ class Animation { width: textureWidth, height: textureHeight, ); - this.frames[i] = Frame(sprite, stepTimes[i]); + frames[i] = Frame(sprite, stepTimes[i]); } } @@ -155,14 +155,14 @@ class Animation { /// Sets a fixed step time to all frames. void set stepTime(double stepTime) { - this.frames.forEach((frame) => frame.stepTime = stepTime); + frames.forEach((frame) => frame.stepTime = stepTime); } /// Resets the animation, like it'd just been created. void reset() { - this.clock = 0.0; - this.elapsed = 0.0; - this.currentIndex = 0; + clock = 0.0; + elapsed = 0.0; + currentIndex = 0; } /// Gets tha current [Sprite] that should be shown. diff --git a/lib/box2d/box2d_component.dart b/lib/box2d/box2d_component.dart index fa857f79c..8dd0b4e89 100644 --- a/lib/box2d/box2d_component.dart +++ b/lib/box2d/box2d_component.dart @@ -29,12 +29,12 @@ abstract class Box2DComponent extends Component { this.positionIterations: DEFAULT_POSITION_ITERATIONS, double scale: DEFAULT_SCALE, }) { - if (this.dimensions == null) { - this.dimensions = window.physicalSize; + if (dimensions == null) { + dimensions = window.physicalSize; } final pool = DefaultWorldPool(worldPoolSize, worldPoolContainerSize); - this.world = World.withPool(Vector2(0.0, gravity), pool); - this.viewport = Viewport(dimensions, scale); + world = World.withPool(Vector2(0.0, gravity), pool); + viewport = Viewport(dimensions, scale); } @override @@ -47,7 +47,7 @@ abstract class Box2DComponent extends Component { @override void render(canvas) { - if (viewport.size == Size(0.0, 0.0)) { + if (viewport.size == Size.zero) { return; } components.forEach((c) { @@ -134,7 +134,7 @@ abstract class BodyComponent extends Component { } } - Vector2 get center => this.body.worldCenter; + Vector2 get center => body.worldCenter; void _renderCircle(Canvas canvas, Fixture fixture) { Vector2 center = Vector2.zero(); diff --git a/lib/box2d/viewport.dart b/lib/box2d/viewport.dart index f1248447e..7fff22d83 100644 --- a/lib/box2d/viewport.dart +++ b/lib/box2d/viewport.dart @@ -17,8 +17,8 @@ class Viewport extends ViewportTransform { /// Resizes the current view port. void resize(Size size) { this.size = size; - this.extents = Vector2.copy(Vector2(size.width / 2, size.height / 2)); - this.center = Vector2.copy(Vector2(size.width / 2, size.height / 2)); + extents = Vector2.copy(Vector2(size.width / 2, size.height / 2)); + center = Vector2.copy(Vector2(size.width / 2, size.height / 2)); } /// Computes the number of horizontal world meters of this viewport considering a percentage of its width. diff --git a/lib/components/animation_component.dart b/lib/components/animation_component.dart index aa5d9f9db..b4301a5ce 100644 --- a/lib/components/animation_component.dart +++ b/lib/components/animation_component.dart @@ -25,7 +25,7 @@ class AnimationComponent extends PositionComponent { }) { this.width = width; this.height = height; - this.animation = Animation.sequenced( + animation = Animation.sequenced( imagePath, amount, textureX: textureX, diff --git a/lib/components/component.dart b/lib/components/component.dart index 9901ea574..810c05e7a 100644 --- a/lib/components/component.dart +++ b/lib/components/component.dart @@ -65,30 +65,30 @@ abstract class PositionComponent extends Component { Position toPosition() => Position(x, y); void setByPosition(Position position) { - this.x = position.x; - this.y = position.y; + x = position.x; + y = position.y; } Position toSize() => Position(width, height); void setBySize(Position size) { - this.width = size.x; - this.height = size.y; + width = size.x; + height = size.y; } Rect toRect() => Rect.fromLTWH(x, y, width, height); void setByRect(Rect rect) { - this.x = rect.left; - this.y = rect.top; - this.width = rect.width; - this.height = rect.height; + x = rect.left; + y = rect.top; + width = rect.width; + height = rect.height; } double angleBetween(PositionComponent c) { - return (atan2(c.x - this.x, this.y - c.y) - pi / 2) % (2 * pi); + return (atan2(c.x - x, y - c.y) - pi / 2) % (2 * pi); } double distance(PositionComponent c) { - return sqrt(pow(this.y - c.y, 2) + pow(this.x - c.x, 2)); + return sqrt(pow(y - c.y, 2) + pow(x - c.x, 2)); } void prepareCanvas(Canvas canvas) { diff --git a/lib/components/composed_component.dart b/lib/components/composed_component.dart index 5626fd5d8..53fc417a0 100644 --- a/lib/components/composed_component.dart +++ b/lib/components/composed_component.dart @@ -56,7 +56,7 @@ mixin ComposedComponent on Component { } void add(Component c) { - this.components.add(c); + components.add(c); if (this is Resizable) { // first time resize @@ -68,5 +68,5 @@ mixin ComposedComponent on Component { } List children() => - this.components.where((r) => r is Resizable).cast().toList(); + components.where((r) => r is Resizable).cast().toList(); } diff --git a/lib/components/parallax_component.dart b/lib/components/parallax_component.dart index 2004d93c6..cc094b2fc 100644 --- a/lib/components/parallax_component.dart +++ b/lib/components/parallax_component.dart @@ -57,7 +57,7 @@ abstract class ParallaxComponent extends PositionComponent { @override void resize(Size size) { - this._size = size; + _size = size; } /// Loads the images defined by this list of filenames. All images are positioned at its scroll center. @@ -103,7 +103,7 @@ abstract class ParallaxComponent extends PositionComponent { @override void update(double delta) { - if (!this.loaded()) { + if (!loaded()) { return; } for (int i = 0; i < _layers.length; i++) { diff --git a/lib/components/text_component.dart b/lib/components/text_component.dart index 264c3d583..e8ebfed3f 100644 --- a/lib/components/text_component.dart +++ b/lib/components/text_component.dart @@ -25,14 +25,14 @@ class TextComponent extends PositionComponent { } TextComponent(this._text, {TextConfig config = const TextConfig()}) { - this._config = config; + _config = config; _updateBox(); } void _updateBox() { TextPainter tp = config.toTextPainter(text); - this.width = tp.width; - this.height = tp.height; + width = tp.width; + height = tp.height; } @override diff --git a/lib/components/tiled_component.dart b/lib/components/tiled_component.dart index 522b4581d..0b5de2413 100644 --- a/lib/components/tiled_component.dart +++ b/lib/components/tiled_component.dart @@ -17,14 +17,14 @@ class TiledComponent extends Component { static Paint paint = Paint()..color = Colors.white; TiledComponent(this.filename) { - this.future = _load(); + future = _load(); } Future _load() async { - this.map = await _loadMap(); - this.image = await Flame.images.load(map.tilesets[0].image.source); - this.images = await _loadImages(map); - this._loaded = true; + map = await _loadMap(); + image = await Flame.images.load(map.tilesets[0].image.source); + images = await _loadImages(map); + _loaded = true; } Future _loadMap() { diff --git a/lib/game.dart b/lib/game.dart index a7522e815..10701ba42 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -61,7 +61,7 @@ class _GameRenderObjectWidget extends SingleChildRenderObjectWidget { @override RenderObject createRenderObject(BuildContext context) => - _GameRenderBox(context, this.game); + _GameRenderBox(context, game); @override void updateRenderObject(BuildContext context, _GameRenderBox _gameRenderBox) { @@ -193,8 +193,8 @@ abstract class BaseGame extends Game { /// /// Also calls [preAdd], witch in turn sets the current size on the component (because the resize hook won't be called until a new resize happens). void add(Component c) { - this.preAdd(c); - this.components.add(c); + preAdd(c); + components.add(c); } /// Registers a component to be added on the components on the next tick. @@ -202,8 +202,8 @@ abstract class BaseGame extends Game { /// Use this to add components in places where a concurrent issue with the update method might happen. /// Also calls [preAdd] for the component added, immediately. void addLater(Component c) { - this.preAdd(c); - this._addLater.add(c); + preAdd(c); + _addLater.add(c); } /// This implementation of render basically calls [renderComponent] for every component, making sure the canvas is reset for each one. diff --git a/lib/position.dart b/lib/position.dart index 98f8e2d3f..7ad8c4c14 100644 --- a/lib/position.dart +++ b/lib/position.dart @@ -40,43 +40,43 @@ class Position { Position.fromVector(b2d.Vector2 vector) : this(vector.x, vector.y); Position add(Position other) { - this.x += other.x; - this.y += other.y; + x += other.x; + y += other.y; return this; } Position minus(Position other) { - return this.add(other.clone().opposite()); + return add(other.clone().opposite()); } Position opposite() { - return this.times(-1.0); + return times(-1.0); } Position times(double scalar) { - this.x *= scalar; - this.y *= scalar; + x *= scalar; + y *= scalar; return this; } double dotProduct(Position p) { - return this.x * p.x + this.y * p.y; + return x * p.x + y * p.y; } double length() { - return math.sqrt(math.pow(this.x, 2) + math.pow(this.y, 2)); + return math.sqrt(math.pow(x, 2) + math.pow(y, 2)); } Position rotate(double angle) { - double nx = math.cos(angle) * this.x - math.sin(angle) * this.y; - double ny = math.sin(angle) * this.x + math.cos(angle) * this.y; - this.x = nx; - this.y = ny; + double nx = math.cos(angle) * x - math.sin(angle) * y; + double ny = math.sin(angle) * x + math.cos(angle) * y; + x = nx; + y = ny; return this; } double distance(Position other) { - return this.minus(other).length(); + return minus(other).length(); } ui.Offset toOffset() { diff --git a/lib/profiler.dart b/lib/profiler.dart index 8df91bb89..a39cb2b72 100644 --- a/lib/profiler.dart +++ b/lib/profiler.dart @@ -9,15 +9,15 @@ class Profiler { List dts = []; Profiler(this.name) { - this.tick(); + tick(); } void tick() { - this.dts.add(currentTime()); + dts.add(currentTime()); } void end() { - this.tick(); + tick(); Records.save(this); } diff --git a/lib/sprite.dart b/lib/sprite.dart index fd78fb41a..53e10ef2b 100644 --- a/lib/sprite.dart +++ b/lib/sprite.dart @@ -24,8 +24,8 @@ class Sprite { if (height == null) { height = img.height.toDouble(); } - this.image = img; - this.src = Rect.fromLTWH(x, y, width, height); + image = img; + src = Rect.fromLTWH(x, y, width, height); }); } @@ -42,7 +42,7 @@ class Sprite { if (height == null) { height = image.height.toDouble(); } - this.src = Rect.fromLTWH(x, y, width, height); + src = Rect.fromLTWH(x, y, width, height); } static Future loadSprite( @@ -66,9 +66,9 @@ class Sprite { return image != null && src != null; } - double get _imageWidth => this.image.width.toDouble(); + double get _imageWidth => image.width.toDouble(); - double get _imageHeight => this.image.height.toDouble(); + double get _imageHeight => image.height.toDouble(); Position get originalSize { if (!loaded()) { @@ -87,14 +87,14 @@ class Sprite { /// Anchor is on top left as default. /// If not loaded, does nothing. void renderScaled(Canvas canvas, Position p, [double scale = 1.0]) { - if (!this.loaded()) { + if (!loaded()) { return; } renderPosition(canvas, p, size.times(scale)); } void renderPosition(Canvas canvas, Position p, [Position size]) { - if (!this.loaded()) { + if (!loaded()) { return; } size ??= this.size; @@ -102,16 +102,16 @@ class Sprite { } void render(Canvas canvas, [double width, double height]) { - if (!this.loaded()) { + if (!loaded()) { return; } - width ??= this.size.x; - height ??= this.size.y; + width ??= size.x; + height ??= size.y; renderRect(canvas, Rect.fromLTWH(0.0, 0.0, width, height)); } void renderRect(Canvas canvas, Rect dst) { - if (!this.loaded()) { + if (!loaded()) { return; } canvas.drawImageRect(image, src, dst, paint); @@ -122,7 +122,7 @@ class Sprite { /// If [size] is not provided, the original size of the src image is used. /// If the asset is not yet loaded, it does nothing. void renderCentered(Canvas canvas, Position p, [Position size]) { - if (!this.loaded()) { + if (!loaded()) { return; } size ??= this.size;