Skip to content

Commit

Permalink
Albert
Browse files Browse the repository at this point in the history
  • Loading branch information
Vital-Vuillaume committed Mar 29, 2024
1 parent f9420b9 commit e80e4fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Binary file added Site/ImageGame/villager1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion Site/Js/JsGame/classes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Sprite {
constructor({position, velocity, image, frames = {max: 1}, sprites }) {
constructor({position, image, frames = {max: 1}, sprites }) {
this.position = position;
this.image = image;
this.frames = {...frames, val: 0, elapsed: 0};
Expand Down Expand Up @@ -38,6 +38,20 @@ class Sprite {
}
}
}

if(this.b) {
if(this.frames.max > 1) {
this.frames.elapsed++;
}

if(this.frames.elapsed % 15 === 0) {
if(this.frames.val + 1 < this.frames.max) {
this.frames.val++;
} else {
this.frames.val = 0;
}
}
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions Site/Js/JsGame/pixel-adventure-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ player4.src = './Site/ImageGame/player4.png';
// Villager image

const villager1 = new Image();
villager1.src = './Site/ImageGame/player1.png';
villager1.src = './Site/ImageGame/villager1.png';

const villager2 = new Image();
villager2.src = './Site/ImageGame/player1.png';
Expand Down Expand Up @@ -194,8 +194,10 @@ let currentSegment = 0;
function keydialogue(villager) {
clearTimeout(timeoutVillager);
if (villager === Albert) {
villager.sprite.b = true
dialogueFunction("Albert", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbxcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccxdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddx");
} else if (villager === Francois) {
villager.sprite.b = true
dialogueFunction("Francois", "Bonjour!");
}
}
Expand All @@ -218,6 +220,9 @@ function dialogueFunction(usernames, texts) {
timeoutVillager = setTimeout(displaySegment, time);
} else {
timeoutVillager = setTimeout(function() {
villagers.forEach(villager => {
villager.sprite.b = false
})
dialogue.classList.remove("active");
}, time);
}
Expand All @@ -229,13 +234,10 @@ function dialogueFunction(usernames, texts) {
dialogue.classList.add("active");
}



let base = "map";

function animate() {
window.requestAnimationFrame(animate);

let moving = true;

if(base === "map") {
Expand All @@ -244,13 +246,12 @@ function animate() {

backgroundMap.draw();
player.draw();
foregroundMap.draw();

player.moving = false;

villagers.forEach(villager => {
villager.sprite.draw();
});
foregroundMap.draw();

player.moving = false;

mapOfCollisions.forEach(mapOfCollision => {
mapOfCollision.draw()
Expand Down

0 comments on commit e80e4fa

Please sign in to comment.