-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (91 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import Sprite from "./js/modules/Sprite.js";
import Player from "./js/modules/Player.js";
import Events from "./js/modules/Events.js";
import animations from "./js/animations/animations.js";
import Canvas from "./js/data/Canvas.js";
import EnemiesData from "./js/data/EnemiesData.js";
import BossData from "./js/data/BossData.js";
import Htmls from "./js/data/Htmls.js";
import CollisionsBlockData from "./js/data/CollisionsBlockData.js";
import Movements from "./js/modules/Movements.js"
const canvas = Canvas.canvas;
const ctx = Canvas.ctx;
const background = new Sprite({
position: {
x: 0,
y: 0,
},
ctx: ctx,
frameRate: 1,
imageSrc: "./img/background/Mapa.jpg",
});
const camera = {
position: {
x: 0,
y: -background.image.height + canvas.height / 2 < -890 ? -background.image.height + canvas.height / 2 : -890,
},
};
//ESTO SE HACE PARA EVITAR ERRORES AL INICIAR LA PRIMERA VEZ
const jugador = new Player({
position: {
x: 150,
y: 1000,
},
canvas: canvas,
ctx: ctx,
imageSrc: "./img/sprites/warrior/Idle.png",
frameRate: 6,
scale: 1,
collisionBlocks: CollisionsBlockData.collisionFloors,
plataformCollisionBlocks: CollisionsBlockData.collisionPlataforms,
camera: camera,
frameDelay: 10,
animations: animations.Warrior,
life: 100
});
const draw = () => {
window.requestAnimationFrame(draw);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.scale(2, 2);
ctx.translate(camera.position.x, camera.position.y);
background.update();
jugador.update();
Htmls.htmlBarra.style.width = jugador.life + "%";
Htmls.htmlPuntos.innerHTML = jugador.points
jugador.velocity.x = 0;
Movements.MovementsPlayer({ player: jugador, camera: camera })
BossData.updateEnemy()
Movements.MovementsEnemy({ player: jugador, enemy: BossData });
EnemiesData.forEach((e, i) => {
Movements.MovementsEnemy({ player: jugador, enemy: e });
e.updateEnemy();
// VERIFICA SI EL ENEMIGO ESTA ELIMINADO Y SI LA VIDA DEL ENEMIGO ES 0, SI TODO ESTO ES CORRECTO, LO ELIMINARA POR COMPLETO
if (e.life <= 0) {
let it = i;
setTimeout(() => {
EnemiesData.delete(it);
}, 500);
}
});
// Esto lo tengo comentado que es para ver los bloques de colicion
// colisionPlataforma.forEach(e=>{
// e.update()
// })
// colisionSuelo.forEach(e=>{
// e.update()
// })
// colisionNPC.forEach(e=>{
// e.update()
// })
ctx.restore();
};
draw();
window.addEventListener("keydown", (e) => {
Events.verifyDown(e.key.toLowerCase());
});
window.addEventListener("keyup", (e) => {
if (e.key.toLowerCase() != "g") {
Events.verifyUp(e.key.toLowerCase());
}
});