Moving tutorials to the Flame main repository (#720)

* Moving tutorials to the Flame main repository

* Update README.md

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>

* Upgraded scripts to support multi projects

* Removed comment out code

* Adding WIP disclaimer

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
This commit is contained in:
Erick
2021-03-23 19:38:09 -03:00
committed by GitHub
parent 093e9552d5
commit 2259587b04
18 changed files with 396 additions and 26 deletions

View File

@ -0,0 +1,40 @@
import 'package:flame/palette.dart';
import 'package:flutter/material.dart';
import 'package:flame/game.dart';
void main() {
final myGame = MyGame();
runApp(
GameWidget(
game: myGame,
),
);
}
class MyGame extends Game {
static const int squareSpeed = 400;
static final squarePaint = BasicPalette.white.paint;
late Rect squarePos;
int squareDirection = 1;
@override
Future<void> onLoad() async {
squarePos = Rect.fromLTWH(0, 0, 100, 100);
}
@override
void update(double dt) {
squarePos = squarePos.translate(squareSpeed * squareDirection * dt, 0);
if (squareDirection == 1 && squarePos.right > size.x) {
squareDirection = -1;
} else if (squareDirection == -1 && squarePos.left < 0) {
squareDirection = 1;
}
}
@override
void render(Canvas canvas) {
canvas.drawRect(squarePos, squarePaint);
}
}