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!: upgrade to flame 1.9.1 #7

Merged
merged 16 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 0 additions & 1 deletion example/README.md

This file was deleted.

18 changes: 11 additions & 7 deletions examples/standard_platformer/lib/coin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import 'package:leap/leap.dart';
import 'package:tiled/tiled.dart';

class Coin extends PhysicalEntity {
final TiledObject tiledObject;

Coin(this.tiledObject, SpriteAnimation animation)
: super(static: true, collisionType: CollisionType.standard) {
size = Vector2.all(16);
Coin({
required this.tiledObject,
required this.animation,
}) : super(static: true, collisionType: CollisionType.standard) {
width = 16;
height = 16;
priority = 2;

anchor = Anchor.center;
Expand All @@ -24,10 +25,13 @@ class Coin extends PhysicalEntity {
);
}

final TiledObject tiledObject;
final SpriteAnimation animation;

@override
void onRemove() {
super.onRemove();

animation.stepTime = 0.2;
FlameAudio.play('coin.wav');
}

marcossevilla marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -47,7 +51,7 @@ class Coin extends PhysicalEntity {
// We are 100% sure that an object layer named `AnimatedCoins`
// exists in the example `map.tmx`.
for (final obj in objGroup.objects) {
map.add(Coin(obj, spriteAnimation));
map.add(Coin(tiledObject: obj, animation: spriteAnimation));
}
}
}
22 changes: 9 additions & 13 deletions examples/standard_platformer/lib/hud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@ import 'package:flutter/material.dart';
import 'package:leap_standard_platformer/main.dart';

class Hud extends PositionComponent with HasGameRef<ExamplePlatformerLeapGame> {
late final TextComponent textComponent;

static const textStyle = TextStyle(
fontSize: 10,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 4,
),
],
);

Hud() {
final textPaint = TextPaint(style: textStyle);
textComponent = TextComponent(textRenderer: textPaint);
add(textComponent);

positionType = PositionType.viewport;
x = 16;
y = 4;
}

late final TextComponent textComponent;
late final CameraComponent cameraComponent;

static const textStyle = TextStyle(
fontSize: 10,
color: Colors.white,
shadows: [Shadow(blurRadius: 4)],
);

@override
void update(double dt) {
super.update(dt);
Expand Down
44 changes: 32 additions & 12 deletions examples/standard_platformer/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/widgets.dart' hide Animation, Image;
import 'package:leap/leap.dart';
Expand All @@ -9,40 +9,60 @@ import 'package:leap_standard_platformer/player.dart';
import 'package:leap_standard_platformer/welcome_dialog.dart';

void main() {
runApp(GameWidget(game: ExamplePlatformerLeapGame()));
runApp(
GameWidget(
game: ExamplePlatformerLeapGame(
tileSize: 16,
),
),
);
}

class ExamplePlatformerLeapGame extends LeapGame
with HasTappables, HasKeyboardHandlerComponents {
with TapCallbacks, HasKeyboardHandlerComponents {
ExamplePlatformerLeapGame({required super.tileSize});

late final Player player;
late final SimpleCombinedInput input;

@override
Future<void> onLoad() async {
await super.onLoad();

await loadWorldAndMap('map.tmx', 16);
setFixedViewportInTiles(32, 16);
marcossevilla marked this conversation as resolved.
Show resolved Hide resolved
await loadWorldAndMap(
tiledMapPath: 'map.tmx',
tileCameraWidth: 32,
tileCameraHeight: 16,
);

input = SimpleCombinedInput();
add(input);

player = Player();
add(player);
camera.followComponent(player);
camera.world!.add(player);
marcossevilla marked this conversation as resolved.
Show resolved Hide resolved
camera.follow(player);

if (!FlameAudio.bgm.isPlaying) {
FlameAudio.bgm.play('village_music.mp3');
}

add(Hud());
add(WelcomeDialog(camera));
await Coin.loadAllInMap(map);
camera.viewport.add(Hud());
camera.viewport.add(
WelcomeDialog(
position: Vector2(
camera.viewport.size.x * 0.5,
camera.viewport.size.y * 0.9,
),
),
);

await Coin.loadAllInMap(leapMap);
}

@override
void update(double dt) {
super.update(dt);

// on web we need to wait for a user interaction before playing any sound
// On web, we need to wait for a user interaction before playing any sound.
if (input.justPressed && !FlameAudio.bgm.isPlaying) {
FlameAudio.bgm.play('village_music.mp3');
}
Expand Down
Loading
Loading