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

feat: adding more options to has_animation_group #54

Merged
merged 1 commit into from
Aug 24, 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
2 changes: 1 addition & 1 deletion examples/standard_platformer/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ packages:
path: "../../packages/leap"
relative: true
source: path
version: "0.6.1"
version: "0.7.0"
lints:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ class AnimationVelocityFlipBehavior
extends PhysicalBehavior<HasAnimationGroup> {
@override
void update(double dt) {
final animationFacesLeft = parent.animationFacesLeft;
final spriteFacesLeft = parent.spriteFacesLeft;
final animationGroup = parent.animationGroup;

// Update sprite for direction
if ((!animationFacesLeft && velocity.x < 0) ||
(animationFacesLeft && velocity.x > 0)) {
final lookDirection = parent.spriteLookDirection;
if ((!spriteFacesLeft && lookDirection == SpriteLookDirection.left) ||
(spriteFacesLeft && lookDirection == SpriteLookDirection.right)) {
animationGroup.scale.x = -animationGroup.scale.x.abs();
} else if ((!animationFacesLeft && velocity.x > 0) ||
(animationFacesLeft && velocity.x < 0)) {
} else if ((!spriteFacesLeft &&
lookDirection == SpriteLookDirection.right) ||
(spriteFacesLeft && lookDirection == SpriteLookDirection.left)) {
animationGroup.scale.x = animationGroup.scale.x.abs();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class PhysicalBehavior<T extends PhysicalEntity> extends Behavior<T> {
CollisionInfo get collisionInfo => parent.collisionInfo;
CollisionInfo get prevCollisionInfo => parent.prevCollisionInfo;

LeapGame get leapGame => parent.leapGame;
LeapMap get leapMap => parent.leapMap;
LeapWorld get leapWorld => parent.leapWorld;

Expand Down
28 changes: 27 additions & 1 deletion packages/leap/lib/src/entities/mixins/has_animation_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,31 @@ import 'package:leap/src/entities/physical_entity.dart';
mixin HasAnimationGroup on PhysicalEntity {
AnchoredAnimationGroup get animationGroup;

bool animationFacesLeft = false;
/// Whether or not the sprite sheet is looking left
bool spriteFacesLeft = false;

SpriteLookDirection? forceSpriteLookDirection;

/// Whether or not the animation should currently be looking left
SpriteLookDirection get spriteLookDirection {
if (forceSpriteLookDirection != null) {
return forceSpriteLookDirection!;
}

if (velocity.x == 0) {
return SpriteLookDirection.previous;
} else if (velocity.x < 0) {
return SpriteLookDirection.left;
} else {
return SpriteLookDirection.right;
}
}
}

enum SpriteLookDirection {
left,
right,

/// [previous] indicates leaving the sprite as is
previous
}
8 changes: 4 additions & 4 deletions packages/leap/lib/src/entities/mixins/has_walk_speed.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mixin HasWalkSpeed {
// Wether or not this is currently facing left
/// Wether or not this is currently facing left
bool faceLeft = false;

// Wether or not walk speed should be applied
/// Wether or not walk speed should be applied
bool isWalking = false;

// Base value for setting [walkSpeed]
/// Base value for setting [walkSpeed]
double baseWalkSpeed = 10;

// How many units to walk per second.
/// How many units to walk per second.
double walkSpeed = 10;
}
4 changes: 2 additions & 2 deletions packages/leap/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
xml:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: leap_workspace
environment:
sdk: '>=2.18.0 <3.0.0'
dev_dependencies:
melos: ^3.1.1
melos: ^6.1.0

Loading