Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High score #9

Merged
merged 3 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/project.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"webpack-dev-server": "^3.7.2"
},
"dependencies": {
<<<<<<< Updated upstream
"firebase": "^8.4.3",
=======
"lodash": "^4.17.21",
>>>>>>> Stashed changes
"phaser": "^3.18.1"
}
}
37 changes: 31 additions & 6 deletions src/GameScene.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Phaser, { Scene } from "phaser";
import globals from "./globals/index";

class GameScene extends Scene {
// Our constructor is called when the instance of our class is created.
Expand Down Expand Up @@ -29,20 +30,22 @@ class GameScene extends Scene {

// Backdrop + methods.
create() {
const sky = this.add.image(0, 0, "sky");
sky.setOrigin(0, 0);
// const sky = this.add.image(0, 0, "sky");
// sky.setOrigin(0, 0);

this.createPlatforms();
this.createPlayer();
this.createCursor();
this.createStars();
this.createBombs();
this.initGlobalVariables();
this.gameStats();

// The text and CSS for our score text.
this.scoreText = this.add.text(16, 16, "Score: 0", {
fontSize: "32px",
fill: "#000",
});
// this.scoreText = this.add.text(16, 16, "Score: 0", {
// fontSize: "32px",
// fill: "#000",
// });

this.gameOverText = this.add.text(400, 300, "Game Over", {
fontSize: "64px",
Expand All @@ -53,6 +56,28 @@ class GameScene extends Scene {
this.gameOverText.visible = false;
}

initGlobalVariables() {
this.game.global = clone(globals);
}

gameStats() {
this.createText(20, 20, "left", `score: ${this.game.global.score}`);
this.createText(0, 20, "center", `lives: ${this.game.global.lives}`);
this.createText(20, 0, "right", `level: ${this.game.global.level}`);

// this.game.add.text(1, 1, "hello").setTextBounds();
}

createText(xOffset, yOffset, align, text) {
return this.game.add
.text(xOffset, yOffset, text, {
font: "18px Arial",
fill: "#000",
boundsAlignH: align,
})
.setTextBounds(0, 0, this.game.world.width, 0);
}

// staticGroup handles static objects - walls, floors etc.
createPlatforms() {
this.platforms = this.physics.add.staticGroup();
Expand Down
5 changes: 5 additions & 0 deletions src/globals/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
score: 0,
level: 1,
lives: 5,
};