diff --git a/.gitignore b/.gitignore index 7d265cf3d..982ad47b0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ doc/api/ android/ ios/ +desktop/ build/ diff --git a/doc/examples/go_desktop/.gitignore b/doc/examples/go_desktop/.gitignore new file mode 100644 index 000000000..07488ba61 --- /dev/null +++ b/doc/examples/go_desktop/.gitignore @@ -0,0 +1,70 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.packages +.pub-cache/ +.pub/ +/build/ + +# Android related +**/android/**/gradle-wrapper.jar +**/android/.gradle +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/doc/examples/go_desktop/.metadata b/doc/examples/go_desktop/.metadata new file mode 100644 index 000000000..8fbc696e8 --- /dev/null +++ b/doc/examples/go_desktop/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 0ba67226ee62d6c9d663a6f8410fb4b2f1076046 + channel: dev + +project_type: app diff --git a/doc/examples/go_desktop/README.md b/doc/examples/go_desktop/README.md new file mode 100644 index 000000000..eef0928a5 --- /dev/null +++ b/doc/examples/go_desktop/README.md @@ -0,0 +1,19 @@ +# go_desktop + +This is an example game for testing Flame games on the desktop using the [go-flutter-desktop](https://github.com/go-flutter-desktop/go-flutter) library. + +This game features a very simple box on the screen where you can move it using WASD keys. + +To run this you need to have go and hover installed, you can find a good guide on how to install both [here](https://github.com/go-flutter-desktop/hover#install); + +After the installation, you will need to initialize the desktop runtime on the project, you con do it by simply running: + +``` +hover init projectUrl +``` + +Then just run by issue the command: + +``` +hover run +``` diff --git a/doc/examples/go_desktop/lib/game.dart b/doc/examples/go_desktop/lib/game.dart new file mode 100644 index 000000000..e7b58953c --- /dev/null +++ b/doc/examples/go_desktop/lib/game.dart @@ -0,0 +1,65 @@ +import 'package:flame/game.dart'; + +import 'package:flutter/services.dart'; +import 'package:flutter/material.dart'; + +class MyGame extends BaseGame { + + static final Paint paint = Paint()..color = Color(0xFFFFFFFF); + + var movingLeft = false; + var movingRight = false; + var movingUp = false; + var movingDown = false; + + double x = 0; + double y = 0; + + MyGame() { + _start(); + } + + void _start() { + RawKeyboard.instance.addListener((RawKeyEvent e) { + final bool isKeyDown = e is RawKeyDownEvent; + + final keyLabel = e.data.logicalKey.keyLabel; + + if (keyLabel == "a") { + movingLeft = isKeyDown; + } + + if (keyLabel == "d") { + movingRight = isKeyDown; + } + + if (keyLabel == "w") { + movingUp = isKeyDown; + } + + if (keyLabel == "s") { + movingDown = isKeyDown; + } + }); + } + + @override + void update(double dt) { + if (movingLeft) { + x -= 100 * dt; + } else if (movingRight) { + x += 100 * dt; + } + + if (movingUp) { + y -= 100 * dt; + } else if (movingDown) { + y += 100 * dt; + } + } + + @override + void render(Canvas canvas) { + canvas.drawRect(Rect.fromLTWH(x, y, 100, 100), paint); + } +} diff --git a/doc/examples/go_desktop/lib/main.dart b/doc/examples/go_desktop/lib/main.dart new file mode 100644 index 000000000..a8b02d115 --- /dev/null +++ b/doc/examples/go_desktop/lib/main.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +import './game.dart'; + +void main() => runApp(MyGame().widget); diff --git a/doc/examples/go_desktop/lib/main_desktop.dart b/doc/examples/go_desktop/lib/main_desktop.dart new file mode 100644 index 000000000..2718a0212 --- /dev/null +++ b/doc/examples/go_desktop/lib/main_desktop.dart @@ -0,0 +1,10 @@ +import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride; + +import 'package:flutter/material.dart'; + +import './game.dart'; + +void main() { + debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; + runApp(MyGame().widget); +} diff --git a/doc/examples/go_desktop/pubspec.yaml b/doc/examples/go_desktop/pubspec.yaml new file mode 100644 index 000000000..ea3336287 --- /dev/null +++ b/doc/examples/go_desktop/pubspec.yaml @@ -0,0 +1,17 @@ +name: go_desktop +description: Flame sample game on using the go flutter desktop framework + +version: 1.0.0+1 + +environment: + sdk: ">=2.1.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter + flame: + path: ../../../ + +dev_dependencies: + flutter_test: + sdk: flutter