diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 2c1c6c4..5a3eb01 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,11 @@ + - connectServer() async { + try { + Socket.connect('10.0.0.224', 50018).then((Socket sock) { + socket = sock; + socket.listen(dataHandler, + onError: errorHandler, onDone: doneHandler, cancelOnError: false); + }); + } catch (e) { + print(e); + } + // try { + // final response = await http.post( + // Uri.parse('http://10.0.0.224:50017'), + // headers: { + // 'Content-Type': 'application/json; charset=UTF-8', + // }, + // body: jsonEncode({ + // 'title': "hi", + // }), + // ); + // if (response.statusCode == 201) { + // // If the server did return a 201 CREATED response, + // // then parse the JSON. + // print("hello"); + // print(response); + // print(response.body); + // } else { + // // If the server did not return a 201 CREATED response, + // // then throw an exception. + // throw Exception('Failed to create album.'); + // } + // // var value = await channel.stream.first; + // // print(value); + // } catch (e) { + // print(e); + // } + } + + Future displayLoss() async { if (!(runner.sprite.animation?.done() ?? false) && runner.sprite.animation!.loop == false && firstDeath) { return; } + await connectServer(); firstDeath = false; overlays.add('gameOver'); } diff --git a/lib/runner.dart b/lib/runner.dart index d07fc6b..8baf000 100644 --- a/lib/runner.dart +++ b/lib/runner.dart @@ -1,12 +1,14 @@ +import 'package:flame/extensions.dart'; import 'package:firo_runner/bug.dart'; import 'package:firo_runner/moving_object.dart'; import 'package:firo_runner/main.dart'; import 'package:flame/effects.dart'; -import 'package:flame/extensions.dart'; -import 'package:flutter/material.dart'; +import 'package:flame/flame.dart'; +// import 'package:flutter/material.dart'; import 'dart:math'; - import 'package:flame/components.dart'; +import 'package:flame/image_composition.dart'; +import 'package:flutter/animation.dart'; enum RunnerState { run, @@ -61,7 +63,11 @@ class Runner extends Component with HasGameRef { @override void render(Canvas c) { super.render(c); - getSprite().render(c, position: sprite.position, size: sprite.size); + // getSprite().render(c, position: sprite.position, size: sprite.size); + getSprite().render(c, + position: Vector2(sprite.position.x - sprite.size.x / 3, + sprite.position.y - sprite.size.y / 3), + size: sprite.size * 1.6); } void updateLevel() { @@ -462,52 +468,96 @@ class Runner extends Component with HasGameRef { } Future load(loadSpriteAnimation) async { - SpriteAnimation running = await loadSpriteAnimation( - 'run-frames.png', - SpriteAnimationData.sequenced( - amount: 7, - stepTime: 0.1, - textureSize: Vector2(512, 512), - ), - ); + List satellites = []; + for (int i = 1; i <= 38; i++) { + satellites.add(await Flame.images.load( + 'runner/satellite/satellite00${i < 10 ? "0" + i.toString() : i.toString()}.png')); + } - SpriteAnimation jumping = await loadSpriteAnimation( - 'jump-frames.png', - SpriteAnimationData.sequenced( - amount: 5, - stepTime: 0.1, - textureSize: Vector2(512, 512), - loop: false, - ), - ); + List runs = []; + for (int i = 1; i <= 38; i++) { + final composition = ImageComposition() + ..add(satellites.elementAt(i - 1), Vector2(0, 0)) + ..add( + await Flame.images.load( + 'runner/run/run00${i < 10 ? "0" + i.toString() : i.toString()}.png'), + Vector2(0, 0)); - SpriteAnimation ducking = await loadSpriteAnimation( - 'crawl-frames.png', - SpriteAnimationData.sequenced( - amount: 3, - stepTime: 0.1, - textureSize: Vector2(512, 512), - ), - ); + runs.add(Sprite(await composition.compose())); + } - SpriteAnimation kicking = await loadSpriteAnimation( - 'kick-frames.png', - SpriteAnimationData.sequenced( - amount: 19, - stepTime: 0.03, - textureSize: Vector2(512, 512), - loop: false, - ), - ); + SpriteAnimation running = + SpriteAnimation.spriteList(runs, stepTime: 0.02, loop: true); - SpriteAnimation floating = await loadSpriteAnimation( - 'hover-frames.png', - SpriteAnimationData.sequenced( - amount: 3, - stepTime: 0.1, - textureSize: Vector2(512, 512), - ), - ); + List jumps = []; + for (int i = 1; i <= 6; i++) { + final composition = ImageComposition() + ..add(satellites.elementAt(i - 1), Vector2(0, 0)) + ..add( + await Flame.images.load( + 'runner/jump/jump00${i < 10 ? "0" + i.toString() : i.toString()}.png'), + Vector2(0, 0)); + + jumps.add(Sprite(await composition.compose())); + } + + SpriteAnimation jumping = + SpriteAnimation.spriteList(jumps, stepTime: 0.02, loop: false); + + List ducks = []; + for (int i = 1; i <= 38; i++) { + final composition = ImageComposition() + ..add(satellites.elementAt(i - 1), Vector2(0, 0)) + ..add( + await Flame.images.load( + 'runner/duck1/duck100${i < 10 ? "0" + i.toString() : i.toString()}.png'), + Vector2(0, 0)); + + ducks.add(Sprite(await composition.compose())); + } + + SpriteAnimation ducking = + SpriteAnimation.spriteList(ducks, stepTime: 0.02, loop: true); + + List kicks = []; + for (int i = 1; i <= 38; i++) { + final composition = ImageComposition() + ..add(satellites.elementAt(i - 1), Vector2(0, 0)) + ..add( + await Flame.images.load( + 'runner/attack1/attack100${i < 10 ? "0" + i.toString() : i.toString()}.png'), + Vector2(0, 0)); + + kicks.add(Sprite(await composition.compose())); + } + + SpriteAnimation kicking = + SpriteAnimation.spriteList(kicks, stepTime: 0.02, loop: false); + + List floats = []; + for (int i = 1; i <= 44; i++) { + final composition = ImageComposition() + ..add(satellites.elementAt(((i - 1) % 38)), Vector2(0, 0)) + ..add( + await Flame.images.load( + 'runner/hover1/hover100${i < 10 ? "0" + i.toString() : i.toString()}.png'), + Vector2(0, 0)); + + floats.add(Sprite(await composition.compose())); + } + + SpriteAnimation floating = + SpriteAnimation.spriteList(floats, stepTime: 0.02, loop: true); + + // TODO Falling animations + // List falls = []; + // for (int i = 1; i <= 38; i++) { + // falls.add(Sprite(await Flame.images.load( + // 'runner/run/run00${i < 10 ? "0" + i.toString() : i.toString()}.png'))); + // } + // + // SpriteAnimation falling = + // SpriteAnimation.spriteList(falls, stepTime: 0.02, loop: true); SpriteAnimation falling = await loadSpriteAnimation( 'fall-frames.png', @@ -518,35 +568,23 @@ class Runner extends Component with HasGameRef { ), ); - SpriteAnimation dying = await loadSpriteAnimation( - 'death-normal-frames.png', - SpriteAnimationData.sequenced( - amount: 20, - stepTime: 0.05, - textureSize: Vector2(512, 512), - loop: false, - ), - ); + List dies = []; + for (int i = 1; i <= 57; i++) { + dies.add(Sprite(await Flame.images.load( + 'runner/death/death200${i < 10 ? "0" + i.toString() : i.toString()}.png'))); + } - SpriteAnimation dyingElectrocuted = await loadSpriteAnimation( - 'electrocuted-frames.png', - SpriteAnimationData.sequenced( - amount: 2, - stepTime: 0.25, - textureSize: Vector2(512, 512), - loop: false, - ), - ); + SpriteAnimation dying = + SpriteAnimation.spriteList(dies, stepTime: 0.02, loop: false); - SpriteAnimation dyingGlitch = await loadSpriteAnimation( - 'death-glitched-frames.png', - SpriteAnimationData.sequenced( - amount: 8, - stepTime: 0.1, - textureSize: Vector2(512, 512), - loop: false, - ), - ); + List dyingGlitches = []; + for (int i = 1; i <= 81; i++) { + dyingGlitches.add(Sprite(await Flame.images.load( + 'runner/deathglitch/death100${i < 10 ? "0" + i.toString() : i.toString()}.png'))); + } + + SpriteAnimation dyingGlitch = + SpriteAnimation.spriteList(dyingGlitches, stepTime: 0.02, loop: false); sprite = SpriteAnimationGroupComponent( animations: { @@ -557,7 +595,7 @@ class Runner extends Component with HasGameRef { RunnerState.float: floating, RunnerState.fall: falling, RunnerState.die: dying, - RunnerState.electrocute: dyingElectrocuted, + RunnerState.electrocute: dying, RunnerState.glitch: dyingGlitch, }, current: RunnerState.run, diff --git a/pubspec.lock b/pubspec.lock index 7e37756..f51826b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -122,7 +122,7 @@ packages: source: sdk version: "0.0.0" http: - dependency: transitive + dependency: "direct main" description: name: http url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 02e38e9..593db1b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: sdk: flutter flame: "^1.0.0-releasecandidate.11" flame_audio: "^1.0.0-rc.1" + http: ^0.13.3 # The following adds the Cupertino Icons font to your application. @@ -51,6 +52,20 @@ flutter: - assets/images/ - assets/audio/ - assets/audio/sfx/ + - assets/images/runner/run/ + - assets/images/runner/satellite/ + - assets/images/runner/death/ + - assets/images/runner/deathglitch/ + - assets/images/runner/jump/ + - assets/images/runner/attack1/ + - assets/images/runner/attack2/ + - assets/images/runner/attack3/ + - assets/images/runner/duck1/ + - assets/images/runner/duck2/ + - assets/images/runner/duck3/ + - assets/images/runner/hover1/ + - assets/images/runner/hover2/ + - assets/images/runner/hover3/ fonts: - family: Codystar