forked from Lukas-Bloom/N-igma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenes.js
64 lines (55 loc) · 1.54 KB
/
scenes.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
import { p1, p2 } from "./players.js";
import { PHYS } from "./constants.js";
import { levels } from "./levels.js";
import { levelConf } from "./assets.js";
import { handleKeyEvents } from "./keyEvents.js";
import { handleCollisionEvents } from "./collisionEvents/collisionEvents.js";
import { handleActionEvents } from "./actions.js";
import { spawnPlayers,addTutorialText } from "./gameCreation.js";
//setData("lvlIndex", 4);
scene("game", (p, otherPlayer) => {
let levelIndex = getData("lvlIndex");
gravity(PHYS.GRAVITY);
const level = addLevel(levels()[getData("lvlIndex")], levelConf());
if (p == 1) {
p = p1();
otherPlayer = p2();
spawnPlayers(p, otherPlayer);
}
if (p == 2) {
p = p2();
otherPlayer = p1();
spawnPlayers(otherPlayer, p);
}
addTutorialText();
handleActionEvents(p, otherPlayer, levelIndex, level);
handleKeyEvents(p);
handleCollisionEvents(p, otherPlayer, level, levelIndex);
keyDown("0", () => {
setData("lvlIndex", 0);
setData("playerNumber", 0);
});
// clicked on the screen and hide the mouse
if (!focused()) {
focus();
//document.getElementsByTagName("canvas")[0].style.cursor = "none";
}
});
loadSprite("winScreen", "sprites/menu-background.png");
scene("win", () => {
add([
sprite("winScreen"),
area(),
pos(0, 0),
scale(0.5),
z(-2)
]);
drawText
add([text("You completed the game!"), pos(center()), scale(0.2), z(100)]);
});
export const game = (p, otherPlayer) => {
go("game", p, otherPlayer);
};
export const win = () => {
go("win");
};