Skip to content

Commit

Permalink
many optimizations and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-stips committed Jan 22, 2024
1 parent bfa90ef commit 68e3f43
Show file tree
Hide file tree
Showing 19 changed files with 910 additions and 441 deletions.
134 changes: 77 additions & 57 deletions src/script/public/App/features/AdvantureMap.js

Large diffs are not rendered by default.

136 changes: 112 additions & 24 deletions src/script/public/App/features/bosses/BossClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ class Boss {
};

display = () => {
boss.style.opacity = "1";
boss.style.display = "flex";
bossIMG.src = this.img;
bossLifeCounter.textContent = `${this.hp}/${this.maxHP} HP`;
bossBar_fill2.style.width = `0`;
bossIMG.style.animation = "";

this.start_attack_interval();
};

delete = () => {
boss.style.display = "none";
boss.style.display = "";
bossIMG.src = "";
this.died = true;

bossIMG.removeEventListener("animationend", bossIMG.fn);
document.querySelector('#GameArea-FieldCircle').style.margin = "0 0 0 0";
this.stop_attack_interval();
};
Expand All @@ -32,13 +37,19 @@ class Boss {
let index = this.attack_timer;
this.interval =
setInterval(() => {
index--;
if (index <= 5) bossIMG.style.animation = "";
if (index <= 0) {
if (!this.died) {
index--;
if (index <= 5) bossIMG.style.animation = "";
if (index <= 0) {
clearInterval(this.interval);
this.interval = null;
this.stop_attack_interval();
this.attack(); // attack
};

} else {
clearInterval(this.interval);
this.interval = null;
this.stop_attack_interval();
this.attack(); // attack
};
}, 1000);
};
Expand All @@ -49,24 +60,48 @@ class Boss {
};

attack = () => {
removeAccessToAnything();

// start animation
bossIMG.style.animation = this.attack_animation;
if (this.attack_animation != null) {
bossIMG.style.animation = this.attack_animation;
};

// play attack sound
this.attack_sound.volume = sfxVolume;
this.attack_sound.play();
// start right attack
switch (this.attack_type) {
case "lock":
boss_attacks.boss_lock_attack()
.then(this.start_attack_interval()); // after attack finished: start new attack timer
break;
if (this.attack_sound != null) {
this.attack_sound.volume = sfxVolume;
this.attack_sound.play();
};

// start right attack
boss_attacks[this.attack_type]() // attack_type = index of attack in boss_attack object
.then(() => {
// after attack finished: start new attack timer
this.start_attack_interval();

// user can leave now and do anything
addAccessToAnything(undefined, true, true);
});
};

damage = (damage) => {
let bossIsDeadNow = false;
let newHP = this.hp - damage

newHP < 0 && (bossIsDeadNow = true);
let percentage = 100 - ((newHP / this.maxHP) * 100);

for (let counter = damage; counter > 0; counter--) {
this.hp--;
bossLifeCounter.textContent = `${this.hp}/${this.maxHP} HP`;

if (!bossIsDeadNow) {
bossLifeCounter.textContent = `${this.hp}/${this.maxHP} HP`;
bossBar_fill2.style.width = `${percentage}%`;

} else {
bossLifeCounter.textContent = `${0}/${this.maxHP} HP`;
bossBar_fill2.style.width = `100%`;
};
};

// animation
Expand All @@ -88,34 +123,87 @@ class Boss {
};

death = () => {
bossIMG.style.animation = "boss_dies 1.5s ease-in-out forwards";
this.died = true;
bossIMG.style.animation = "boss_dies 1.5s ease-in-out";

removeAccessToAnything();

bossIMG.addEventListener("animationend", bossIMG.fn = (e) => {
console.log(e);

bossIMG.addEventListener("animationend", () => {
setTimeout(() => {
this.died = true;
this.delete();
}, 50);
this.delete();
addAccessToAnything();
});
};
};

// star eye -------------------------------------------------------
class StarEye extends Boss {
constructor() {
super("./assets/game/cursed-star.svg", 50, "lock", "StarEye_Attack 1s linear", Shoot1, 4000);
super("./assets/game/cursed-star.svg", 65, "boss_lock_attack", "StarEye_Attack 1s linear", Shoot1, 3000);
};
};

class Sun extends Boss {
constructor() {
super("./assets/game/spikes-full.svg", 110, "triple_shoot", null, null, 4000);
};
};

class Eye extends Boss {
constructor() {
super("./assets/game/warlock-eye.svg", 70, "big_shoot", null, null, 8000);
};
};

// attacks
const boss_attacks = {
// attack # 0
boss_lock_attack: () => {
return new Promise((resolve) => {
return new Promise(resolve => {
let Rnd_Indexes = getRandomIndexes(options, 30);

Rnd_Indexes.forEach(index => {
single_CellBlock(cells[index]);
});

resolve();
});
},

// attack # 1
triple_shoot: () => {
return new Promise(resolve => {
let attack_count = 0;
let attack_interval = setInterval(() => {
// attack process. if died = close process
if (!current_level_boss.died) {
eye_attack_soundeffect.currentTime = 0;
eye_attack_soundeffect.pause();

attack_count++;
sun_attack();

if (attack_count >= 3) {
clearInterval(attack_interval);
attack_interval = null;

resolve();
};

} else {
clearInterval(attack_interval);
attack_interval = null;
};

}, 1500);
});
},

// attack # 2
big_shoot: () => {
return new Promise(resolve => {
eye_attack();
resolve();
});
}
Expand Down
60 changes: 29 additions & 31 deletions src/script/public/App/features/bosses/eye.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,27 @@ function init_eye() {
};
// HP
eyeLifeCounter.textContent = `${eye_HP}/${eye_HP} HP`;
eyeBar_fill2.style.width = `0`;
// get position
The_eye.getBoundingClientRect();
};

// eye attack
function eye_attack() {
if (!eyeDied) {
// bug fix
CloseOnlinePopUps(true);

// animation
// change eye position so it is vibrating
let eye_pos = setInterval(() => {
let first_pos = Math.random() * 15;
let second_pos = Math.random() * 15;

The_eye.style.transform = `translate(${first_pos}px, ${second_pos}px)`;
}, 100);
// animation
// change eye position so it is vibrating
let eye_pos = setInterval(() => {
let first_pos = Math.random() * 15;
let second_pos = Math.random() * 15;

// end of animation
setTimeout(() => {
clearInterval(eye_pos);
eye_pos = null;
bossIMG.style.transform = `translate(${first_pos}px, ${second_pos}px)`;
}, 100);

// end of animation
setTimeout(() => {
clearInterval(eye_pos);
eye_pos = null;
if (!current_level_boss.died) {
// play soundeffect
eye_attack_soundeffect.volume = sfxVolume;
eye_attack_soundeffect.playbackRate = 1;
Expand All @@ -59,13 +56,13 @@ function eye_attack() {
eye_attckingBeam.style.opacity = "1";

// animation
The_eye.style.transform = "scale(1.2)";
bossIMG.style.transform = "scale(1.2)";
DarkLayer.style.display = "block";
DarkLayer.style.backgroundColor = "white";

setTimeout(() => {
The_eye.style.transform = "scale(1)";
The_eye.style.transition = "all 2s ease-in-out";
bossIMG.style.transform = "scale(1)";
bossIMG.style.transition = "all 2s ease-in-out";

eye_attckingBeam.style.transition = "opacity 200ms linear";
eye_attckingBeam.style.opacity = "0";
Expand Down Expand Up @@ -98,19 +95,11 @@ function eye_attack() {
}, 1000);

setTimeout(() => {
The_eye.style.transition = "all 0.2s ease-in-out";
bossIMG.style.transition = "all 0.2s ease-in-out";
}, 2500);
};

// start attack interval again
if (curr_mode != GameMode[2].opponent) {
EyeAttackInterval();
};

setTimeout(() => {
addAccessToAnything();
}, 2250);
}, 3000); // Ändern Sie die Dauer der Vibration nach Bedarf
};
}, 3000); // Ändern Sie die Dauer der Vibration nach Bedarf
};

// damage from eye attack on cell-grid
Expand Down Expand Up @@ -201,12 +190,21 @@ socket.on("EyeDamage", async(OptionsArray) => {
// user can defeat the eye through his patterns and if he clicks on the eye with the cursor
// cursor damage: 1, pattern damage: 450 - 900
function eyeGot_HP_Damage(damage) {
let bossIsDeadNow = false;
let newHP = eye_HP - damage
newHP < 0 && (bossIsDeadNow = true);

if (!eyeDied) {
for (let counter = damage; counter > 0; counter--) {
playBtn_Audio_2();

let maxHP = inAdvantureMode ? 20000 : 10000;

eye_HP = eye_HP - 1;
inAdvantureMode ? eyeLifeCounter.textContent = `${eye_HP}/${20000} HP` : eyeLifeCounter.textContent = `${eye_HP}/${10000} HP`;
!bossIsDeadNow ? eyeLifeCounter.textContent = `${sun_HP}/${maxHP} HP` : eyeLifeCounter.textContent = `${0}/${maxHP} HP`;

let percentage = 100 - ((newHP / maxHP) * 100);
!bossIsDeadNow ? sunBar_fill2.style.width = `${percentage}%` : sunBar_fill2.style.width = `100%`;
};

// animation
Expand Down
Loading

0 comments on commit 68e3f43

Please sign in to comment.