Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed js/Core/physics/collision.js
Empty file.
10 changes: 8 additions & 2 deletions js/Core/physics/movement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

export function input(game, gameLoop = null) {

export function input(game, spawn, gameLoop = null) {
// faire que le personnage ne puisse pas sortir de la map
if (game.character.inputs.z) {
if (game.character.object.targetY > 0) {
Expand Down Expand Up @@ -42,8 +43,12 @@ export function input(game, gameLoop = null) {
allowEscapeKey: false,
allowEnterKey: false,
}).then((result) => {
game.animationFrameId = requestAnimationFrame(gameLoop);
game.spawnProcess.forEach((intervalId) => {
clearInterval(intervalId)
});
if (result.isConfirmed) {
game.animationFrameId = requestAnimationFrame(gameLoop);
console.log("reprendre");
} else {
location.reload();
}
Expand All @@ -55,6 +60,7 @@ export function input(game, gameLoop = null) {
export function keyDownListener(event, game) {
game.character.inputs[event.key] = true;
}

export function keyUpListener(event, game) {
game.character.inputs[event.key] = false;
}
Expand Down
5 changes: 0 additions & 5 deletions js/Core/physics/shoot.js

This file was deleted.

4 changes: 2 additions & 2 deletions js/Core/vars/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const game = {
gui: {
playerStats: null,
},
intervalInstances: [],
process: [],
spawnProcess: [],
autofireProcess: [],
mousePos: {
x: 0,
y: 0
Expand Down
12 changes: 5 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Projectile from "./Entities/Projectile.js";
import {game, characterSprites, lootSprites} from "./Core/vars/game.js";
import {drawCharacterHpBar, drawHealthBar, drawPlayerStats, drawXpBar} from "./Core/ui/drawUI.js";
import {spawnEnemies} from "./Core/physics/spawn.js";
import {shoot} from "./Core/physics/shoot.js";
import {keyDownListener, keyUpListener, input} from "./Core/physics/movement.js";
import {loadImages} from "./Core/loader.js";

Expand Down Expand Up @@ -55,7 +54,6 @@ let potion, coin, pile, bag;
let quiPlayerStats;
[quiPlayerStats] = await loadImages(["assets/img/gui/uu.png"]);
game.gui.playerStats = quiPlayerStats;
console.log("Sprites chargés");
game.character.sprites = {
up: up,
upLeft: upLeft,
Expand Down Expand Up @@ -85,7 +83,7 @@ startButton.addEventListener("click", () => {
gameLoop();
game.isLooping = true;
// Apparition des ennemis
game.intervalInstances.push(spawnEnemies(canvas, game, Enemy));
game.spawnProcess.push(spawnEnemies(canvas, game, Enemy));
// On ajoute des évènements sur les touches du clavier
window.onmousemove = (e) => game.isLooping ? updateMousePos(e, game) : null;
window.addEventListener('keydown', (e) => game.isLooping ? keyDownListener(e, game) : null);
Expand All @@ -97,18 +95,18 @@ startButton.addEventListener("click", () => {
let idInterval = setInterval(() => {
game.character.object.shoot(game, Projectile);
}, 40000 / game.character.object.fireRate);
game.process.push(idInterval);
game.autofireProcess.push(idInterval);
}
}
});
document.addEventListener("mouseup", (e) => {
game.character.inputs.click = false;
if (game.isLooping) {
game.character.inputs.click = false;
game.process.forEach((idInterval) => {
game.autofireProcess.forEach((idInterval) => {
clearInterval(idInterval);
});
game.process = [];
game.autofireProcess = [];
}
});
})
Expand All @@ -120,7 +118,7 @@ function gameLoop() {
game.animationFrameId = requestAnimationFrame(gameLoop);
clearCanvas(context, canvas);
// On ajoute l'événement de déplacement du personnage
input(game, gameLoop);
input(game, canvas, gameLoop);
// On actualise le personnage
game.character.object.update(context, game);
// On actualise les projectiles
Expand Down