Skip to content
Snippets Groups Projects
Commit ad694c97 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

refactor: #fe clue placement bounds

parent 439697cf
No related branches found
No related tags found
No related merge requests found
...@@ -15,10 +15,11 @@ class Clue extends Phaser.GameObjects.Sprite { ...@@ -15,10 +15,11 @@ class Clue extends Phaser.GameObjects.Sprite {
word: Types.Word; word: Types.Word;
scene: FightScene; scene: FightScene;
textureKey: string; textureKey: string;
body: Phaser.Physics.Arcade.Body;
constructor(scene: FightScene, word: Types.Word) { constructor(scene: FightScene, word: Types.Word) {
// TODO: set positions // TODO: set positions
super(scene, 400, 300, "__MISSING"); super(scene, 0, 0, "__MISSING");
scene.add.existing(this); scene.add.existing(this);
this.setAlpha(0); this.setAlpha(0);
...@@ -63,13 +64,18 @@ class Clue extends Phaser.GameObjects.Sprite { ...@@ -63,13 +64,18 @@ class Clue extends Phaser.GameObjects.Sprite {
this.body = new Phaser.Physics.Arcade.Body(this.scene.physics.world, this); this.body = new Phaser.Physics.Arcade.Body(this.scene.physics.world, this);
this.scene.physics.world.add(this.body); this.scene.physics.world.add(this.body);
this.scene.cluesGroup.add(this); this.scene.cluesGroup.add(this);
this.setPositionForDrop();
this.fadeIn();
}
setPositionForDrop() {
const bounds = this.body.customBoundsRectangle;
const x = const x =
(this.scene.cameras.main.width - this.width - 10) * Math.random() + bounds.left +
5 + this.displayWidth * 0.5 +
this.width / 2; Math.random() * (bounds.width - this.displayWidth);
this.setPosition(x, 50); const y = bounds.top + this.displayHeight * 0.5;
this.fadeIn(); this.setPosition(x, y);
} }
delete() { delete() {
......
...@@ -265,9 +265,9 @@ export default class FightScene extends Phaser.Scene { ...@@ -265,9 +265,9 @@ export default class FightScene extends Phaser.Scene {
initCluesGroup() { initCluesGroup() {
const bounds = new Phaser.Geom.Rectangle( const bounds = new Phaser.Geom.Rectangle(
0, 4,
0, 4,
this.cameras.main.width, this.cameras.main.width - 8,
this.cameras.main.height / 2, this.cameras.main.height / 2,
); );
this.cluesGroup = this.physics.add.group({ this.cluesGroup = this.physics.add.group({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment