-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- GitHub button - Fix bug with stopwatch - Refactor logic of labels in new class - Add some comments
- Loading branch information
Showing
9 changed files
with
219 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,7 @@ main { | |
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#game-controls { | ||
margin: 0 auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GameObjects, Scene } from 'phaser'; | ||
|
||
interface ILabelProps { | ||
scene: Scene; | ||
x: number; | ||
y: number; | ||
text: string; | ||
nameKey: string; | ||
} | ||
|
||
export class Label extends GameObjects.Text { | ||
constructor({ scene, x, y, text, nameKey }: ILabelProps) { | ||
super(scene, x, y, text, {}); | ||
|
||
this.name = nameKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { GameObjects, Scene } from 'phaser'; | ||
|
||
// Interfaces | ||
import { IGameInitialData } from '@src/game/common/interfaces/IGameInitialData'; | ||
|
||
// Controls | ||
import { Label } from '@src/game/controls/label/Label'; | ||
|
||
interface ILabelGroupProps { | ||
scene: Scene; | ||
gameData: IGameInitialData; | ||
} | ||
|
||
export class LabelGroup extends GameObjects.Group { | ||
private _gameData: IGameInitialData; | ||
|
||
constructor({ scene, gameData }: ILabelGroupProps) { | ||
super(scene); | ||
|
||
this._gameData = gameData; | ||
|
||
this.classType = Label; | ||
|
||
this._setUp(); | ||
} | ||
|
||
private _setUp() { | ||
const style = { | ||
font: '15px BitBold', | ||
fill: 'white', | ||
stroke: 'black', | ||
strokeThickness: 2.5, | ||
}; | ||
|
||
const attempsLabel = new Label({ | ||
scene: this.scene, | ||
x: 50, | ||
y: 22, | ||
text: `MOVEMENTS: ${this._gameData.attemps}`, | ||
nameKey: 'ATTEMPS', | ||
}).setStyle(style); | ||
|
||
this.add(attempsLabel, true); | ||
|
||
const timeLabel = new Label({ | ||
scene: this.scene, | ||
x: 230, | ||
y: 22, | ||
text: 'TIME: 00:00:00', | ||
nameKey: 'TIME', | ||
}).setStyle(style); | ||
|
||
this.add(timeLabel, true); | ||
} | ||
|
||
showEndGameLabel(text: string) { | ||
const stWin = new Label({ | ||
scene: this.scene, | ||
x: this.scene.cameras.main.centerX, | ||
y: 120, | ||
text: text, | ||
nameKey: 'END_TEXT', | ||
}) | ||
.setFontFamily('"BitBold", "Tahoma"') | ||
.setFontSize(20) | ||
.setColor('white') | ||
.setStroke('black', 2.5) | ||
.setAlpha(0) | ||
.setOrigin(0.5); | ||
|
||
this.add(stWin, true); | ||
|
||
this.scene.tweens.add({ | ||
targets: stWin, | ||
props: { | ||
alpha: 1, | ||
}, | ||
ease: 'Sine.easeInOut', | ||
yoyo: true, | ||
repeat: -1, | ||
}); | ||
} | ||
|
||
setTextByKey(keyName: string, value: string) { | ||
const _label = this.getMatching('name', keyName)[0]; | ||
|
||
if (_label) { | ||
(_label as GameObjects.Text).setText(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.