unecessary new

This commit is contained in:
Renan Araujo
2019-03-22 13:20:18 -03:00
parent b23c316def
commit e7ac8ed094
13 changed files with 73 additions and 73 deletions

View File

@ -41,7 +41,7 @@ class Animation {
/// ///
/// All frames have the same [stepTime]. /// All frames have the same [stepTime].
Animation.spriteList(List<Sprite> sprites, {double stepTime, this.loop}) { Animation.spriteList(List<Sprite> 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. /// Creates an animation given a list of frames.
@ -68,7 +68,7 @@ class Animation {
double textureHeight, double textureHeight,
double stepTime = 0.1, double stepTime = 0.1,
}) { }) {
this.frames = List<Frame>(amount); frames = List<Frame>(amount);
for (var i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
Sprite sprite = Sprite( Sprite sprite = Sprite(
imagePath, imagePath,
@ -77,7 +77,7 @@ class Animation {
width: textureWidth, width: textureWidth,
height: textureHeight, height: textureHeight,
); );
this.frames[i] = Frame(sprite, stepTime); frames[i] = Frame(sprite, stepTime);
} }
} }
@ -91,7 +91,7 @@ class Animation {
double textureWidth, double textureWidth,
double textureHeight, double textureHeight,
}) { }) {
this.frames = List<Frame>(amount); frames = List<Frame>(amount);
for (var i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
Sprite sprite = Sprite( Sprite sprite = Sprite(
imagePath, imagePath,
@ -100,7 +100,7 @@ class Animation {
width: textureWidth, width: textureWidth,
height: textureHeight, 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. /// Sets a fixed step time to all frames.
void set stepTime(double stepTime) { 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. /// Resets the animation, like it'd just been created.
void reset() { void reset() {
this.clock = 0.0; clock = 0.0;
this.elapsed = 0.0; elapsed = 0.0;
this.currentIndex = 0; currentIndex = 0;
} }
/// Gets tha current [Sprite] that should be shown. /// Gets tha current [Sprite] that should be shown.

View File

@ -29,12 +29,12 @@ abstract class Box2DComponent extends Component {
this.positionIterations: DEFAULT_POSITION_ITERATIONS, this.positionIterations: DEFAULT_POSITION_ITERATIONS,
double scale: DEFAULT_SCALE, double scale: DEFAULT_SCALE,
}) { }) {
if (this.dimensions == null) { if (dimensions == null) {
this.dimensions = window.physicalSize; dimensions = window.physicalSize;
} }
final pool = DefaultWorldPool(worldPoolSize, worldPoolContainerSize); final pool = DefaultWorldPool(worldPoolSize, worldPoolContainerSize);
this.world = World.withPool(Vector2(0.0, gravity), pool); world = World.withPool(Vector2(0.0, gravity), pool);
this.viewport = Viewport(dimensions, scale); viewport = Viewport(dimensions, scale);
} }
@override @override
@ -47,7 +47,7 @@ abstract class Box2DComponent extends Component {
@override @override
void render(canvas) { void render(canvas) {
if (viewport.size == Size(0.0, 0.0)) { if (viewport.size == Size.zero) {
return; return;
} }
components.forEach((c) { 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) { void _renderCircle(Canvas canvas, Fixture fixture) {
Vector2 center = Vector2.zero(); Vector2 center = Vector2.zero();

View File

@ -17,8 +17,8 @@ class Viewport extends ViewportTransform {
/// Resizes the current view port. /// Resizes the current view port.
void resize(Size size) { void resize(Size size) {
this.size = size; this.size = size;
this.extents = Vector2.copy(Vector2(size.width / 2, size.height / 2)); extents = Vector2.copy(Vector2(size.width / 2, size.height / 2));
this.center = 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. /// Computes the number of horizontal world meters of this viewport considering a percentage of its width.

View File

@ -25,7 +25,7 @@ class AnimationComponent extends PositionComponent {
}) { }) {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.animation = Animation.sequenced( animation = Animation.sequenced(
imagePath, imagePath,
amount, amount,
textureX: textureX, textureX: textureX,

View File

@ -65,30 +65,30 @@ abstract class PositionComponent extends Component {
Position toPosition() => Position(x, y); Position toPosition() => Position(x, y);
void setByPosition(Position position) { void setByPosition(Position position) {
this.x = position.x; x = position.x;
this.y = position.y; y = position.y;
} }
Position toSize() => Position(width, height); Position toSize() => Position(width, height);
void setBySize(Position size) { void setBySize(Position size) {
this.width = size.x; width = size.x;
this.height = size.y; height = size.y;
} }
Rect toRect() => Rect.fromLTWH(x, y, width, height); Rect toRect() => Rect.fromLTWH(x, y, width, height);
void setByRect(Rect rect) { void setByRect(Rect rect) {
this.x = rect.left; x = rect.left;
this.y = rect.top; y = rect.top;
this.width = rect.width; width = rect.width;
this.height = rect.height; height = rect.height;
} }
double angleBetween(PositionComponent c) { 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) { 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) { void prepareCanvas(Canvas canvas) {

View File

@ -56,7 +56,7 @@ mixin ComposedComponent on Component {
} }
void add(Component c) { void add(Component c) {
this.components.add(c); components.add(c);
if (this is Resizable) { if (this is Resizable) {
// first time resize // first time resize
@ -68,5 +68,5 @@ mixin ComposedComponent on Component {
} }
List<Resizable> children() => List<Resizable> children() =>
this.components.where((r) => r is Resizable).cast<Resizable>().toList(); components.where((r) => r is Resizable).cast<Resizable>().toList();
} }

View File

@ -57,7 +57,7 @@ abstract class ParallaxComponent extends PositionComponent {
@override @override
void resize(Size size) { 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. /// 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 @override
void update(double delta) { void update(double delta) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
for (int i = 0; i < _layers.length; i++) { for (int i = 0; i < _layers.length; i++) {

View File

@ -25,14 +25,14 @@ class TextComponent extends PositionComponent {
} }
TextComponent(this._text, {TextConfig config = const TextConfig()}) { TextComponent(this._text, {TextConfig config = const TextConfig()}) {
this._config = config; _config = config;
_updateBox(); _updateBox();
} }
void _updateBox() { void _updateBox() {
TextPainter tp = config.toTextPainter(text); TextPainter tp = config.toTextPainter(text);
this.width = tp.width; width = tp.width;
this.height = tp.height; height = tp.height;
} }
@override @override

View File

@ -17,14 +17,14 @@ class TiledComponent extends Component {
static Paint paint = Paint()..color = Colors.white; static Paint paint = Paint()..color = Colors.white;
TiledComponent(this.filename) { TiledComponent(this.filename) {
this.future = _load(); future = _load();
} }
Future _load() async { Future _load() async {
this.map = await _loadMap(); map = await _loadMap();
this.image = await Flame.images.load(map.tilesets[0].image.source); image = await Flame.images.load(map.tilesets[0].image.source);
this.images = await _loadImages(map); images = await _loadImages(map);
this._loaded = true; _loaded = true;
} }
Future<TileMap> _loadMap() { Future<TileMap> _loadMap() {

View File

@ -61,7 +61,7 @@ class _GameRenderObjectWidget extends SingleChildRenderObjectWidget {
@override @override
RenderObject createRenderObject(BuildContext context) => RenderObject createRenderObject(BuildContext context) =>
_GameRenderBox(context, this.game); _GameRenderBox(context, game);
@override @override
void updateRenderObject(BuildContext context, _GameRenderBox _gameRenderBox) { 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). /// 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) { void add(Component c) {
this.preAdd(c); preAdd(c);
this.components.add(c); components.add(c);
} }
/// Registers a component to be added on the components on the next tick. /// 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. /// 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. /// Also calls [preAdd] for the component added, immediately.
void addLater(Component c) { void addLater(Component c) {
this.preAdd(c); preAdd(c);
this._addLater.add(c); _addLater.add(c);
} }
/// This implementation of render basically calls [renderComponent] for every component, making sure the canvas is reset for each one. /// This implementation of render basically calls [renderComponent] for every component, making sure the canvas is reset for each one.

View File

@ -40,43 +40,43 @@ class Position {
Position.fromVector(b2d.Vector2 vector) : this(vector.x, vector.y); Position.fromVector(b2d.Vector2 vector) : this(vector.x, vector.y);
Position add(Position other) { Position add(Position other) {
this.x += other.x; x += other.x;
this.y += other.y; y += other.y;
return this; return this;
} }
Position minus(Position other) { Position minus(Position other) {
return this.add(other.clone().opposite()); return add(other.clone().opposite());
} }
Position opposite() { Position opposite() {
return this.times(-1.0); return times(-1.0);
} }
Position times(double scalar) { Position times(double scalar) {
this.x *= scalar; x *= scalar;
this.y *= scalar; y *= scalar;
return this; return this;
} }
double dotProduct(Position p) { double dotProduct(Position p) {
return this.x * p.x + this.y * p.y; return x * p.x + y * p.y;
} }
double length() { 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) { Position rotate(double angle) {
double nx = math.cos(angle) * this.x - math.sin(angle) * this.y; double nx = math.cos(angle) * x - math.sin(angle) * y;
double ny = math.sin(angle) * this.x + math.cos(angle) * this.y; double ny = math.sin(angle) * x + math.cos(angle) * y;
this.x = nx; x = nx;
this.y = ny; y = ny;
return this; return this;
} }
double distance(Position other) { double distance(Position other) {
return this.minus(other).length(); return minus(other).length();
} }
ui.Offset toOffset() { ui.Offset toOffset() {

View File

@ -9,15 +9,15 @@ class Profiler {
List<double> dts = []; List<double> dts = [];
Profiler(this.name) { Profiler(this.name) {
this.tick(); tick();
} }
void tick() { void tick() {
this.dts.add(currentTime()); dts.add(currentTime());
} }
void end() { void end() {
this.tick(); tick();
Records.save(this); Records.save(this);
} }

View File

@ -24,8 +24,8 @@ class Sprite {
if (height == null) { if (height == null) {
height = img.height.toDouble(); height = img.height.toDouble();
} }
this.image = img; image = img;
this.src = Rect.fromLTWH(x, y, width, height); src = Rect.fromLTWH(x, y, width, height);
}); });
} }
@ -42,7 +42,7 @@ class Sprite {
if (height == null) { if (height == null) {
height = image.height.toDouble(); height = image.height.toDouble();
} }
this.src = Rect.fromLTWH(x, y, width, height); src = Rect.fromLTWH(x, y, width, height);
} }
static Future<Sprite> loadSprite( static Future<Sprite> loadSprite(
@ -66,9 +66,9 @@ class Sprite {
return image != null && src != null; 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 { Position get originalSize {
if (!loaded()) { if (!loaded()) {
@ -87,14 +87,14 @@ class Sprite {
/// Anchor is on top left as default. /// Anchor is on top left as default.
/// If not loaded, does nothing. /// If not loaded, does nothing.
void renderScaled(Canvas canvas, Position p, [double scale = 1.0]) { void renderScaled(Canvas canvas, Position p, [double scale = 1.0]) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
renderPosition(canvas, p, size.times(scale)); renderPosition(canvas, p, size.times(scale));
} }
void renderPosition(Canvas canvas, Position p, [Position size]) { void renderPosition(Canvas canvas, Position p, [Position size]) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
size ??= this.size; size ??= this.size;
@ -102,16 +102,16 @@ class Sprite {
} }
void render(Canvas canvas, [double width, double height]) { void render(Canvas canvas, [double width, double height]) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
width ??= this.size.x; width ??= size.x;
height ??= this.size.y; height ??= size.y;
renderRect(canvas, Rect.fromLTWH(0.0, 0.0, width, height)); renderRect(canvas, Rect.fromLTWH(0.0, 0.0, width, height));
} }
void renderRect(Canvas canvas, Rect dst) { void renderRect(Canvas canvas, Rect dst) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
canvas.drawImageRect(image, src, dst, paint); 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 [size] is not provided, the original size of the src image is used.
/// If the asset is not yet loaded, it does nothing. /// If the asset is not yet loaded, it does nothing.
void renderCentered(Canvas canvas, Position p, [Position size]) { void renderCentered(Canvas canvas, Position p, [Position size]) {
if (!this.loaded()) { if (!loaded()) {
return; return;
} }
size ??= this.size; size ??= this.size;