Unify examples structure (#1118)

* Animations, CameraAndViewport, CollisionDetection and Components unified

* Added descriptions to effects

* Rename input games

* Unify input stories

* Add info to parallax section

* Added descriptions to the rendering examples

* Add descriptions to the sprites directory

* Fix utils and rendering section

* Add descriptions to the widgets section

* Delete directory that rebase brought back

* Unify game names

* Added some styleguide docs for examples

* Fix analyze issues

* All files should have _example as suffix

* Made the FollowComponentExample a bit easier to understand

* Change priority of ember
This commit is contained in:
Lukas Klingsbo
2021-11-19 14:28:04 +01:00
committed by GitHub
parent 904481d289
commit 8b132d7c0b
90 changed files with 1574 additions and 1140 deletions

View File

@ -0,0 +1,57 @@
import 'dart:ui';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import '../../commons/ember.dart';
class KeyboardExample extends FlameGame with KeyboardEvents {
static const String description = '''
Example showcasing how to act on keyboard events.
It also briefly showcases how to create a game without the FlameGame.
Usage: Use A S D F to steer Ember.
''';
static final Paint white = BasicPalette.white.paint();
static const int speed = 200;
late final Ember ember;
final Vector2 velocity = Vector2(0, 0);
@override
Future<void> onLoad() async {
await super.onLoad();
ember = Ember(position: size / 2, size: Vector2.all(100));
add(ember);
}
@override
void update(double dt) {
super.update(dt);
final displacement = velocity * (speed * dt);
ember.position.add(displacement);
}
@override
KeyEventResult onKeyEvent(
RawKeyEvent event,
Set<LogicalKeyboardKey> keysPressed,
) {
final isKeyDown = event is RawKeyDownEvent;
if (event.logicalKey == LogicalKeyboardKey.keyA) {
velocity.x = isKeyDown ? -1 : 0;
} else if (event.logicalKey == LogicalKeyboardKey.keyD) {
velocity.x = isKeyDown ? 1 : 0;
} else if (event.logicalKey == LogicalKeyboardKey.keyW) {
velocity.y = isKeyDown ? -1 : 0;
} else if (event.logicalKey == LogicalKeyboardKey.keyS) {
velocity.y = isKeyDown ? 1 : 0;
}
return super.onKeyEvent(event, keysPressed);
}
}