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
... | |
class FlyTerminator extends Game with TapDetector { | |
... | |
void spawnFly() { | |
... | |
flies!.add(Fly(this, x, y)); | |
} | |
void update(double t) { | |
... |
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
... | |
class FlyTerminator extends Game { | |
... | |
List<Fly>? flies; | |
Random? rnd; | |
FlyTerminator() { | |
initialize(); | |
} |
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
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); | |
} |
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
void main() { | |
print('Hello World!'); | |
List<int> testList = List.generate(5, (index) => index); | |
print(testList); | |
} | |
// OUTPUT: | |
// Hello World! | |
// [0,1,2,3,4] |
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/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 |
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
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; |
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
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 |
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
void main() { | |
CustomGame game = CustomGame(); // create instance of class | |
runApp(game.widget); // run game | |
} |
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
class CustomGame extends Game { | |
@override | |
void render(Canvas canvas) { | |
// TODO: implement render | |
} | |
@override | |
void update(double t) { | |
// TODO: implement update | |
} | |
} |
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
// 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 |
NewerOlder