Skip to content

Commit

Permalink
Merge pull request #11 from flame-engine/luan.glb
Browse files Browse the repository at this point in the history
Upgrade to use new flame_3d version
  • Loading branch information
luanpotter authored Aug 31, 2024
2 parents 17617b4 + 78bf86d commit c673e36
Show file tree
Hide file tree
Showing 27 changed files with 187 additions and 473 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down Expand Up @@ -42,5 +44,4 @@ app.*.map.json
/android/app/profile
/android/app/release

pubspec_overrides.yaml
pubspec.lock
pubspec.lock
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:flutter_lints/flutter.yaml
include: package:flame_lint/analysis_options.yaml
Binary file added assets/objects/donuts/donut_2.glb
Binary file not shown.
29 changes: 23 additions & 6 deletions lib/audio.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
import 'package:defend_the_donut/utils.dart';
import 'package:flame_audio/flame_audio.dart';

class Audio {
static late final AudioPool _pewPool;
static late final AudioPool _failedPewPool;

static Future<void> init() async {
_pewPool = await FlameAudio.createPool('sfx/laser.mp3', maxPlayers: 5, minPlayers: 3);
_failedPewPool = await FlameAudio.createPool('sfx/error.mp3', maxPlayers: 5, minPlayers: 3);
_pewPool = await FlameAudio.createPool(
'sfx/laser.mp3',
maxPlayers: 5,
minPlayers: 3,
);
_failedPewPool = await FlameAudio.createPool(
'sfx/error.mp3',
maxPlayers: 5,
minPlayers: 3,
);
}

static void pew() {
_pewPool.start();
if (enableAudio) {
_pewPool.start();
}
}

static void failedPew() {
_failedPewPool.start();
if (enableAudio) {
_failedPewPool.start();
}
}

static void boost() {
FlameAudio.play('sfx/boost.mp3');
if (enableAudio) {
FlameAudio.play('sfx/boost.mp3');
}
}

static void explode() {
FlameAudio.play('sfx/explode.mp3');
if (enableAudio) {
FlameAudio.play('sfx/explode.mp3');
}
}
}
12 changes: 6 additions & 6 deletions lib/components/base_component.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flame/components.dart';
import 'package:flame_3d/components.dart';
import 'package:flutter/foundation.dart';
import 'package:defend_the_donut/space_game_3d.dart';
import 'package:defend_the_donut/utils.dart';
import 'package:flame/components.dart';
import 'package:flame_3d_extras/model/model_component.dart';
import 'package:flutter/foundation.dart';

class BaseComponent extends MeshComponent with HasGameReference<SpaceGame3D> {
class BaseComponent extends ModelComponent with HasGameReference<SpaceGame3D> {
BaseComponent({
required super.mesh,
required super.model,
required super.position,
});

Expand All @@ -26,4 +26,4 @@ class BaseComponent extends MeshComponent with HasGameReference<SpaceGame3D> {
}

void doUpdate(double dt) {}
}
}
11 changes: 6 additions & 5 deletions lib/components/beam.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:ui';
import 'dart:math' as math;
import 'dart:ui';

import 'package:defend_the_donut/components/cylinder_mesh.dart';
import 'package:flame_3d/components.dart';
import 'package:flame_3d/game.dart';
import 'package:flame_3d/resources.dart';
Expand All @@ -18,7 +17,7 @@ class Beam extends MeshComponent {
),
);

static Beam generate({
factory Beam.generate({
required Vector3 start,
required Vector3 end,
double radius = _beamRadius,
Expand Down Expand Up @@ -51,7 +50,7 @@ class Beam extends MeshComponent {

final translationMatrix = Matrix4.translation(translation);
final rotationMatrix = _rotateAroundPoint(rotation, start);
final transform = rotationMatrix * translationMatrix;
final transform = rotationMatrix.multiplied(translationMatrix);

return Transform3D.fromMatrix4(transform);
}
Expand All @@ -76,7 +75,9 @@ class Beam extends MeshComponent {
}

static Matrix4 _rotateAroundPoint(Matrix4 rotation, Vector3 point) {
return Matrix4.translation(point) * rotation * Matrix4.translation(-point);
return Matrix4.translation(point)
.multiplied(rotation)
.multiplied(Matrix4.translation(-point));
}

static const _beamRadius = 0.02;
Expand Down
94 changes: 0 additions & 94 deletions lib/components/cylinder_mesh.dart

This file was deleted.

30 changes: 21 additions & 9 deletions lib/components/donut.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'dart:async';

import 'package:flame/geometry.dart';
import 'package:flame_3d/game.dart';
import 'package:flame_3d/resources.dart';
import 'package:defend_the_donut/components/base_component.dart';
import 'package:defend_the_donut/parser/obj_parser.dart';
import 'package:defend_the_donut/utils.dart';
import 'package:flame/geometry.dart';
import 'package:flame_3d/game.dart';
import 'package:flame_3d_extras/parser/model_parser.dart';

enum DonutType {
donut1('objects/donuts/donut_1.obj');
donut1('objects/donuts/donut_1.obj'),
donut2('objects/donuts/donut_2.glb'),
;

final String path;

Expand All @@ -19,14 +20,14 @@ class Donut extends BaseComponent {
final DonutType type;
late Vector3 _rotationAxis;

Donut({
Donut._({
required this.type,
required super.position,
}) : super(mesh: Mesh());
required super.model,
});

@override
FutureOr<void> onLoad() async {
await ObjParser.parse(type.path, applyTo: mesh);
transform.scale = Vector3.all(150.0);
transform.rotation = Quaternion.euler(
random.nextDouble() * tau,
Expand All @@ -46,6 +47,17 @@ class Donut extends BaseComponent {
final dr = Quaternion.axisAngle(_rotationAxis, angle);
transform.rotation = transform.rotation * dr;
}

static const _rotationSpeed = 0.2;

static Future<Donut> donut({
required Vector3 position,
}) async {
final type = DonutType.values.first;
return Donut._(
type: type,
position: position,
model: await ModelParser.parse(type.path),
);
}
}
Loading

0 comments on commit c673e36

Please sign in to comment.