Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
feat: sprite player hop splits (#321)
Browse files Browse the repository at this point in the history
* feat: split player hop down animation

* feat: split player left animation

* feat: split player hop right

* feat: split player up animation

* feat: update player__up_up

* feat: player sprite sheet logic now uses multiple sprite sheets

* perf: reduce player sprite sheet and shadow animation size

---------

Co-authored-by: Ollie Pugh <[email protected]>
  • Loading branch information
alestiago and OlliePugh authored Mar 12, 2024
1 parent 57711f5 commit 80c6a39
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 51 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
102 changes: 97 additions & 5 deletions packages/trashy_road/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 37 additions & 46 deletions packages/trashy_road/lib/src/game/entities/player/player.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:ui' as ui;

import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
Expand Down Expand Up @@ -103,47 +102,44 @@ class _PlayerSpriteComponent extends SpriteAnimationComponent
_PlayerSpriteComponent()
: super(
position: Vector2(-0.4, -2.5)..toGameSize(),
scale: Vector2.all(0.45),
scale: Vector2.all(0.9),
);

final Map<Direction, Map<Direction, SpriteAnimation>> _animations = {};

static final List<List<Direction>> _animationDirectionOrder =
List.unmodifiable([
[Direction.right, Direction.right],
[Direction.right, Direction.up],
[Direction.right, Direction.down],
[Direction.right, Direction.left],
[Direction.up, Direction.right],
[Direction.up, Direction.up],
[Direction.up, Direction.down],
[Direction.up, Direction.left],
[Direction.down, Direction.right],
[Direction.down, Direction.up],
[Direction.down, Direction.down],
[Direction.down, Direction.left],
[Direction.left, Direction.right],
[Direction.left, Direction.up],
[Direction.left, Direction.down],
[Direction.left, Direction.left],
]);
static final Map<(Direction, Direction), AssetGenImage> _animationSpriteMap =
{
(Direction.right, Direction.right): Assets.images.sprites.playerRightRight,
(Direction.right, Direction.up): Assets.images.sprites.playerUpUp,
(Direction.right, Direction.down): Assets.images.sprites.playerRightDown,
(Direction.right, Direction.left): Assets.images.sprites.playerRightLeft,
(Direction.up, Direction.right): Assets.images.sprites.playerUpRight,
(Direction.up, Direction.up): Assets.images.sprites.playerUpUp,
(Direction.up, Direction.down): Assets.images.sprites.playerUpDown,
(Direction.up, Direction.left): Assets.images.sprites.playerUpLeft,
(Direction.down, Direction.right): Assets.images.sprites.playerDownRight,
(Direction.down, Direction.up): Assets.images.sprites.playerDownUp,
(Direction.down, Direction.down): Assets.images.sprites.playerDownDown,
(Direction.down, Direction.left): Assets.images.sprites.playerDownLeft,
(Direction.left, Direction.right): Assets.images.sprites.playerLeftRight,
(Direction.left, Direction.up): Assets.images.sprites.playerLeftUp,
(Direction.left, Direction.down): Assets.images.sprites.playerLeftDown,
(Direction.left, Direction.left): Assets.images.sprites.playerLeftLeft,
};

Direction _previousDirection = Direction.up;

SpriteAnimation _createAnimation(ui.Image image, int row) {
Future<SpriteAnimation> _createAnimation(AssetGenImage image) async {
final spriteSheet = await game.images.load(image.path);
const frameCount = 7;

return SpriteAnimation.fromFrameData(
image,
SpriteAnimationData.range(
amount: frameCount * _animationDirectionOrder.length,
amountPerRow: frameCount,
textureSize: Vector2.all(512),
start: row * frameCount,
end: row * frameCount + frameCount - 1,
stepTimes: List.filled(
7,
(PlayerMovingBehavior.moveDelay.inMilliseconds / 1000) / frameCount,
),
spriteSheet,
SpriteAnimationData.sequenced(
amount: frameCount,
stepTime:
(PlayerMovingBehavior.moveDelay.inMilliseconds / 1000) / frameCount,
textureSize: Vector2.all(256),
loop: false,
),
);
Expand All @@ -153,19 +149,14 @@ class _PlayerSpriteComponent extends SpriteAnimationComponent
Future<void> onLoad() async {
await super.onLoad();

final image = await game.images.fetchOrGenerate(
Assets.images.sprites.playerHop.path,
() => game.images.load(Assets.images.sprites.playerHop.path),
);

for (var i = 0; i < _animationDirectionOrder.length; i++) {
final [startingDirection, endDirection] = _animationDirectionOrder[i];
for (final entry in _animationSpriteMap.entries) {
final (startingDirection, endDirection) = entry.key;
final image = entry.value;
final spriteSheet = await _createAnimation(image);
_animations[startingDirection] ??= {};
_animations[startingDirection]![endDirection] = _createAnimation(
image,
i,
);
_animations[startingDirection]![endDirection] = spriteSheet;
}

playing = false;
animation = _animations[Direction.up]![Direction.up];
}
Expand All @@ -183,7 +174,7 @@ class _PlayerShadowSpriteComponent extends SpriteAnimationComponent
_PlayerShadowSpriteComponent()
: super(
position: Vector2(-0.4, -2.5)..toGameSize(),
scale: Vector2.all(0.45),
scale: Vector2.all(1.8),
);

@override
Expand All @@ -202,7 +193,7 @@ class _PlayerShadowSpriteComponent extends SpriteAnimationComponent
SpriteAnimationData.sequenced(
amount: frameCount,
amountPerRow: 3,
textureSize: Vector2.all(512),
textureSize: Vector2.all(128),
stepTime:
(PlayerMovingBehavior.moveDelay.inMilliseconds / 1000) / frameCount,
loop: false,
Expand Down

0 comments on commit 80c6a39

Please sign in to comment.