Skip to content

Commit

Permalink
added some backend
Browse files Browse the repository at this point in the history
  • Loading branch information
fauwara committed Sep 25, 2021
1 parent 2e165da commit 5189a2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
14 changes: 12 additions & 2 deletions backend/lb.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var express = require('express');
var router = express.Router();

// define the home page route
// json parser
router.use(express.json());

router.get('/', function (req, res) {
res.send('');
res.send('hello');
});

// define the home page route
router.post('/', function (req, res) {
res.send({
name: req.body.name,
score: req.body.score,
});
});

module.exports = router;
26 changes: 21 additions & 5 deletions game/js/endScene.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
class endScene extends Phaser.Scene {

constructor() {
super("endScene");
}

init(data) {
this.user = data;
}

create() {
this.add.text(20, 20, "Game Over ahahahhaha NOOOB");
// let playButton = this.physics.add.image(config.width/2, config.height/2, "player");

this.add.text(20, 20, `Game Over ahahahhaha NOOOB EVEN MY GRANDMOM CAN SCORE MORE THAN ${this.user.score}`);
let playButton = this.add.rectangle(config.width/2, config.height/2, 250, 75, 0x2ECC71);
// console.log(getCenter(playButton));
// playButton.setStrokeStyle(3, 0x2ECC71);
console.log(playButton.x);

console.log(this.user);

fetch("http://localhost:5000/lb/", {
method: "POST",
body: JSON.stringify({
name: this.user.name,
score: this.user.score,
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(res => res.json())
.then(json => console.log(json));

this.add.text(playButton.x - playButton.width/4, playButton.y - playButton.height/4, "PLAY AGAIN");

Expand Down
10 changes: 6 additions & 4 deletions game/js/mainGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class mainGame extends Phaser.Scene {

// timed events
this.time.addEvent({ delay: 9000, callback: this.ghostAppears, callbackScope: this, loop: true });
this.time.addEvent({ delay: 5000, callback: this.ghostShoot, callbackScope: this, loop: true });
this.time.addEvent({ delay: 1000, callback: this.ghostShoot, callbackScope: this, loop: true });
this.time.addEvent({ delay: 3000, callback: this.incScore, callbackScope: this, loop: true});

this.distance = Phaser.Math.Distance.Between(
Expand All @@ -71,9 +71,11 @@ class mainGame extends Phaser.Scene {

this.health = 5;
this.user.score = 0;

// set text to screen
this.scoreLabel = this.add.text(10, 10, `SCORE ${this.user.score}`, { font: '30px Courier', fill: '#00ff00' });
this.healthLabel = this.add.text(10, 40, `HEALTH ${this.health}`, { font: '30px Courier', fill: '#00ff00' });
this.userLabel = this.add.text(10, 10, `WE HAVE A NEWW CHALLLENGER: ${this.user.name}`, { font: '30px Courier', fill: '#00ff00' });
this.scoreLabel = this.add.text(10, 40, `SCORE ${this.user.score}`, { font: '30px Courier', fill: '#00ff00' });
this.healthLabel = this.add.text(10, 70, `HEALTH ${this.health}`, { font: '30px Courier', fill: '#00ff00' });

// this.physics.add.collider(player, this.ghosts, hurt);

Expand All @@ -86,7 +88,7 @@ class mainGame extends Phaser.Scene {
// else{
// window.location.reload();
// }
this.scene.start("endScene");
this.scene.start("endScene", this.user);
}

this.ghostFlip();
Expand Down

0 comments on commit 5189a2c

Please sign in to comment.