update code

This commit is contained in:
Alexander Popov 2022-11-03 05:45:57 +03:00
parent daac1d5fde
commit 963dbedd21

View File

@ -76,7 +76,7 @@ function initLevel() {
Game.objects.attackButton.y = 300; Game.objects.attackButton.y = 300;
Game.objects.attackButton.interactive = true; Game.objects.attackButton.interactive = true;
Game.objects.attackButton.buttonMode = true; Game.objects.attackButton.cursor = 'pointer';
Game.objects.attackButton.on('click', (event) => { Game.objects.attackButton.on('click', (event) => {
if (Game.enemyHp >= 10) if (Game.enemyHp >= 10)
Game.enemyHp -= 10; Game.enemyHp -= 10;
@ -84,12 +84,20 @@ function initLevel() {
Game.enemyHp = 100; Game.enemyHp = 100;
}); });
Game.objects.buttonText = new PIXI.Text('Attack!');
Game.objects.buttonText.style.fontSize = 30;
Game.objects.buttonText.style.fontStyle = 'bold';
Game.objects.buttonText.anchor.set(0.5);
Game.objects.buttonText.x = app.screen.width / 2;
Game.objects.buttonText.y = Game.objects.attackButton.y - 4;
Game.objects.fillContainer.addChild(Game.objects.hpFill); Game.objects.fillContainer.addChild(Game.objects.hpFill);
app.stage.addChild(Game.objects.hpBar); app.stage.addChild(Game.objects.hpBar);
app.stage.addChild(Game.objects.fillContainer); app.stage.addChild(Game.objects.fillContainer);
app.stage.addChild(Game.objects.label); app.stage.addChild(Game.objects.label);
app.stage.addChild(Game.objects.hpText); app.stage.addChild(Game.objects.hpText);
app.stage.addChild(Game.objects.attackButton); app.stage.addChild(Game.objects.attackButton);
app.stage.addChild(Game.objects.buttonText);
app.ticker.add(gameLoop); app.ticker.add(gameLoop);
} }
@ -103,7 +111,7 @@ function gameLoop(delta) {
.beginFill(0xffffff) .beginFill(0xffffff)
.drawRect(Game.objects.hpFill.x - (Game.objects.hpFill.width / 2), .drawRect(Game.objects.hpFill.x - (Game.objects.hpFill.width / 2),
Game.objects.hpFill.y - (Game.objects.hpFill.height / 2), Game.objects.hpFill.y - (Game.objects.hpFill.height / 2),
(Game.enemyHp * Game.objects.hpFill.width / 100), Game.enemyHp * Game.objects.hpFill.width / 100,
Game.objects.hpFill.height) Game.objects.hpFill.height)
.endFill(); .endFill();
} }