Save record on server
This commit is contained in:
parent
a38072214e
commit
a575d447f9
9 changed files with 68 additions and 36 deletions
40
game/package-lock.json
generated
40
game/package-lock.json
generated
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "hs3jam-miner",
|
||||
"name": "hs3jam-space-smasher-9001",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hs3jam-miner",
|
||||
"name": "hs3jam-space-smasher-9001",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
@ -1785,9 +1785,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz",
|
||||
"integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==",
|
||||
"version": "7.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
|
||||
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/q": {
|
||||
|
|
@ -4768,9 +4768,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/glob-parent": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
|
||||
"integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"is-glob": "^4.0.1"
|
||||
|
|
@ -5788,9 +5788,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/is-promise": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
|
||||
"integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/is-regex": {
|
||||
|
|
@ -11281,9 +11281,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz",
|
||||
"integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==",
|
||||
"version": "7.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
|
||||
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/q": {
|
||||
|
|
@ -13762,9 +13762,9 @@
|
|||
}
|
||||
},
|
||||
"glob-parent": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
|
||||
"integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-glob": "^4.0.1"
|
||||
|
|
@ -14543,9 +14543,9 @@
|
|||
}
|
||||
},
|
||||
"is-promise": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
|
||||
"integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==",
|
||||
"dev": true
|
||||
},
|
||||
"is-regex": {
|
||||
|
|
|
|||
|
|
@ -33,5 +33,13 @@ export default {
|
|||
|
||||
async login(key: string) {
|
||||
return this.post("login", { key })
|
||||
}
|
||||
},
|
||||
|
||||
async record(points: number, shoots: number, time: number) {
|
||||
return this.post("record", {
|
||||
points,
|
||||
shoots,
|
||||
time
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ export default class Bullets extends Phaser.Physics.Arcade.Group {
|
|||
if (bullet && this.lastShoot + this.cooldown <= time) {
|
||||
bullet.fire(shooter.x, shooter.y, shooter.rotation)
|
||||
this.lastShoot = time
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export default class Ship extends Phaser.Physics.Arcade.Sprite {
|
|||
bullets: Bullets
|
||||
thruster: Thruster
|
||||
life = 3
|
||||
shoots = 0
|
||||
|
||||
constructor(scene: Phaser.Scene) {
|
||||
super(
|
||||
|
|
@ -56,8 +57,10 @@ export default class Ship extends Phaser.Physics.Arcade.Sprite {
|
|||
if (keyRight.isDown) vec.x = this.acceleration
|
||||
if (keyLeft.isDown) vec.x = -this.acceleration
|
||||
|
||||
if (this.scene.input.activePointer.leftButtonDown())
|
||||
this.bullets!.fireBullet(time, this);
|
||||
if (this.scene.input.activePointer.leftButtonDown()) {
|
||||
if (this.bullets!.fireBullet(time, this))
|
||||
this.shoots++
|
||||
}
|
||||
|
||||
this.rotation = Phaser.Math.Angle.BetweenPoints(
|
||||
this,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ declare global {
|
|||
key?: String | null,
|
||||
record?: String | null,
|
||||
}
|
||||
freezeGui: Function,
|
||||
unfreezeGui: Function
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +28,18 @@ declare global {
|
|||
key: document.getElementById("key"),
|
||||
}
|
||||
|
||||
window.freezeGui = () => {
|
||||
(elements.buttons.login as HTMLButtonElement).disabled = true;
|
||||
(elements.buttons.logout as HTMLButtonElement).disabled = true;
|
||||
(elements.buttons.signup as HTMLButtonElement).disabled = true;
|
||||
}
|
||||
|
||||
window.unfreezeGui = () => {
|
||||
(elements.buttons.login as HTMLButtonElement).disabled = false;
|
||||
(elements.buttons.logout as HTMLButtonElement).disabled = false;
|
||||
(elements.buttons.signup as HTMLButtonElement).disabled = false;
|
||||
}
|
||||
|
||||
function readDataFromToken(token) {
|
||||
return JSON.parse(
|
||||
atob(token.split('.')[1])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import Phaser from 'phaser'
|
||||
import API from "../api"
|
||||
|
||||
export default class PlayScene extends Phaser.Scene {
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ export default class PlayScene extends Phaser.Scene {
|
|||
this.load.image('hs3-logo', 'assets/img/hs3-logo.png')
|
||||
}
|
||||
|
||||
create(data) {
|
||||
async create(data) {
|
||||
console.log("Show end screen with data:", data)
|
||||
|
||||
this.add.image(250, 550, 'phaser-logo').setScale(0.5)
|
||||
|
|
@ -27,6 +28,7 @@ export default class PlayScene extends Phaser.Scene {
|
|||
const rank = 0
|
||||
const pts = data.points || 0
|
||||
const lvl = data.level || 0
|
||||
const shts = data.shoots || 0
|
||||
const time = Math.ceil(data.elapsedTime || 0)
|
||||
|
||||
this.add.text(this.cameras.main.centerX, this.cameras.main.centerY, [
|
||||
|
|
@ -39,5 +41,9 @@ export default class PlayScene extends Phaser.Scene {
|
|||
align: 'center',
|
||||
color: 'cyan'
|
||||
}).setOrigin(0.5, 0.5)
|
||||
|
||||
if (window.myStuff.token)
|
||||
await API.record(pts, shts, time)
|
||||
window.unfreezeGui()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ export default class PlayScene extends Phaser.Scene {
|
|||
backgroundOrder: number[] = []
|
||||
backgroundId = 0
|
||||
startTimestamp: number = 0
|
||||
auth: any
|
||||
|
||||
constructor() {
|
||||
super('play-scene')
|
||||
|
|
@ -36,10 +35,7 @@ export default class PlayScene extends Phaser.Scene {
|
|||
this.load.multiatlas('asteroids', 'assets/img/asteroids.json', 'assets/img');
|
||||
}
|
||||
|
||||
create(data) {
|
||||
console.log("Started game with", data)
|
||||
this.auth = data
|
||||
|
||||
create() {
|
||||
Asteroid.createAnimations(this)
|
||||
this.difficulty = new DifficultyManager(this)
|
||||
this.events.on('getpoint', this.updateLabel, this)
|
||||
|
|
@ -69,7 +65,8 @@ export default class PlayScene extends Phaser.Scene {
|
|||
this.scene.start('game-over-scene', {
|
||||
points: this.difficulty!.getPoints(),
|
||||
level: this.difficulty!.getLevel(),
|
||||
elapsedTime: (this.time.now - this.startTimestamp) / 1000
|
||||
elapsedTime: (this.time.now - this.startTimestamp) / 1000,
|
||||
shoots: this.player!.shoots
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ export default class StartScene extends Phaser.Scene {
|
|||
}).setOrigin(0.5, 0.5)
|
||||
|
||||
this.input.on('pointerup', () => {
|
||||
this.scene.start('play-scene', window.myStuff);
|
||||
window.freezeGui()
|
||||
this.scene.start('play-scene');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import cors from 'cors'
|
|||
|
||||
import auth from './Auth.js'
|
||||
import db from './Database.js'
|
||||
import jg from './JusticeGuard'
|
||||
import jg from './JusticeGuard.js'
|
||||
|
||||
const protect = (req, res, next) => {
|
||||
const authHeader = req.headers.authorization;
|
||||
|
|
@ -76,7 +76,7 @@ app.post("/login", neededArguments(['key']), async (req, res) => {
|
|||
res.json(user)
|
||||
})
|
||||
|
||||
app.post("/record", neededArguments(['points', 'shoots', 'time']), jg, async (req, res) => {
|
||||
app.post("/record", protect, neededArguments(['points', 'shoots', 'time']), jg, async (req, res) => {
|
||||
db.updateRecord(req.user.name, req.body.points)
|
||||
|
||||
res.json({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue