Skip to content
Snippets Groups Projects
Commit a4d93e06 authored by ah3472's avatar ah3472
Browse files

added levels and difficulty scaling

parent 9fba1fef
Branches
No related tags found
No related merge requests found
......@@ -2,13 +2,12 @@ class Map {
constructor(numRooms, currentRoom = null) {
this.numOfRooms = numRooms;
this.currentRoom = currentRoom;
this.listOfRooms = [];
this.notEmptyRooms = 0;
}
generateStartRoom() {
let numOfEnemies = Math.floor(Math.random() * (10 - 4)) + 4
let start = new Room(lvl1TileMaps[1], 1)
this.currentRoom = start
let start = new Room(lvl1TileMaps[1], 0)
this.currentRoom = start;
}
copyTileMap(tileMap) {
......@@ -22,7 +21,7 @@ class Map {
return newTileMap
}
generateRandomMap() {
generateRandomMap(minEnemies, maxEnemies) {
let room = this.currentRoom
let roomsLeft = this.numOfRooms
while (roomsLeft > 0) {
......@@ -31,13 +30,14 @@ class Map {
return arr.slice()
})
//var tileMap = this.copyTileMap(lvl1TileMaps[1])
let numOfEnemies = Math.floor(Math.random() * (10 - 4)) + 4
let numOfEnemies = Math.floor(Math.random() * (maxEnemies - minEnemies)) + minEnemies;
let newRoom = new Room(tileMap, numOfEnemies)
switch (num) {
case 0:
if (room.top == null) {
this.addRoomTop(room, newRoom);
roomsLeft--;
this.notEmptyRooms++;
}
else {
room = room.top;
......@@ -47,6 +47,7 @@ class Map {
if (room.bottom == null) {
this.addRoomBottom(room, newRoom);
roomsLeft--;
this.notEmptyRooms++;
}
else {
room = room.bottom;
......@@ -56,6 +57,7 @@ class Map {
if (room.left == null) {
this.addRoomLeft(room, newRoom);
roomsLeft--;
this.notEmptyRooms++;
}
else {
room = room.left;
......@@ -65,12 +67,12 @@ class Map {
if (room.right == null) {
this.addRoomRight(room, newRoom);
roomsLeft--;
this.notEmptyRooms++;
}
else {
room = room.right;
}
}
this.listOfRooms.push(newRoom)
}
}
......
......@@ -8,9 +8,10 @@ restartButton.addEventListener("click", function() {
overlay.style.display = "none";
app.stage.removeChildren();
app.ticker.stop();
score = 0
lvl = 1;
score = 0;
startUpGame();
app.ticker.start()
app.ticker.start();
})
let logOutButton = document.getElementById("logout")
......@@ -54,9 +55,17 @@ let mobList = [];
let bounds;
let playerCollided;
let lvl = 1;
let lvlText;
let score = 0;
let scoreTxt;
let difficulty = {
numOfRooms: 3,
minEnemies: 2,
maxEnemies: 4,
}
let nextX;
let nextY;
......@@ -67,16 +76,15 @@ let downPressed = false;
let fPressed = false;
function startUpGame() {
map = new Map(5);
map = new Map(difficulty.numOfRooms);
map.generateStartRoom();
map.generateRandomMap();
console.log(map.listOfRooms)
map.generateRandomMap(difficulty.minEnemies, difficulty.maxEnemies);
map.currentRoom.drawRoom(app)
map.currentRoom.firstTimeInRoom = false;
roomDoors = map.currentRoom.getRoomDoorColliders()
p1 = new player("Bob", app.view.width/2, app.view.height/2, 5, "Pistol");
p1 = new player("Bob", app.view.width/2, app.view.height/2, 10, "Pistol");
nextX = p1.x;
nextY = p1.y;
p1.create_p1(app);
......@@ -86,10 +94,10 @@ function startUpGame() {
bounds = map.currentRoom.getColliders(app);
randomlySpawnMobs(map.currentRoom.numOfEnemies);
loadSprites();
healthBar();
createLevelLabel();
createScoreBoard();
app.ticker.add(map_loop);
......@@ -100,11 +108,18 @@ function createScoreBoard() {
scoreTxt = new PIXI.Text(something,{fontFamily: "Arial",fontSize: 25, fill: "#FFFFFF"});
scoreTxt.anchor.set(0.5);
scoreTxt.x = app.view.width / 2;
scoreTxt.y = 30; //app.view.height / 4;
scoreTxt.anchor.set = 0.5;
scoreTxt.y = 50;
app.stage.addChild(scoreTxt);
}
function createLevelLabel() {
lvlText = new PIXI.Text("Level " + lvl, {fontFamily: "Arial",fontSize: 30, fill: "#FFFFFF"});
lvlText.anchor.set(0.5);
lvlText.x = app.view.width / 2;
lvlText.y = 20;
app.stage.addChild(lvlText);
}
function checkDoorCollision() {
if (nextX - 23 < roomDoors.minX) {
p1.x = app.view.width/2 + 64 * 9.5
......@@ -138,6 +153,7 @@ function ChangeRooms(nextRoom) {
app.ticker.stop()
map.currentRoom = nextRoom
map.currentRoom.drawRoom(app)
createLevelLabel()
createScoreBoard()
bounds = map.currentRoom.getColliders(app)
if (map.currentRoom.firstTimeInRoom) {
......@@ -349,6 +365,73 @@ function calculateNextXY() {
}
}
function scaleDifficulty() {
let multipler = 1 + lvl / 4
if (difficulty.maxEnemies < 8) {
difficulty.maxEnemies = Math.floor(4 * multipler);
}
else {
difficulty.maxEnemies = 8
}
if (difficulty.minEnemies < 8) {
difficulty.minEnemies = Math.floor(2 * multipler);
}
else {
difficulty.minEnemies = 5;
}
if (difficulty.numOfRooms < 9) {
difficulty.numOfRooms = Math.floor(3 * multipler);
}
else {
difficulty.numOfRooms = 9;
}
}
function createNextLvl() {
lvl++;
scaleDifficulty();
app.stage.removeChildren();
app.ticker.stop();
map = new Map(difficulty.numOfRooms)
map.generateStartRoom();
map.generateRandomMap(difficulty.minEnemies, difficulty.maxEnemies);
p1.x = app.view.width / 2;
p1.y = app.view.height / 2;
g1.x = p1.x - 40
g1.y = p1.y - 5
map.currentRoom.drawRoom(app)
map.currentRoom.firstTimeInRoom = false;
roomDoors = map.currentRoom.getRoomDoorColliders()
bounds = map.currentRoom.getColliders(app);
healthBar();
createLevelLabel();
createScoreBoard();
loadSprites();
if(g1.weapon === "Awp"){
wep.textures = gunAnim.awp;
wep.play();
}
else if(g1.weapon === "smg"){
wep.textures = gunAnim.smg;
wep.play();
}
else{
wep.textures = gunAnim.idle;
wep.play();
}
app.ticker.start();
}
function map_loop(delta) {
calculateNextXY()
......@@ -383,6 +466,11 @@ function map_loop(delta) {
}
}
console.log(map.notEmptyRooms)
if (map.notEmptyRooms === 0) {
createNextLvl()
}
checkDoorCollision()
movePlayer()
......@@ -449,6 +537,9 @@ function bulletCollider(delta){
map.currentRoom.enemies.splice(j, 1);
score += 100;
scoreTxt.text ="Score: " + score;
if (map.currentRoom.numOfEnemies === 0) {
map.notEmptyRooms--;
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment