This file contains hidden or 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
explodeAndKill(deadPlayerId) { | |
this.avatars[deadPlayerId].disableBody(true, true); | |
let explosion = new Explosion( | |
this, | |
this.avatars[deadPlayerId].x, | |
this.avatars[deadPlayerId].y | |
); | |
delete this.avatars[deadPlayerId]; | |
document.getElementById("join-leave-updates").innerHTML = | |
players[deadPlayerId].nickname + " died"; |
This file contains hidden or 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
update() { | |
if (gameOn) { | |
if (this.ship.x) { | |
this.ship.x = latestShipPosition; | |
} else { | |
this.ship = this.physics.add | |
.sprite(latestShipPosition, config.height - 32, "ship") | |
.setOrigin(0.5, 0.5); | |
this.ship.x = latestShipPosition; | |
} |
This file contains hidden or 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
create() { | |
this.avatars = {}; | |
this.visibleBullets = {}; | |
this.ship = {}; | |
this.cursorKeys = this.input.keyboard.createCursorKeys(); | |
this.anims.create({ | |
key: "explode", | |
frames: this.anims.generateFrameNumbers("explosion"), | |
frameRate: 20, |
This file contains hidden or 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
const realtime = Ably.Realtime({ | |
authUrl: BASE_SERVER_URL + "/auth", | |
}); | |
realtime.connection.once("connected", () => { | |
myClientId = realtime.auth.clientId; | |
gameRoom = realtime.channels.get("game-room"); | |
deadPlayerCh = realtime.channels.get("dead-player"); | |
myChannel = realtime.channels.get("clientChannel-" + myClientId); | |
gameRoom.presence.enter(myNickname); |
This file contains hidden or 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
let gameRoom; | |
let deadPlayerCh; | |
let myClientId; | |
let myChannel; | |
let gameOn = false; | |
let players = {}; | |
let totalPlayers = 0; | |
let latestShipPosition; | |
let bulletThatShotMe; | |
let bulletThatShotSomeone; |
This file contains hidden or 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
function randomAvatarSelector() { | |
return Math.floor(Math.random() * 3); | |
} |
This file contains hidden or 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
function calcRandomVelocity() { | |
let randomShipXVelocity = Math.floor(Math.random() * 200) + 20; | |
randomShipXVelocity *= Math.floor(Math.random() * 2) == 1 ? 1 : -1; | |
return randomShipXVelocity; | |
} |
This file contains hidden or 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
function startMovingPhysicsWorld() { | |
let p2WorldInterval = setInterval(function () { | |
if (!gameOn) { | |
clearInterval(p2WorldInterval); | |
} else { | |
// updates velocity every 5 seconds | |
if (++shipVelocityTimer >= 80) { | |
shipVelocityTimer = 0; | |
shipBody.velocity[0] = calcRandomVelocity(); | |
} |
This file contains hidden or 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
function resetServerState() { | |
peopleAccessingTheWebsite = 0; | |
gameOn = false; | |
gameTickerOn = false; | |
totalPlayers = 0; | |
alivePlayers = 0; | |
for (let item in playerChannels) { | |
playerChannels[item].unsubscribe(); | |
} | |
} |
This file contains hidden or 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
function finishGame(playerId) { | |
let firstRunnerUpName = ""; | |
let secondRunnerUpName = ""; | |
let winnerName = "Nobody"; | |
let leftoverPlayers = new Array(); | |
for (let item in players) { | |
leftoverPlayers.push({ | |
nickname: players[item].nickname, | |
score: players[item].score, | |
}); |