RafaelBarbosatec / bonfire

(RPG maker) Create RPG-style or similar games more simply with Flame.
https://bonfire-engine.github.io
MIT License
1.27k stars 190 forks source link

[question]: how to make breakable block #466

Closed shinriyo closed 6 months ago

shinriyo commented 1 year ago

How can we help?

I want to add ColumnDecoration to the breakable feature in the example.

When the player attacks the object, it will be broken.

I want a similar feature that can be attached to the GameDecoration extended class.

And I want the feature which respawns again with time count.

RafaelBarbosatec commented 1 year ago

Hi @shinriyo ! You can use de Mixin Attackable in your game decoration. Wen die (this method is called when your life is equal 0). You can remove this component

shinriyo commented 1 year ago

Thank you. I will try. Don't close the ticket until doing it.

shinriyo commented 1 year ago

I wanted to set only 1 life

  @override
  void initialLife(double life) {
    super.initialLife(1);
  }

but it wasn't make sense.

finally, I did like the below. Is it in accordance with your design intent?

class ColumnDecoration extends GameDecoration with Attackable {
  ColumnDecoration(Vector2 position)
      : super.withSprite(
          sprite: CommonSpriteSheet.venderMachine,
          position: position,
          size: Vector2(DungeonMap.tileSize, DungeonMap.tileSize),
        ) {
    // I added here
    initialLife(1);
  }
RafaelBarbosatec commented 1 year ago

Yeah, is it. Set the initial life in the constructor.

shinriyo commented 1 year ago

@RafaelBarbosatec

isVisible has no effect. It momentarily is invisible, but it becomes visible again.

  @override
  void die() {
    super.die();

    isVisible = false;
  }
RafaelBarbosatec commented 1 year ago

Hi @shinriyo ! Yes, there is a routine that update this variable. Why can you set isVisible = false?

shinriyo commented 1 year ago

because, I want to hide the object

RafaelBarbosatec commented 1 year ago

You can create you won variable to control call or not the super.render . Or only change the opacity. The variable isVisible is used to control if that component position is visible in camera

RafaelBarbosatec commented 1 year ago

You can do it

bool myIsVisible = true;

  @override
  bool get isVisible => myIsVisible ? super.isVisible : false;
shinriyo commented 1 year ago

I tried but I couldn't resolve.

What I want to do is to disappear a few minit and revive like the block of the game. https://www.youtube.com/live/J9xl0Jt6ohw?si=v-7AppwX_3WOsg_H&t=397


  bool myIsVisible = true;

  @override
  bool get isVisible => myIsVisible ? super.isVisible : false;

  @override
  void initialLife(double life) {
    super.initialLife(1);
  }

  @override
  void die() {
    super.die();

    myIsVisible = false;
    stopFiveSeconds();
  }

  Future<void> stopFiveSeconds() async {
    while (true) {
      await Future.delayed(const Duration(seconds: 5));
      revive();
      myIsVisible = true;
    }
  }
RafaelBarbosatec commented 1 year ago

Got it.on second thought what you did do make sense. I will rename the isVisible to isVisibleInCamera and create a bool variable named 'visible' to control if render or not the component. Remembering that setting visible=false is not disable the block movement collision.

shinriyo commented 1 year ago

I didn't need while (true).

How to disable collision?

RafaelBarbosatec commented 1 year ago

In the next Bonfire version (it will release maybe tomorrow ). isVisible = false will works. To disable BlockMovementCollision just do override in onBlockMovement and return false. So, if you want disable collision when isVisible == false, just do it:

@override
bool onBlockMovement(
    Set<Vector2> intersectionPoints,
    GameComponent other,
  ) {
    return isVisible;
  }
shinriyo commented 1 year ago

In the next Bonfire version (it will release maybe tomorrow ). isVisible = false will works.

Thank you! I am waiting.

To disable BlockMovementCollision just do override in onBlockMovement and return false.

I added with BlockMovementCollision for ColumnDecoration class. It has many override methods. but I also added Movement class. I resolved it.

But, when myIsVisible = true and it appears again, It appears strange in position.

RafaelBarbosatec commented 1 year ago

Version 3.0.7 available

shinriyo commented 1 year ago

3.0.7 is newer than develop branch?

RafaelBarbosatec commented 1 year ago

Is the same code

shinriyo commented 1 year ago

I changed. But, I didn't attach Pushable to ColumnDecoration class, but I can push it.

class ColumnDecoration extends GameDecoration
    with Movement, BlockMovementCollision, Attackable {

And, the barrel shouldn't have moved diagonally, but it did.

class BarrelDraggable extends GameDecoration
    with Movement, BlockMovementCollision, Pushable {
RafaelBarbosatec commented 1 year ago

I think that your ColumnDecoration don't need have BlockMovementCollision, just adds a shapehitbox.

Why your barrel shouldn't move in diagonal?

RafaelBarbosatec commented 1 year ago

I will fix this unwanted push.

shinriyo commented 1 year ago

I think that your ColumnDecoration doesn't need to have BlockMovementCollision, just adds a shapehitbox.

I replaced BlockMovementCollision with ShapeHitbox. There are a lot of must fix

Screenshot 2023-11-14 at 9 43 41

Why your barrel shouldn't move diagonally?

Because I want to make a tile-based game.

RafaelBarbosatec commented 1 year ago

No, i'm sorry. The shapeHitbox that I said was adds a children collision:

@override
Future onLoad(){
add(RectangleHitbox());
}

Just add a collision without mixin BlockMovementCollision

shinriyo commented 1 year ago

I removed BlockMovementCollision from with and a onBlockMovement method. And I added your onLoad's source code. I resolved the phenomenon of pushing it.