Skip to content

Commit

Permalink
Merge pull request #453 from RafaelBarbosatec/develop
Browse files Browse the repository at this point in the history
Version 3.0.3
  • Loading branch information
RafaelBarbosatec authored Oct 23, 2023
2 parents 74b8b13 + a1ec43c commit 552f9db
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 52 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.3
- Now all Tile in the map have you own Paint.
- Update `tiledjsonreader` to `1.3.3`.
- Tiled improvements : Now if you set the class of objectlayer to `collision`, all object of this layer will be collision.
- Adds param `resolution` in `CameraConfig`.

## 3.0.2
- `BleedingPixel` improvements.
- Adds `orientation` param in `getZoomFromMaxVisibleTile`.
Expand Down
1 change: 0 additions & 1 deletion example/assets/images/platform/simple_map_gem.tmj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"y":0
},
{
"class":"collision",
"draworder":"topdown",
"id":2,
"name":"objects",
Expand Down
9 changes: 0 additions & 9 deletions example/assets/images/tiled/punnyworld/punyworld_tileset.tsj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -44,7 +43,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -70,7 +68,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -96,7 +93,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -122,7 +118,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -148,7 +143,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -174,7 +168,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand All @@ -200,7 +193,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand Down Expand Up @@ -526,7 +518,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
Expand Down
4 changes: 2 additions & 2 deletions example/assets/images/tiled/punnyworld/simple_map.tmj
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"x":0,
"y":0
}],
"nextlayerid":4,
"nextobjectid":3,
"nextlayerid":5,
"nextobjectid":7,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.9.0",
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/enemy/melee_enemy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MeleeEnemy extends SimpleEnemy {
Future<void> onLoad() {
/// Adds rectangle collision
add(RectangleHitbox(size: size / 2, position: size / 4));
animation?.showStroke(Colors.white, 1);
_addsText();
return super.onLoad();
}
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/player/simple/simple_player_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SimplePlayerPage extends StatelessWidget {
),
cameraConfig: CameraConfig(
zoom: getZoomFromMaxVisibleTile(context, tileSize, 20),
speed: 5,
),
backgroundColor: const Color(0xff20a0b4),
);
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.1"
version: "3.0.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -435,10 +435,10 @@ packages:
dependency: transitive
description:
name: tiledjsonreader
sha256: "752c81fb93932fbd891369b955ab8bd90568fbd2e00cf3a1863b4a8829f82674"
sha256: "2fe265c0a47b81dff2ea900d6c3c915046c0d7a7347cfc812f3ddff1da914773"
url: "https://pub.dev"
source: hosted
version: "1.3.2"
version: "1.3.3"
typed_data:
dependency: transitive
description:
Expand Down
7 changes: 6 additions & 1 deletion lib/base/bonfire_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:bonfire/color_filter/color_filter_component.dart';
import 'package:bonfire/joystick/joystick_map_explorer.dart';
import 'package:bonfire/lighting/lighting_component.dart';
// ignore: implementation_imports
import 'package:flame/src/camera/viewports/fixed_resolution_viewport.dart';
// ignore: implementation_imports
import 'package:flutter/widgets.dart';

