mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Adding go desktop example
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,4 +12,5 @@ doc/api/
|
||||
|
||||
android/
|
||||
ios/
|
||||
desktop/
|
||||
build/
|
||||
|
||||
70
doc/examples/go_desktop/.gitignore
vendored
Normal file
70
doc/examples/go_desktop/.gitignore
vendored
Normal 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
|
||||
10
doc/examples/go_desktop/.metadata
Normal file
10
doc/examples/go_desktop/.metadata
Normal 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
|
||||
19
doc/examples/go_desktop/README.md
Normal file
19
doc/examples/go_desktop/README.md
Normal 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
|
||||
```
|
||||
65
doc/examples/go_desktop/lib/game.dart
Normal file
65
doc/examples/go_desktop/lib/game.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
5
doc/examples/go_desktop/lib/main.dart
Normal file
5
doc/examples/go_desktop/lib/main.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './game.dart';
|
||||
|
||||
void main() => runApp(MyGame().widget);
|
||||
10
doc/examples/go_desktop/lib/main_desktop.dart
Normal file
10
doc/examples/go_desktop/lib/main_desktop.dart
Normal 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);
|
||||
}
|
||||
17
doc/examples/go_desktop/pubspec.yaml
Normal file
17
doc/examples/go_desktop/pubspec.yaml
Normal 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
|
||||
Reference in New Issue
Block a user