Last active
April 21, 2020 14:34
-
-
Save BoHellgren/db71012be81e05f2d49a69a7f1364df4 to your computer and use it in GitHub Desktop.
Game MyGame class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flame/flame.dart'; | |
import 'package:flame/game.dart'; | |
import 'dart:math'; | |
class MyGame extends BaseGame { | |
static int kills; | |
static int target; | |
static final Paint paint = Paint(); | |
static Rect progressIndicatorRect; | |
static double progressIndicatorLength; | |
Rect bgRect; | |
double secondsPassed = 0.0; | |
@override | |
bool debugMode() { | |
return false; | |
} | |
@override | |
void resize(Size size) { | |
bgRect = Rect.fromLTWH(0.0, 0.0, size.width, size.height); | |
super.resize(size); | |
} | |
void update(double dt) { | |
if ((secondsPassed < 10.0) && (kills < target)) secondsPassed += dt; | |
super.update(dt); | |
} | |
@override | |
void render(Canvas canvas) { | |
paint.color = Colors.white; | |
canvas.drawRect(bgRect, paint); | |
super.render(canvas); | |
progressIndicatorLength = | |
min(secondsPassed * size.width / 10.0, size.width); | |
progressIndicatorRect = | |
Rect.fromLTWH(0.0, 0.0, progressIndicatorLength, 15.0); | |
paint.color = Colors.red; | |
canvas.drawRect(progressIndicatorRect, paint); | |
TextConfig(fontSize: 16.0, color: Colors.black,) | |
..render(canvas, I18n.currentKills + ' ${MyGame.kills}', Position(5.0, size.height - 20.0)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment