mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
As discussed previously, this PR moves the Space Shooter Tutorial to the tutorials folder for direct inclusion in the docs. A few things to note, other than basic grammar and formatting, nothing was changed other than migrating the information to the current tutorial format. This should allow the tutorials.flame-engine.org subdomain to be deleted. Note: Upon moving this tutorial, I discovered it is incomplete and missing the majority of the game. Also, I realized that I left the android folder and some files that weren't necessary for the platform tutorial and have deleted those.
45 lines
876 B
Dart
45 lines
876 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
runApp(GameWidget(game: SpaceShooterGame()));
|
|
}
|
|
|
|
class SpaceShooterGame extends FlameGame with PanDetector {
|
|
late Player player;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
|
|
player = Player();
|
|
|
|
add(player);
|
|
}
|
|
|
|
@override
|
|
void onPanUpdate(DragUpdateInfo info) {
|
|
player.move(info.delta.game);
|
|
}
|
|
}
|
|
|
|
class Player extends SpriteComponent with HasGameRef<SpaceShooterGame> {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
|
|
sprite = await gameRef.loadSprite('player-sprite.png');
|
|
|
|
position = gameRef.size / 2;
|
|
width = 100;
|
|
height = 150;
|
|
anchor = Anchor.center;
|
|
}
|
|
|
|
void move(Vector2 delta) {
|
|
position.add(delta);
|
|
}
|
|
}
|