-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
executable file
·177 lines (133 loc) · 4.81 KB
/
game.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
window.onload = function () {
//start crafty
Crafty.init(1408, 896);
Crafty.mapSize = {w:22,h:14};
Crafty.tileSize = 64;
Crafty.npc = [];
musique= Crafty.e("Musique");
function finicharger() {
musique = Crafty.e("Musique");
musique.jeu();
var map = [];
for( i=0;i< Crafty.mapSize.w; i++)
map[i] = [];
Crafty("MapTile").each(function(){
map[this._x/Crafty.tileSize][this._y/Crafty.tileSize] = this.tilePos();
});
Crafty('blocked').each(function() {
this.addComponent('Collision');
this.collision([0,64],[64,64],[64,0],[0,0]);
})
Crafty.PathFinder = Crafty.e('AStar, PathFinder').setTiles(map);
Crafty.RayTracer = Crafty.e('RayTracing');
Crafty('Teenager').each(function() {
Crafty.npc.push(this);
})
Crafty('Teenager').each(function() {
this.checkFriend();
})
}
function enterPanicMode() {
Crafty.enterPanicMode();
}
//method to generate the map
function generateWorld() {
Crafty.e("TiledLevel, Input").tiledLevel('assets/level01.json?v'+ (Math.random() * 1E9 |0) ,'DOM',finicharger)
.bind('KeyDown', function (e) {
if (e.key == Crafty.keys['ESC'])
if( Jeu.paused )
Jeu.Resume();
else
Jeu.Pause();
});
}
//the loading screen that will display while our assets load
Crafty.scene("loading", function () {
Crafty.load([
'assets/sprites/ecran-accueil.png',
'assets/sprites/ecran-credits.png',
'assets/sprites/ecran-scores.png',
'assets/sprites/texture64.png',
'assets/sprites/teenagers.png',
'assets/map.json',
'assets/sprites/barreEmpty.png',
'assets/sprites/barreFull.png',
'assets/sprites/slasher.png',
'assets/sprites/onoClac.png',
'assets/sprites/onoPsht.png',
'assets/sprites/onoFlush.png',
'assets/sprites/onoDring.png',
'assets/sprites/traps.png'
],function() {
Crafty.scene("ecran");
});
//black background with some loading text
Crafty.background("#fff");
Crafty.e("2D, DOM, Text, color").attr({ w: 100, h: 20, x: 150, y: 120 })
.text("Loading")
.css({ "text-align": "center" });
});
Crafty.scene("ecran", function () {
musique.peur();
Crafty.e("2D, DOM, Image, Mouse").attr({ w: 1440, h: 900, x: 0, y: 0 })
.image("assets/sprites/ecran-accueil.png")
;
Crafty.e( "2D, DOM,Mouse").attr({ w: 1440, h: 450, x: 0, y: 0 }).bind("Click", function() {
musique.stop();
Crafty.scene("main");
});
Crafty.e( "2D,DOM, Mouse").attr({ w: 1440, h: 450, x: 0, y: 450 }).bind("Click", function() {
musique.stop();
Crafty.scene("credits");
});
//createNight();
//create our player entity with some premade components
});
Crafty.scene("credits", function () {
musique.doubt();
Crafty.e("2D, DOM, Image, Mouse").attr({ w: 1440, h: 900, x: 0, y: 0 })
.image("assets/sprites/ecran-credits.png").bind("Click", function() {
musique.stop();
Crafty.scene("ecran");
});
//createNight();
//create our player entity with some premade components
});
Crafty.scene("over", function () {
musique.doubt();
Crafty.e("2D, DOM, Image, Mouse").attr({ w: 1440, h: 900, x: 0, y: 0 })
.image("assets/sprites/ecran-scores.png").bind("Click", function() {
musique.stop();
Crafty.scene("ecran");
});
//createNight();
//create our player entity with some premade components
});
Crafty.scene("main", function () {
Crafty.trapLefts = 5;
Crafty.panic = false;
Crafty.deaths = 0;
Crafty.escaped = 0;
InventoryLoad();
Crafty.e("Inventory");
Crafty.e("Teenagers");
generateWorld();
//createNight();
//create our player entity with some premade components
});
Crafty.bind('NpcDead', function() {
Crafty.deaths++;
if(Crafty.deaths+Crafty.escaped >=5) {
Crafty.scene("over");
}
});
Crafty.bind('NpcEscape', function() {
Crafty.escaped++;
if(Crafty.deaths+Crafty.escaped >=5) {
Crafty.scene("over");
}
})
Crafty.bind('PANIC',enterPanicMode);
//automatically play the loading scene
Crafty.scene("loading");
};