Skip to content

Instantly share code, notes, and snippets.

View juskek's full-sized avatar

Justin juskek

View GitHub Profile
...
class FlyTerminator extends Game with TapDetector {
...
void spawnFly() {
...
flies!.add(Fly(this, x, y));
}
void update(double t) {
...
...
class FlyTerminator extends Game {
...
List<Fly>? flies;
Random? rnd;
FlyTerminator() {
initialize();
}
class Fly {
final FlyTerminator game;
Rect? flyRect;
Paint flyPaint = Paint();
Fly(this.game, double x, double y) {
flyRect = Rect.fromLTWH(x, y, game.tileSize!, game.tileSize!);
flyPaint.color = Color(0xff6ab04c);
}
void main() {
print('Hello World!');
List<int> testList = List.generate(5, (index) => index);
print(testList);
}
// OUTPUT:
// Hello World!
// [0,1,2,3,4]
import 'package:flame/gestures.dart'; // for TapDetector mixin
import 'package:flutter/gestures.dart'; // for TapDownDetails class
class BoxGame extends Game with TapDetector {
bool hasWon = false;
@override
void onTapDown(TapDownDetails tapDownDetails) {
// handle taps here
void render(Canvas canvas) {
/// BACKGROUND (BOTTOMMOST LAYER)
Rect bgRect = Rect.fromLTWH(0, 0, screenSize!.width,screenSize!.height);
Paint bgPaint = Paint();
bgPaint.color = Color(0xffbbcc00);
canvas.drawRect(bgRect, bgPaint);
/// TARGET BOX (TOPMOST LAYER)
print(screenSize); // ! target box does not change with screen size
double screenCenterX = screenSize!.width / 2;
double screenCenterY = screenSize!.height / 2;
class CustomGame extends Game {
Size? screenSize;
bool hasPressed;
// this will be CustomGame's resize function
@override
void resize (Size size) {
screenSize = size; // assign Game widget size to screenSize
super.resize(size); // call Game's resize function again
}
... // update and render functions
void main() {
CustomGame game = CustomGame(); // create instance of class
runApp(game.widget); // run game
}
class CustomGame extends Game {
@override
void render(Canvas canvas) {
// TODO: implement render
}
@override
void update(double t) {
// TODO: implement update
}
}
// in pubspec.yaml
flame: ^0.29.4
// in main.dart
import 'package:flutter/material.dart';
import 'package:flame/game.dart'; // for creating Game class
import 'package:flame/gestures.dart'; // for TapDetector mixin
import 'package:flutter/gestures.dart'; // for TapDownDetails class
import 'dart:ui'; // for Canvas and Size
// in console
flutter run --no-sound-null-safety