418 lines
13 KiB
JavaScript
418 lines
13 KiB
JavaScript
PAGE_TITLE="Servers Under Maintenance";
|
|
|
|
FPS=Game.FPS;
|
|
|
|
|
|
function cleanSlate() {
|
|
GameObject.gameObjects = [];
|
|
UIElement.elements = [];
|
|
Hitbox.hitboxes = [];
|
|
|
|
Game.tutorialServers = [];
|
|
|
|
Game.serverLoadGrowth = Game.INITIAL_SERVER_LOAD_GROWTH;
|
|
Game.serverLoad = 200;
|
|
Game.lastServerLoad = 200;
|
|
|
|
Game.money = 0;
|
|
|
|
Game.cursor = new Cursor(0,0);
|
|
}
|
|
|
|
function initMainMenu() {
|
|
cleanSlate();
|
|
|
|
Game.gamestate = "menu";
|
|
|
|
new UIText("Servers under Maintenance", 22, 42, "white", "large");
|
|
new AnimatedTextButton(70, 70, "#BEA58C", "Play", "white", "large", () => {
|
|
initMainGame();
|
|
});
|
|
new AnimatedTextButton(130, 80, "#49B3BC", "Tutorial", "white", "small", () => {
|
|
initTutorial();
|
|
});
|
|
}
|
|
|
|
|
|
function initGameOver() {
|
|
cleanSlate();
|
|
|
|
Game.gamestate = "gameover";
|
|
|
|
let seconds_full = Math.floor(Game.playedFrames / Game.FPS);
|
|
let minutes = Math.floor(seconds_full / 60);
|
|
let seconds = (seconds_full % 60).toString().padStart(2, '0');
|
|
|
|
new UIText("Game Over", 90, 42, "white", "large");
|
|
new UIText("Time survived: " + minutes + ":" + seconds, 90, 60, "white", "small");
|
|
new AnimatedTextButton(90, 70, "#BEA58C", "Play Again", "white", "large", () => {
|
|
initMainGame();
|
|
});
|
|
new AnimatedTextButton(90, 100, "#49B3BC", "Main Menu", "white", "small", () => {
|
|
initMainMenu();
|
|
});
|
|
}
|
|
|
|
function initMainGame() {
|
|
|
|
cleanSlate();
|
|
|
|
Game.playedFrames = 0;
|
|
Game.gamestate = "playing";
|
|
|
|
new Hitbox(0, 0, Game.WIDTH, 32);
|
|
new Hitbox(0, 0, 0, Game.HEIGHT);
|
|
new Hitbox(0, Game.HEIGHT, Game.WIDTH, 0);
|
|
new Hitbox(Game.WIDTH, 0, 0, Game.HEIGHT);
|
|
|
|
|
|
Game.player = new Player(Game.WIDTH / 2, Game.HEIGHT / 2 + Game.TILESIZE * 2);
|
|
new Inventory(2, Game.HEIGHT - 18);
|
|
new EnergyBar(Game.WIDTH - 50, 2, 48, 6);
|
|
new ServerLoadBar(Game.WIDTH - 50, 10, 48, 6);
|
|
new PlayerCount(Game.WIDTH - 80, 30);
|
|
new MoneyLabel(16, 16);
|
|
new ServerLoadGauge(Game.WIDTH - 120, 1);
|
|
|
|
new Server(5 * Game.TILESIZE, 3 * Game.TILESIZE);
|
|
new Server(7 * Game.TILESIZE, 3 * Game.TILESIZE);
|
|
new Server(9 * Game.TILESIZE, 3 * Game.TILESIZE);
|
|
new Server(5 * Game.TILESIZE, 5 * Game.TILESIZE);
|
|
new Server(7 * Game.TILESIZE, 5 * Game.TILESIZE);
|
|
new Server(9 * Game.TILESIZE, 5 * Game.TILESIZE);
|
|
|
|
new Trashbin(Game.WIDTH - Game.TILESIZE, Game.HEIGHT - Game.TILESIZE * 5);
|
|
new CoffeeTable(Game.WIDTH - Game.TILESIZE * 3, Game.HEIGHT - Game.TILESIZE);
|
|
new CableTable(Game.WIDTH - Game.TILESIZE * 7, Game.HEIGHT - Game.TILESIZE);
|
|
new ShopTable(Game.WIDTH - Game.TILESIZE * 11, Game.HEIGHT - Game.TILESIZE);
|
|
}
|
|
|
|
function initTutorial() {
|
|
cleanSlate();
|
|
|
|
Game.gamestate = "tutorial";
|
|
Game.tutorialStep = 0;
|
|
|
|
new Hitbox(0, 0, Game.WIDTH, 32);
|
|
new Hitbox(0, 0, 0, Game.HEIGHT);
|
|
new Hitbox(0, Game.HEIGHT, Game.WIDTH, 0);
|
|
new Hitbox(Game.WIDTH, 0, 0, Game.HEIGHT);
|
|
|
|
|
|
Game.player = new Player(Game.WIDTH / 2, Game.HEIGHT / 2);
|
|
Game.player.maxEnergy = Game.PLAYER_MAX_ENERGY * 3;
|
|
Game.player.inventorySlots = 3;
|
|
Game.money = 160;
|
|
|
|
Game.tutorialServers.push(new TutorialServer(5 * Game.TILESIZE, 3 * Game.TILESIZE));
|
|
Game.tutorialServers.push(new TutorialServer(7 * Game.TILESIZE, 3 * Game.TILESIZE));
|
|
Game.tutorialServers.push(new TutorialServer(9 * Game.TILESIZE, 3 * Game.TILESIZE));
|
|
|
|
new AnimatedTextButton(0, 32, "#49B3BC", "Main Menu", "white", "small", () => {
|
|
initMainMenu();
|
|
});
|
|
|
|
new Dialogue("Welcome to your first day", "in the [redacted] Games data center", tutorialStep);
|
|
}
|
|
|
|
function tutorialStep() {
|
|
Game.tutorialStep++;
|
|
|
|
for (let i = 0; i < UIElement.elements.length; i++) {
|
|
if (UIElement.elements[i] instanceof Dialogue) {
|
|
UIElement.elements[i].delete();
|
|
}
|
|
}
|
|
|
|
if (Game.tutorialStep == 1) {
|
|
new Dialogue("Your task will be to maintain the", "servers as the player count rises", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 2) {
|
|
new Dialogue("Servers will inevitably fail and it is your ", "job to fix them before they overload", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 3) {
|
|
Game.tutorialServers[0].ui.createMoveCableFailure();
|
|
Game.tutorialServers[0].framesUntilNextFailure = 0;
|
|
new Dialogue("Talking of! Looks like that server has a", "problem. Go check it out.", () => {});
|
|
}
|
|
if (Game.tutorialStep == 4) {
|
|
new Dialogue("Looks like this cable isn't plugged in", "the right connectors.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 5) {
|
|
new Dialogue("Drag and Drop the ends of the cable", "into the marked connectors.", () => {
|
|
if (!Game.tutorialServers[0].failure) {
|
|
tutorialStep();
|
|
}
|
|
});
|
|
}
|
|
if (Game.tutorialStep == 6) {
|
|
new Dialogue("Good Job! You have successfuly", "repaired your first server.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 7) {
|
|
Game.tutorialServers[0].ui.closeButton.click();
|
|
new Dialogue("Wow that was tiring. It's", "about time for a coffee!", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 8) {
|
|
new CoffeeTable(Game.WIDTH - Game.TILESIZE * 3, Game.HEIGHT - Game.TILESIZE);
|
|
new Dialogue("Click the Coffee Table in the bottom", "right to make a coffee", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 9) {
|
|
new Dialogue("Then click on yourself to drink it", "", () => {});
|
|
}
|
|
if (Game.tutorialStep == 10) {
|
|
new Dialogue("Wow, tasty!", "", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 11) {
|
|
new Dialogue("Should you ever feel tired, you can", "have as much coffee as you'd like", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 12) {
|
|
new EnergyBar(Game.WIDTH - 50, 2, 48, 6);
|
|
new Dialogue("Make sure you drink some before your", "energy runs out!", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 13) {
|
|
setTimeout(() => {
|
|
Game.tutorialServers[1].ui.createNewCableFailure();
|
|
Game.tutorialServers[1].framesUntilNextFailure = 0;
|
|
new Dialogue("Oh no! Another server just broke down.", "Go check it out!", () => {});
|
|
}, 1000);
|
|
}
|
|
if (Game.tutorialStep == 14) {
|
|
new Dialogue("Hmm, looks like this one is missing", "a cable.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 15) {
|
|
Game.tutorialServers[1].ui.closeButton.click();
|
|
new Dialogue("Go fetch a new one from the table", "at the bottom of the screen.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 16) {
|
|
new Dialogue("Click on the Table to grab a cable", "", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 17) {
|
|
new CableTable(Game.WIDTH - Game.TILESIZE * 7, Game.HEIGHT - Game.TILESIZE);
|
|
new Inventory(2, Game.HEIGHT - 18);
|
|
new Dialogue("Then place it in your inventroy", "in the bottom left", () => {});
|
|
}
|
|
if (Game.tutorialStep == 18) {
|
|
new Dialogue("Nice, now you have everything you", "need to repair the server", () => {});
|
|
}
|
|
if (Game.tutorialStep == 19) {
|
|
new Dialogue("Click on the cable in your", "inventory to pick it up", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 20) {
|
|
new Dialogue("Then drag it from one connector", "to the other to install it", () => {
|
|
if (!Game.tutorialServers[1].failure) {
|
|
tutorialStep();
|
|
}
|
|
});
|
|
}
|
|
if (Game.tutorialStep == 21) {
|
|
new MoneyLabel(16, 16);
|
|
Game.tutorialServers[1].ui.closeButton.click();
|
|
new Dialogue("Great job. You've earned some", "money already.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 22) {
|
|
new Dialogue("Time to spend some of it in", "the online shop.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 23) {
|
|
new ShopTable(Game.WIDTH - Game.TILESIZE * 11, Game.HEIGHT - Game.TILESIZE);
|
|
new Dialogue("You can access it from the", "computer table in the bottom left", () => {});
|
|
}
|
|
|
|
if (Game.tutorialStep == 24) {
|
|
new Dialogue("Looks like you can afford some", "better shoes.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 25) {
|
|
new Dialogue("Buy them to be able to walk", "for longer without getting tired", () => {
|
|
if (Game.player.maxEnergy > Game.PLAYER_MAX_ENERGY * 3) {
|
|
tutorialStep();
|
|
}
|
|
});
|
|
}
|
|
if (Game.tutorialStep == 26) {
|
|
new Dialogue("Wow, those look really good", "on you :)", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 27) {
|
|
for (let i = 0; i < UIElement.elements.length; i++) {
|
|
if (UIElement.elements[i] instanceof Shop) {
|
|
UIElement.elements[i].closeButton.click();
|
|
}
|
|
}
|
|
Game.tutorialServers[2].ui.createBrokenCableFailure();
|
|
Game.tutorialServers[2].framesUntilNextFailure = 0;
|
|
new Dialogue("Oh Bollocks! Now the last", "server broke down too.", () => {});
|
|
}
|
|
if (Game.tutorialStep == 28) {
|
|
new Dialogue("This cable seems to be broken", "You will have to replace it", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 29) {
|
|
new Dialogue("Drag the ends on top of one", "another to detach the cable", () => {
|
|
if (Game.tutorialServers[2].ui.cables.length == 0 || !Game.tutorialServers[2].failure) {
|
|
tutorialStep();
|
|
}
|
|
});
|
|
}
|
|
if (Game.tutorialStep == 30) {
|
|
new Trashbin(Game.WIDTH - Game.TILESIZE, Game.HEIGHT - Game.TILESIZE * 5);
|
|
new Dialogue("Go to the trash bin on the right", "to throw this cable out", () => {});
|
|
}
|
|
if (Game.tutorialStep == 31) {
|
|
new Dialogue("Great, now grab a new cable", "and replace this old one", () => {});
|
|
}
|
|
if (Game.tutorialStep == 32) {
|
|
Game.tutorialServers[2].ui.closeButton.click();
|
|
new Dialogue("Well done. You're ready to repair", "any server now", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 33) {
|
|
new PlayerCount(Game.WIDTH - 80, 30);
|
|
new Dialogue("Each server provides capacity for 100", "players to play simultaneausly", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 34) {
|
|
new Dialogue("We will need to buy a new one before", "they overload.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 35) {
|
|
Game.money = 320;
|
|
new Dialogue("Head to the Computer table to order", "a new server.", () => {});
|
|
}
|
|
if (Game.tutorialStep == 36) {
|
|
new Dialogue("Now our servers should be able to", "handle all the players.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 37) {
|
|
new Dialogue("As long as they are up and", "running of course", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 38) {
|
|
new Dialogue("If the servers break down they can't", "provide any more capacity.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 39) {
|
|
new ServerLoadGauge(Game.WIDTH - 120, 1);
|
|
new Dialogue("This gauge tells you how well servers", "are keeping up with demand", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 40) {
|
|
new Dialogue("If it goes to the right the servers", "are overloaded", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 41) {
|
|
new ServerLoadBar(Game.WIDTH - 50, 10, 48, 6);
|
|
new Dialogue("If the servers are overloaded for", "too long, you will be fired.", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 42) {
|
|
new Dialogue("Keep them under maximum capacity", "to make sure that doesn't happen", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 43) {
|
|
new Dialogue("Good Luck", "", tutorialStep);
|
|
}
|
|
if (Game.tutorialStep == 44) {
|
|
initMainMenu();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (Game.tutorialStep == 24) {
|
|
// new Dialogue("You are about ready for the", "real deal now.", tutorialStep);
|
|
// }
|
|
// if (Game.tutorialStep == 25) {
|
|
// new ServerLoadGauge(Game.WIDTH - 120, 1);
|
|
// new ServerLoadBar(Game.WIDTH - 50, 10, 48, 6);
|
|
// new Dialogue("The Server Load Bar and the", "Gauge show you how...", tutorialStep);
|
|
// }
|
|
// if (Game.tutorialStep == 26) {
|
|
// new Dialogue("busy the servers are.", "If the red bar fills up", tutorialStep);
|
|
// }
|
|
// if (Game.tutorialStep == 27) {
|
|
// new Dialogue("all the way, you're fired.", "Good luck.", tutorialStep);
|
|
// }
|
|
}
|
|
|
|
function init() {
|
|
document.addEventListener("mousemove", mouseMoveHandler);
|
|
Game.c = c;
|
|
Game.cv = cv;
|
|
|
|
c.imageSmoothingEnabled = false;
|
|
Assets.loadAssets();
|
|
resize();
|
|
|
|
initMainMenu();
|
|
}
|
|
|
|
function onresize(x, y) {
|
|
resize();
|
|
}
|
|
|
|
function resize() {
|
|
let dpr = window.devicePixelRatio;
|
|
let xScale = window.innerWidth * dpr / Game.WIDTH;
|
|
let yScale = window.innerHeight * dpr / Game.HEIGHT;
|
|
|
|
Game.scale = Math.min(xScale, yScale);
|
|
|
|
cv.width = Game.WIDTH;
|
|
cv.height = Game.HEIGHT
|
|
|
|
cv.style.width = Game.WIDTH * Game.scale;
|
|
cv.style.height = Game.HEIGHT * Game.scale;
|
|
}
|
|
|
|
function drawBackground() {
|
|
Game.c.drawImage(Assets.background, 0, 0, Game.WIDTH, 32);
|
|
for (let x = 0; x < Game.TILES_X; x++) {
|
|
for (let y = 2; y < Game.TILES_Y; y++) {
|
|
Game.c.drawImage(Assets.floorTile, x * Game.TILESIZE, y * Game.TILESIZE, Game.TILESIZE, Game.TILESIZE);
|
|
}
|
|
}
|
|
}
|
|
|
|
function onKeyDown(e) {
|
|
if (Game.gamestate != "menu") {
|
|
Game.player.keydown(e);
|
|
}
|
|
}
|
|
|
|
function onKeyUp(e) {
|
|
if (Game.gamestate != "menu") {
|
|
Game.player.keyup(e);
|
|
}
|
|
}
|
|
|
|
function mouseMoveHandler(e) {
|
|
let rect = Game.cv.getBoundingClientRect();
|
|
Game.cursor.x = Math.floor((e.clientX - rect.x) / rect.width * Game.WIDTH);
|
|
Game.cursor.y = Math.floor((e.clientY - rect.y) / rect.height * Game.HEIGHT);
|
|
}
|
|
|
|
function onMouseDown() {
|
|
Game.cursor.click();
|
|
}
|
|
|
|
function onMouseUp() {
|
|
Game.cursor.mouseUp();
|
|
}
|
|
|
|
function tick() {
|
|
if (Game.gamestate == "menu" || Game.gamestate == "gameover") {
|
|
Game.c.drawImage(Assets.menuBackground, 0, 0);
|
|
} else {
|
|
if (Game.gamestate == "playing") {
|
|
if (Game.serverLoad < 0) {
|
|
Game.serverLoad = 0;
|
|
}
|
|
if (Game.serverLoad > Game.MAX_SERVER_LOAD) {
|
|
initGameOver();
|
|
}
|
|
Game.lastServerLoad = Game.serverLoad;
|
|
Game.serverLoad += Game.serverLoadGrowth;
|
|
Game.money += Game.PASSIVE_INCOME_PER_PLAYER * Game.serverLoadGrowth;
|
|
Game.serverLoadGrowth += 0.02;
|
|
|
|
Game.playedFrames++;
|
|
}
|
|
|
|
GameObject.updateAll();
|
|
|
|
drawBackground();
|
|
}
|
|
|
|
GameObject.drawAll();
|
|
UIElement.drawAll();
|
|
}
|