Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.9.8 #544

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.9.8
- Fix bug when hitbox anchor is center.
- BREAKING CHANGE: Update `bool receiveDamage` to `void onReceiveDamage`. Now to perform receive of attack use `handleAttack` method.

# 3.9.7
- Update `tiledjsonreader`
- Bugfix/tile rotation collision. [#535](https://github.com/RafaelBarbosatec/bonfire/pull/535)
Expand Down
7 changes: 6 additions & 1 deletion example/lib/pages/player/simple/human.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ class HumanPlayer extends SimplePlayer with BlockMovementCollision {
@override
Future<void> onLoad() {
/// Adds rectangle collision
add(RectangleHitbox(size: size / 2, position: size / 4));
add(
RectangleHitbox(
size: size / 2,
position: size / 4,
),
);
return super.onLoad();
}
}
4 changes: 2 additions & 2 deletions example/lib/shared/decoration/spikes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Spikes extends GameDecoration with Sensor<Attackable> {
@override
void onContact(Attackable component) {
if (component is Player) {
component.receiveDamage(AttackOriginEnum.ENEMY, 10, 1);
component.handleAttack(AttackOriginEnum.ENEMY, 10, 1);
} else {
component.receiveDamage(AttackOriginEnum.PLAYER_OR_ALLY, 10, 1);
component.handleAttack(AttackOriginEnum.PLAYER_OR_ALLY, 10, 1);
}
}
}
6 changes: 3 additions & 3 deletions lib/collision/block_movement_collision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ mixin BlockMovementCollision on Movement {

if (_bodyType.isDynamic) {
Vector2 correction;
double depth = collisionData.depth;
if (depth != 0) {
depth = collisionData.depth.abs() + 0.08;
double depth = collisionData.depth.abs();
if (depth > 0) {
depth += 0.08;
}

correction = (-collisionData.normal * depth);
Expand Down
2 changes: 1 addition & 1 deletion lib/collision/collision_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ final _cachedGlobalVertices = ValueCache<List<Vector2>>();

extension PolygonComponentExt on PolygonComponent {
List<Vector2> get absoluteVertices {
final Vector2 p = absolutePosition;
final Vector2 p = absoluteTopLeftPosition;
final adjustedVerticies =
absoluteAngle == 0 ? vertices : rotatedVerticesBonfire(absoluteAngle);

Expand Down
29 changes: 23 additions & 6 deletions lib/mixins/attackable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ mixin Attackable on GameComponent {

double get life => _life;

/// Set initial life
void initialLife(double life) {
_life = life;
_maxLife = life;
}

/// increase life
/// Increase life
void addLife(double life) {
double newLife = _life + life;

Expand All @@ -43,6 +44,7 @@ mixin Attackable on GameComponent {
_verifyLimitsLife();
}

// Update life
void updateLife(double life, {bool verifyDieOrRevive = true}) {
_life = life;
if (verifyDieOrRevive) {
Expand All @@ -62,7 +64,10 @@ mixin Attackable on GameComponent {
_verifyLimitsLife();
}

// Called when life is removed
void onRemoveLife(double life) {}

// Called when life is restored
void onRestoreLife(double life) {}

void _verifyLimitsLife() {
Expand All @@ -75,16 +80,25 @@ mixin Attackable on GameComponent {

/// This method is called to give damage a this component.
/// Only receive damage if the method [checkCanReceiveDamage] return `true`.
bool receiveDamage(
bool handleAttack(
AttackOriginEnum attacker,
double damage,
dynamic identify,
) {
if (checkCanReceiveDamage(attacker)) {
removeLife(damage);
return true;
final canReceive = checkCanReceiveDamage(attacker);
if (canReceive) {
onReceiveDamage(attacker, damage, identify);
}
return false;
return canReceive;
}

// Called when the component receives damage
void onReceiveDamage(
AttackOriginEnum attacker,
double damage,
dynamic identify,
) {
removeLife(damage);
}

/// This method is used to check if this component can receive damage from any attacker.
Expand Down Expand Up @@ -112,15 +126,18 @@ mixin Attackable on GameComponent {
return false;
}

// Called when the component dies
void onDie() {
_isDead = true;
}

// Called when the component revives
void onRevive() {
_isDead = false;
}

bool get isDead => _isDead;

// Get rect collision of the component used to receive damage
Rect rectAttackable() => rectCollision;
}
2 changes: 1 addition & 1 deletion lib/objects/flying_attack_game_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class FlyingAttackGameObject extends AnimatedGameObject
@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
if (other is Attackable && animationDestroy == null) {
other.receiveDamage(attackFrom, damage, id);
other.handleAttack(attackFrom, damage, id);
}
if (other is GameComponent) {
_destroyObject(other);
Expand Down
2 changes: 1 addition & 1 deletion lib/util/damage_hitbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DamageHitbox extends GameComponent {
.attackables(onlyVisible: true)
.where((a) => a.rectAttackable().overlaps(toAbsoluteRect()))
.forEach((attackable) {
final receiveDamage = attackable.receiveDamage(origin, damage, id);
final receiveDamage = attackable.handleAttack(origin, damage, id);
if (receiveDamage) {
onDamage?.call(attackable);
}
Expand Down
2 changes: 1 addition & 1 deletion 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.9.7
version: 3.9.8
homepage: https://bonfire-engine.github.io
repository: https://github.com/RafaelBarbosatec/bonfire
issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues
Expand Down
Loading