Last active
June 9, 2020 13:37
-
-
Save Srushtika/f5a1b7d608ee27dff67f597a74d541b7 to your computer and use it in GitHub Desktop.
Code snippet 7 - For multiplayer space invaders article
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 envConfig = require("dotenv").config(); | |
const express = require("express"); | |
const Ably = require("ably"); | |
const p2 = require("p2"); | |
const app = express(); | |
const ABLY_API_KEY = process.env.ABLY_API_KEY; | |
const CANVAS_HEIGHT = 750; | |
const CANVAS_WIDTH = 1400; | |
const SHIP_PLATFORM = 718; | |
const PLAYER_VERTICAL_INCREMENT = 20; | |
const PLAYER_VERTICAL_MOVEMENT_UPDATE_INTERVAL = 1000; | |
const PLAYER_SCORE_INCREMENT = 5; | |
const P2_WORLD_TIME_STEP = 1 / 16; | |
const MIN_PLAYERS_TO_START_GAME = 3; | |
const GAME_TICKER_MS = 100; | |
let peopleAccessingTheWebsite = 0; | |
let players = {}; | |
let playerChannels = {}; | |
let shipX = Math.floor((Math.random() * 1370 + 30) * 1000) / 1000; | |
let shipY = SHIP_PLATFORM; | |
let avatarColors = ["green", "cyan", "yellow"]; | |
let avatarTypes = ["A", "B", "C"]; | |
let gameOn = false; | |
let alivePlayers = 0; | |
let totalPlayers = 0; | |
let gameRoom; | |
let deadPlayerCh; | |
let gameTickerOn = false; | |
let bulletTimer = 0; | |
let shipBody; | |
let world; | |
let shipVelocityTimer = 0; | |
let killerBulletId = ""; | |
let copyOfShipBody = { | |
position: "", | |
velocity: "", | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment