Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.8.1 #505

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.8.1
- Adds param `centerAnchor` in `SimpleDirectionAnimation` and `PlatformAnimations`. It's useful to correct spritesheet not centered.

# 3.8.0
- Adds `DamageHitbox`. Use it to do damage.
- `GameMap` Improvements. Now you can access the layers
Expand Down
3 changes: 3 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:label="example"
android:name="${applicationName}"
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.7.1"
version: "3.8.0"
boolean_selector:
dependency: transitive
description:
Expand Down
18 changes: 8 additions & 10 deletions lib/mixins/direction_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ mixin DirectionAnimation on Movement {
}

void onPlayRunDownAnimation() {
if (animation?.runDown != null ||
(animation?.runUp != null && animation?.enabledFlipY == true)) {
if (animation?.canRunDown == true) {
animation?.play(SimpleAnimationEnum.runDown);
} else {
if (lastDirectionHorizontal == Direction.left) {
Expand All @@ -118,7 +117,7 @@ mixin DirectionAnimation on Movement {
}

void onPlayRunUpAnimation() {
if (animation?.runUp != null) {
if (animation?.canRunUp == true) {
animation?.play(SimpleAnimationEnum.runUp);
} else {
if (lastDirectionHorizontal == Direction.left) {
Expand All @@ -130,31 +129,31 @@ mixin DirectionAnimation on Movement {
}

void onPlayRunUpLeftAnimation() {
if (animation?.runUpLeft != null) {
if (animation?.canRunUpLeft == true) {
animation?.play(SimpleAnimationEnum.runUpLeft);
} else {
animation?.play(SimpleAnimationEnum.runLeft);
}
}

void onPlayRunUpRightAnimation() {
if (animation?.runUpRight != null) {
if (animation?.canRunUpRight == true) {
animation?.play(SimpleAnimationEnum.runUpRight);
} else {
animation?.play(SimpleAnimationEnum.runRight);
}
}

void onPlayRunDownLeftAnimation() {
if (animation?.runDownLeft != null) {
if (animation?.canRunDownLeft == true) {
animation?.play(SimpleAnimationEnum.runDownLeft);
} else {
animation?.play(SimpleAnimationEnum.runLeft);
}
}

void onPlayRunDownRightAnimation() {
if (animation?.runDownRight != null) {
if (animation?.canRunDownRight == true) {
animation?.play(SimpleAnimationEnum.runDownRight);
} else {
animation?.play(SimpleAnimationEnum.runRight);
Expand All @@ -170,7 +169,7 @@ mixin DirectionAnimation on Movement {
}

void onPlayIdleUpAnimation() {
if (animation?.idleUp != null) {
if (animation?.canIdleUp == true) {
animation?.play(SimpleAnimationEnum.idleUp);
} else {
if (lastDirectionHorizontal == Direction.left) {
Expand All @@ -182,8 +181,7 @@ mixin DirectionAnimation on Movement {
}

void onPlayIdleDownAnimation() {
if (animation?.idleDown != null ||
(animation?.idleUp != null && animation?.enabledFlipY == true)) {
if (animation?.canIdleDown == true) {
animation?.play(SimpleAnimationEnum.idleDown);
} else {
if (lastDirectionHorizontal == Direction.left) {
Expand Down
43 changes: 25 additions & 18 deletions lib/player/platform_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PlatformPlayer extends SimplePlayer
PlatformPlayer({
required super.position,
required super.size,
required PlatformAnimations animation,
PlatformAnimations? animation,
Direction initDirection = Direction.right,
double? speed,
double life = 100,
Expand All @@ -14,23 +14,30 @@ class PlatformPlayer extends SimplePlayer
initDirection: initDirection,
speed: speed,
life: life,
animation: SimpleDirectionAnimation(
idleRight: animation.idleRight,
runRight: animation.runRight,
idleLeft: animation.idleLeft,
runLeft: animation.runLeft,
others: {
if (animation.jump?.jumpUpRight != null)
JumpAnimationsEnum.jumpUpRight: animation.jump!.jumpUpRight,
if (animation.jump?.jumpUpLeft != null)
JumpAnimationsEnum.jumpUpLeft: animation.jump!.jumpUpLeft!,
if (animation.jump?.jumpDownRight != null)
JumpAnimationsEnum.jumpDownRight: animation.jump!.jumpDownRight,
if (animation.jump?.jumpDownLeft != null)
JumpAnimationsEnum.jumpDownLeft: animation.jump!.jumpDownLeft!,
...animation.others ?? {},
},
),
animation: animation != null
? SimpleDirectionAnimation(
idleRight: animation.idleRight,
runRight: animation.runRight,
idleLeft: animation.idleLeft,
runLeft: animation.runLeft,
centerAnchor: animation.centerAnchor,
others: {
if (animation.jump?.jumpUpRight != null)
JumpAnimationsEnum.jumpUpRight:
animation.jump!.jumpUpRight,
if (animation.jump?.jumpUpLeft != null)
JumpAnimationsEnum.jumpUpLeft:
animation.jump!.jumpUpLeft!,
if (animation.jump?.jumpDownRight != null)
JumpAnimationsEnum.jumpDownRight:
animation.jump!.jumpDownRight,
if (animation.jump?.jumpDownLeft != null)
JumpAnimationsEnum.jumpDownLeft:
animation.jump!.jumpDownLeft!,
...animation.others ?? {},
},
)
: null,
) {
setupJumper(maxJump: countJumps);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/util/direction_animations/platform_animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PlatformAnimations {
final FutureOr<SpriteAnimation>? runLeft;
final PlatformJumpAnimations? jump;
final Map<String, FutureOr<SpriteAnimation>>? others;
final Vector2? centerAnchor;

PlatformAnimations({
required this.idleRight,
Expand All @@ -31,5 +32,6 @@ class PlatformAnimations {
this.runLeft,
this.jump,
this.others,
this.centerAnchor,
});
}
89 changes: 89 additions & 0 deletions lib/util/direction_animations/render_transform_warpper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:ui';

import 'package:bonfire/bonfire.dart';

class RenderTransformWrapper {
final List<RenderTransformer> transforms;
final void Function(Canvas canvas, Paint paint) render;

RenderTransformWrapper({required this.transforms, required this.render});

void execRender(Canvas canvas, Paint paint) {
int index = 0;
for (final transform in transforms) {
if (transform.transform(canvas)) {
index++;
}
}
render(canvas, paint);
for (int i = 0; i < index; i++) {
canvas.restore();
}
}
}

abstract class RenderTransformer {
bool transform(Canvas canvas);
}

class CenterAdjustRenderTransform extends RenderTransformer {
final CenterAdjustRenderData? Function() onTransform;

CenterAdjustRenderTransform(this.onTransform);

@override
bool transform(Canvas canvas) {
final data = onTransform();
if (data == null) {
return false;
}
canvas.save();
Vector2 diff = data.center - data.newCenter;
canvas.translate(diff.x, diff.y);
return true;
}
}

class CenterAdjustRenderData {
final Vector2 center;
final Vector2 newCenter;

CenterAdjustRenderData({
required this.center,
required this.newCenter,
});
}

class FlipRenderTransform extends RenderTransformer {
final FlipRenderTransformData? Function() onTransform;

FlipRenderTransform(this.onTransform);

@override
bool transform(Canvas canvas) {
final data = onTransform();
if (data == null) {
return false;
}
canvas.save();
canvas.translate(data.center.x, data.center.y);
canvas.scale(
data.horizontal ? -1 : 1,
data.vertical ? -1 : 1,
);
canvas.translate(-data.center.x, -data.center.y);
return true;
}
}

class FlipRenderTransformData {
final Vector2 center;
final bool horizontal;
final bool vertical;

FlipRenderTransformData({
required this.center,
required this.horizontal,
required this.vertical,
});
}
Loading
Loading