/// Is a customGame where all magic of the Bonfire happen.
Expand Down Expand Up @@ -116,7 +118,10 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
}) : globalForces = globalForces ?? [],
super(
camera: BonfireCamera(
config: cameraConfig ?? CameraConfig(),
config: cameraConfig,
viewport: cameraConfig?.resolution != null
? FixedResolutionViewport(resolution: cameraConfig!.resolution!)
: null,
hudComponents: [
LightingComponent(
color: lightingColorGame ?? const Color(0x00000000),
Expand Down
6 changes: 6 additions & 0 deletions lib/base/game_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,10 @@ abstract class GameComponent extends PositionComponent
return [];
}
}

@override
void onMount() {
paint.isAntiAlias = false;
super.onMount();
}
}
17 changes: 8 additions & 9 deletions lib/camera/bonfire_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class BonfireCamera extends CameraComponent with BonfireHasGameRef {
double _spacingMap = 32.0;
final CameraConfig config;
BonfireCamera({
required this.config,
CameraConfig? config,
super.world,
super.hudComponents,
super.viewport,
}) {
if (config.initPosition != null) {
position = config.initPosition!;
}) : config = config ?? CameraConfig() {
if (this.config.initPosition != null) {
position = this.config.initPosition!;
}
viewfinder.zoom = config.zoom;
viewfinder.angle = config.angle;
if (config.target != null) {
follow(config.target!, snap: true);
viewfinder.zoom = this.config.zoom;
viewfinder.angle = this.config.angle;
if (this.config.target != null) {
follow(this.config.target!, snap: true);
}
}

Expand Down Expand Up @@ -137,7 +137,6 @@ class BonfireCamera extends CameraComponent with BonfireHasGameRef {
viewfinder.add(
MyFollowBehavior(
target: target,
owner: viewfinder,
maxSpeed: config.speed,
movementWindow: config.movementWindow,
horizontalOnly: horizontalOnly,
Expand Down
3 changes: 3 additions & 0 deletions lib/camera/camera_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CameraConfig {

final Vector2? initPosition;

final Vector2? resolution;

CameraConfig({
this.moveOnlyMapArea = false,
this.startFollowPlayer = true,
Expand All @@ -38,5 +40,6 @@ class CameraConfig {
this.initialMapZoomFit = InitialMapZoomFitEnum.none,
this.initPosition,
Vector2? movementWindow,
this.resolution,
}) : movementWindow = movementWindow ?? movementWindowDefault;
}
3 changes: 1 addition & 2 deletions lib/camera/camera_effects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class MyFollowBehavior extends FollowBehavior {
MyFollowBehavior({
required super.target,
required this.movementWindow,
PositionProvider? owner,
super.maxSpeed = double.infinity,
super.horizontalOnly = false,
super.verticalOnly = false,
Expand All @@ -30,7 +29,7 @@ class MyFollowBehavior extends FollowBehavior {

if (delta.isZero()) return;
if (delta.length <= maxSpeed * dt) {
owner.position = owner.position.clone()..add(delta);
owner.position = delta..add(owner.position);
} else {
owner.position = owner.position.clone()
..lerp(owner.position + delta, dt * maxSpeed);
Expand Down
4 changes: 1 addition & 3 deletions lib/map/base/map_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ abstract class GameMap extends GameComponent {
double tileSizeToUpdate;
double tileSize = 0.0;

GameMap(this.tiles, {this.tileSizeToUpdate = 0}) {
paint.isAntiAlias = false;
}
GameMap(this.tiles, {this.tileSizeToUpdate = 0});

Iterable<Tile> getRendered();

Expand Down
8 changes: 0 additions & 8 deletions lib/map/base/tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ class Tile extends GameComponent with UseAssetsLoader {
await _animation?.onLoad();
}

@override
void onMount() {
if (opacity == (parent as HasPaint?)?.opacity) {
paint = (parent as HasPaint?)?.paint ?? paint;
}
super.onMount();
}

bool get containAnimation => _animation != null;

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/mixins/bouncing_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:bonfire/bonfire.dart';
// Mixin responsable to give the bounce behavior. (experimental)
mixin BouncingObject on BlockMovementCollision {
final _countFrameCOllisionDiabledAfterBounce = 4;
double _bouncingReflectFactor = 1.01;
double _bouncingReflectFactor = 1.0;
bool _bouncingObjectEnabled = true;
int? _countFrameCollisionStoped;

Expand All @@ -24,7 +24,7 @@ mixin BouncingObject on BlockMovementCollision {
PositionComponent other,
Direction? direction,
) {
if (onBouncingCollision(other) && !isStoped() && _bouncingObjectEnabled) {
if (onBouncingCollision(other) && !isStopped() && _bouncingObjectEnabled) {
if (direction == Direction.left || direction == Direction.right) {
velocity.x = velocity.x * -_bouncingReflectFactor;
} else if (direction == Direction.up || direction == Direction.down) {
Expand Down
4 changes: 2 additions & 2 deletions lib/mixins/movement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ mixin Movement on GameComponent {
}
}

bool isStoped() {
return velocity.x < 0.01 && velocity.y < 0.01;
bool isStopped() {
return velocity.x.abs() < 0.01 && velocity.y.abs() < 0.01;
}

// Move to position. return true whether move.
Expand Down
12 changes: 8 additions & 4 deletions lib/tiled/builder/tiled_world_builder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ignore_for_file: constant_identifier_names

import 'dart:math';
import 'dart:ui';

import 'package:bonfire/background/background_image_game.dart';
Expand Down Expand Up @@ -386,13 +387,15 @@ class TiledWorldBuilder {

void _addObjects(ObjectLayer layer) {
if (layer.visible != true) return;
bool isCollisionLayer = layer.layerClass?.toLowerCase() == 'collision';
double offsetX = _getDoubleByProportion(layer.offsetX);
double offsetY = _getDoubleByProportion(layer.offsetY);
for (var element in layer.objects ?? const <Objects>[]) {
double x = _getDoubleByProportion(element.x) + offsetX;
double y = _getDoubleByProportion(element.y) + offsetY;
double width = _getDoubleByProportion(element.width);
double height = _getDoubleByProportion(element.height);
double rotation = (element.rotation ?? 0) * pi / 180;
final collision = _getCollisionObject(
x,
y,
Expand Down Expand Up @@ -425,9 +428,10 @@ class TiledWorldBuilder {
int.parse('0xFF${element.text!.color.replaceAll('#', '')}'),
),
),
),
)..angle = rotation,
);
} else if (element.typeOrClass?.toLowerCase() == 'collision') {
} else if (element.typeOrClass?.toLowerCase() == 'collision' ||
isCollisionLayer) {
_components.add(
CollisionGameComponent(
name: element.name ?? '',
Expand All @@ -437,15 +441,15 @@ class TiledWorldBuilder {
collision..position = Vector2.zero(),
],
properties: _extractOtherProperties(element.properties),
),
)..angle = rotation,
);
} else if (_objectsBuilder[element.name] != null) {
final object = _objectsBuilder[element.name]?.call(
TiledObjectProperties(
Vector2(x, y),
Vector2(width, height),
element.typeOrClass,
element.rotation,
rotation,
_extractOtherProperties(element.properties),
element.name,
element.id,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ packages:
dependency: "direct main"
description:
name: tiledjsonreader
sha256: "752c81fb93932fbd891369b955ab8bd90568fbd2e00cf3a1863b4a8829f82674"
sha256: "2fe265c0a47b81dff2ea900d6c3c915046c0d7a7347cfc812f3ddff1da914773"
url: "https://pub.dev"
source: hosted
version: "1.3.2"
version: "1.3.3"
typed_data:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bonfire
description: (RPG maker) Create RPG-style or similar games more simply with Flame.
version: 3.0.2
version: 3.0.3
homepage: https://bonfire-engine.github.io
repository: https://github.com/RafaelBarbosatec/bonfire
issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues
Expand All @@ -15,7 +15,7 @@ dependencies:
sdk: flutter

flame: ^1.10.0
tiledjsonreader: ^1.3.2
tiledjsonreader: ^1.3.3
http: ^1.1.0
a_star_algorithm: ^0.3.0

Expand Down

0 comments on commit 552f9db

Please sign in to comment.