Skip to content

Commit

Permalink
feat: adding more options to has_animation_group (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtome authored Aug 24, 2024
1 parent 2711d39 commit 6be5eba
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
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

0 comments on commit 6be5eba

Please sign in to comment.