Skip to content

Commit

Permalink
Bugs solved, Health bars done
Browse files Browse the repository at this point in the history
  • Loading branch information
eea88 committed Jul 18, 2024
1 parent be62941 commit 0a738f1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion battle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function extraBattle(battleArray,bottomContainer){
if(game.battleArray.length>= 1){
if(game.enemies.length> 0){
if(game.enemies.length> 40){
let orcNumber = Math.floor(Math.random()*game.enemies.length);
let soldierNumber= Math.floor(Math.random()*game.battleArray.length);
let soldierBlocker = game.battleArray[soldierNumber];
Expand Down
58 changes: 42 additions & 16 deletions enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ const enemyClassesArray = [

class Enemy {
constructor(level) {
this.createEnemyElement();
//this metod creates the enemey which we need to set the position


this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();

this.velocity = 10 + level / 2;
this.health = 90 + level * 2;
this.stamina = 50 + level * 3;
Expand All @@ -32,14 +27,6 @@ class Enemy {

//other stats go here
}

createEnemyElement() {
this.element = document.createElement("div");
let randomClass = Math.floor(Math.random() * 7 + 1);
this.element.className = enemyClassesArray[randomClass];

gameArea.appendChild(this.element);
}
updateElementPosition() {
this.element.style.left = `${this.positionX}px`;
this.element.style.top = `${this.positionY}px`;
Expand Down Expand Up @@ -186,6 +173,25 @@ class Enemy {
}
}

class BasicOrc extends Enemy{
constructor(level) {
super(level);
this.createEnemyElement();
this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();
}
createEnemyElement() {
this.element = document.createElement("div");
let randomClass = Math.floor(Math.random() * 7 + 1);
this.element.className = enemyClassesArray[randomClass];

gameArea.appendChild(this.element);
}

}
class EnemySwordsman extends Enemy {
constructor(level) {
super(level);
Expand All @@ -195,6 +201,11 @@ class EnemySwordsman extends Enemy {
this.defense = 10 + level;
this.agility = 10 + level;
this.createEnemySwordsmanElement();
this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();
}
createEnemySwordsmanElement() {
this.element = document.createElement("div");
Expand All @@ -218,6 +229,11 @@ class EnemyAxeOrc extends Enemy {
this.defense = 8 + level;
this.agility = 3 + level;
this.createAxeOrcElement();
this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();
}
createAxeOrcElement() {
this.element = document.createElement("div");
Expand All @@ -241,6 +257,11 @@ class AttackingBoss extends Enemy {
this.defense = 15 + level;
this.agility = 8 + level;
this.createAttackingBossElement();
this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();
}
createAttackingBossElement() {
this.element = document.createElement("div");
Expand All @@ -263,6 +284,11 @@ class BigBoss extends Enemy {
this.defense = 20 + level;
this.agility = 8 + level;
this.createBigBossElement();
this.positionX = Math.floor(
Math.random() * (gameArea.offsetWidth - this.element.offsetWidth)
);
this.positionY = gameArea.offsetHeight - this.element.offsetHeight;
this.updateElementPosition();
}
createBigBossElement() {
this.element = document.createElement("div");
Expand All @@ -278,7 +304,7 @@ class BigBoss extends Enemy {

for (let i = 0; i < 20; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(1));
game.enemies.push(new BasicOrc(1));
}

/* setInterval(() =>{
Expand Down
30 changes: 17 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function playGame() {

for (let i = 0; i < 10; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(1));
game.enemies.push(new BasicOrc(1));
console.log("New Enemy Wave");
}

Expand All @@ -75,7 +75,7 @@ function playGame() {

for (let i = 0; i < 20; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(2));
game.enemies.push(new BasicOrc(2));
console.log("New Enemy Wave");
}
}
Expand All @@ -88,10 +88,14 @@ function playGame() {

for (let i = 0; i < 18; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(3));
game.enemies.push(new BasicOrc(3));
console.log("New Enemy Wave");
}

for (let i = 0; i < 1; i++) {
// Create basic enemies
game.enemies.push(new EnemySwordsman(2));
game.enemies.push(new EnemyAxeOrc(2));
}
}
}
}
Expand All @@ -102,14 +106,14 @@ function playGame() {

for (let i = 0; i < 25; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(4)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(4)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
/* for (let i = 0; i < 1; i++) {
for (let i = 0; i < 1; i++) {
// Create basic enemies
game.enemies.push(new EnemySwordsman(3));
game.enemies.push(new EnemyAxeOrc(3));
} */
}
}
}
}
Expand All @@ -120,7 +124,7 @@ function playGame() {

for (let i = 0; i < 25; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(5)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(5)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
game.enemies.push(new AttackingBoss(1));
Expand All @@ -135,7 +139,7 @@ function playGame() {

for (let i = 0; i < 15; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(6)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(6)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
}
Expand All @@ -148,7 +152,7 @@ function playGame() {

for (let i = 0; i < 30; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(7)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(7)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
/* for (let i = 0; i < 2; i++) {
Expand All @@ -169,7 +173,7 @@ function playGame() {

for (let i = 0; i < 35; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(8)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(8)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
/* for (let i = 0; i < 2; i++) {
Expand All @@ -189,7 +193,7 @@ function playGame() {

for (let i = 0; i < 40; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(8)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(8)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
/* for (let i = 0; i < 3; i++) {
Expand All @@ -211,7 +215,7 @@ function playGame() {

for (let i = 0; i < 50; i++) {
// Create 20 basic enemies
game.enemies.push(new Enemy(9)); // ideally change the Enemy type here
game.enemies.push(new BasicOrc(9)); // ideally change the Enemy type here
console.log("New Enemy Wave");
}
/* for (let i = 0; i < 5; i++) {
Expand Down

0 comments on commit 0a738f1

Please sign in to comment.