Skip to content
Snippets Groups Projects
Select Git revision
  • 6ef9c245b9de3fed7ede998286e0462476806174
  • main default protected
2 results

bricks.ts

Blame
  • Forked from jeremy.gobet / breakout
    Source project has a limited visibility.
    bricks.ts 1.03 KiB
    // https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObject.html
    import GameObject = Phaser.GameObjects.GameObject;
    
    export default class Bricks extends Phaser.GameObjects.GameObject {
    
      group: Phaser.Physics.Arcade.StaticGroup;
      
      constructor(scene: Phaser.Scene) {
        super(scene, "bricks");
    
        this.create();
      }
    
      create() {
        //  Création des briques dans une grille de 10x6
        this.group = this.scene.physics.add.staticGroup({
          key: 'assets', frame: [ 'blue1', 'red1', 'green1', 'yellow1', 'silver1', 'purple1' ],
          frameQuantity: 10,
          gridAlign: { width: 10, height: 6, cellWidth: 64, cellHeight: 32, x: 112, y: 100 }
        });
      }
    
      reset() {
        this.group.children.entries.forEach((brick: Phaser.Physics.Arcade.Image) => {
          brick.enableBody(false, 0, 0, true, true);
        })
      }
    
      hitBrick(ball: Phaser.Physics.Arcade.Image, brick: Phaser.Physics.Arcade.Image) {
        brick.disableBody(true, true);
    
        if (this.group.countActive() === 0)
        {
          this.emit("allBricksDestroyedEvent");
        }
      }
    };