Adding go desktop example

This commit is contained in:
Erick Zanardo
2019-05-21 12:20:05 -03:00
parent 6418242f65
commit dd0de2e751
8 changed files with 197 additions and 0 deletions

1
.gitignore vendored
View File

@ -12,4 +12,5 @@ doc/api/
android/
ios/
desktop/
build/

70
doc/examples/go_desktop/.gitignore vendored Normal file
View File

@ -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

View File

@ -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

View File

@ -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
```

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
import 'package:flutter/material.dart';
import './game.dart';
void main() => runApp(MyGame().widget);

View File

@ -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);
}

View File

@ -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