-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveMigrants.html
More file actions
304 lines (256 loc) · 8.63 KB
/
saveMigrants.html
File metadata and controls
304 lines (256 loc) · 8.63 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<html>
<head>
<meta charset="UTF-8" />
<title>Sauve Les Migrants </title>
<script src="//cdn.jsdelivr.net/npm/phaser@3.22.0/dist/phaser.js"></script>
</head>
<body>
<div>
<script type="text/javascript">
var config = {
type: Phaser.AUTO,
width: 1024,
height: 768,
dom: {
createContainer: true
},
physics: {
default: 'arcade',
gravity: { y: 900 },
arcade: {
debug: false
}
},
scene: {
preload: preload, //Fonction pour preciser les précharges
create: create, //Fonction pour créer les objets et les animations
update: update //Fonction pour définir les actions
}
};
var game = new Phaser.Game(config); //l'objet de Phaser
//Ici on définit les variables
//
var cursors;
var positif;
var negatif;
var navire;
var background;
var alan;
var damage=100;
var migrant=0;
var migrantTxt;
var damageTxt;
var infoTxt;
var rock;
var police;
//
//
function preload ()
{
this.load.image('background1', 'photos/bal.GIF');
this.load.spritesheet('alanHorizon', 'photos/aman.png', { frameWidth: 144, frameHeight: 300 }); //mouvement horizontal
this.load.spritesheet('alanHaut', 'photos/loki.png', { frameWidth: 111, frameHeight: 200 }); //mouvement vers le haut
this.load.spritesheet('alanBas', 'photos/moki.png', { frameWidth: 111, frameHeight: 200 }); //mouvement vers le bas
this.load.image('yildiz', 'photos/as.png');
this.load.image('vague', 'photos/wave.png');
this.load.image('navireresim', 'photos/alan.png');
this.load.image('policeresim', 'photos/police2.png');
this.load.image('kaya', 'photos/rock3.png');
this.load.image('denek', 'photos/eze.png');
this.load.image('cocuk', 'photos/gulay2.png');
this.load.image('cezaevi', 'photos/prison.png');
}
function create ()
{
face = this.add.image('cezaevi', 'photos/prison.png');
face = this.add.image('cocuk', 'photos/gulay2.png');
face = this.add.image('denek', 'photos/eze.png');
background = this.add.image(512, 384, 'background1');
alan = this.physics.add.sprite(100, 450, 'alanHorizon').setScale(0.3); //Ici,on ajoute notre caractére nommée "alan",on utilise la fonction setScale pour dimensionner
cursors = this.input.keyboard.createCursorKeys();
negatif = this.physics.add.staticGroup();
for (i = 0; i < 25; i++)
{
x = Phaser.Math.Between(0, 1024);
y = Phaser.Math.Between(0, 768);
negatif.create(x, y, 'vague').refreshBody();
}
for (i = 0; i < 10; i++)
{
x = Phaser.Math.Between(0, 1024);
y = Phaser.Math.Between(0, 768);
negatif.create(x, y, 'kaya').refreshBody();
}
positif = this.physics.add.staticGroup();
for (i = 0; i < 11; i++)
{
x = Phaser.Math.Between(0, 1024);
y = Phaser.Math.Between(0, 768);
positif.create(x, y, 'yildiz').refreshBody();
}
police= this.physics.add.sprite(300, 300, 'policeresim').setScale(0.5);
navire = this.physics.add.sprite(700, 500, 'navireresim').setScale(0.5);
//creaiton des reactions entre alan et les objets
this.physics.add.overlap(alan, positif, ramasseDb, null, this);
this.physics.add.overlap(alan, negatif, vagueCarp, null, this);
this.physics.add.overlap(alan, navire, newScene, null, this);
this.physics.add.overlap(alan, police, newScene2, null, this);
this.anims.create({
key: 'up',
frames: this.anims.generateFrameNumbers('alanHaut', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'down',
frames: this.anims.generateFrameNumbers('alanBas', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('alanHorizon', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'turn',
frames: [ { key: 'alanHorizon', frame: 4 } ],
frameRate: 20
});
this.anims.create({
key: 'right',
frames: this.anims.generateFrameNumbers('alanHorizon', { start: 5, end: 8 }),
frameRate: 10,
repeat: -1
});
migrantTxt = this.add.text(16, 16, 'migrant: 0', { font: "bold 24px Verdana", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" });
damageTxt = this.add.text(16, 46, 'damage: 100', {font: "bold 24px Verdana", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle"});
infoTxt = this.add.text(this.scene.centerX, this.scene.centerY, '', { font: "bold 64px Verdana", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" })
}
function update ()
{
if (cursors.up.isDown)
{
alan.setVelocityY(-160);
alan.anims.play('up', true);
}
else if (cursors.down.isDown)
{
alan.setVelocityY(160);
alan.anims.play('down', true);
}
else
{
alan.setVelocityY(0);
}
if (cursors.left.isDown)
{
alan.setVelocityX(-160);
alan.anims.play('left', true);
}
else if (cursors.right.isDown)
{
alan.setVelocityX(160);
alan.anims.play('right', true);
}
else
{
alan.setVelocityX(0);
}
if (!(cursors.left.isDown||cursors.right.isDown||cursors.up.isDown||cursors.down.isDown))
{
alan.anims.play('turn');
}
if (damage < 10)
{
face = this.add.image( 500, 450, "denek");
infoTxt = this.add.text(this.scene.centerX, this.scene.centerY, "Au secours!!!", { font: "bold 64px Verdana", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }) ;
infoTxt.setTint(0xff00ff, 0xffff00, 0x0000ff, 0xff0000);
Phaser.Display.Align.In.Center(infoTxt, this.add.zone(512, 354, 1024, 768));
alan.destroy();
police.destroy();
background.destroy();
damageTxt.destroy();
navire.destroy();
Phaser.Actions.SetVisible(negatif.getChildren(), false);
negatif.clear();
Phaser.Actions.SetVisible(positif.getChildren(), false);
positif.clear();
return;
}
}
//les autres fontions
function vagueCarp (alan, negatif)
{ //la reaction entre alan et vague(le feur) pour diminuer damage
negatif.disableBody(true, true);
damage -= 10;
damageTxt.setText('damage: ' + damage);
}
function ramasseDb (alan, positif)
{ // La reaction entre alan et migrant pour augmenter le nombre
positif.disableBody(true, true);
migrant += 1;
migrantTxt.setText('migrant: ' + migrant);
}
function newScene (alan, navire)
{
if (migrant>=10){
infoTxt.setVisible(true);
face = this.add.image( 500, 450, "cocuk");
infoTxt.setText('Merci, vous m`avez sauvé!');
infoTxt.setTint(0xff00ff, 0xffff00, 0x0000ff, 0xff0000);
Phaser.Display.Align.In.Center(infoTxt, this.add.zone(512, 154, 1024, 768));
alan.setX(0);
alan.setY(0);
// alan.setScale(1);
alan.disableInteractive();
police.destroy();
background.destroy();
navire.destroy();
Phaser.Actions.SetVisible(negatif.getChildren(), false);
negatif.clear();
Phaser.Actions.SetVisible(positif.getChildren(), false);
positif.clear();
alan.anims.play('turn');
}
else {
infoTxt.setVisible(true);
infoTxt.setText('Sauvez Tous les Migrants !!!');
infoTxt.setTint(0xff00ff, 0xffff00, 0x0000ff, 0xff0000);
Phaser.Display.Align.In.Center(infoTxt, this.add.zone(512, 354, 1024, 768));
this.time.delayedCall(1000, cacheInfo, [], this);
}
}
function cacheInfo ()
{
infoTxt.setVisible(false);
}
///time icin
function newScene2 (alan, police)
{
if (migrant>=0){
infoTxt.setVisible(true);
face = this.add.image( 500, 450, "cezaevi");
infoTxt.setText('PRISON!');
infoTxt.setTint(0xff00ff, 0xffff00, 0x0000ff, 0xff0000);
Phaser.Display.Align.In.Center(infoTxt, this.add.zone(512, 154, 1024, 768));
alan.setX(0);
alan.setY(0);
// alan.setScale(1);
alan.disableInteractive();
police.destroy();
background.destroy();
navire.destroy();
Phaser.Actions.SetVisible(negatif.getChildren(), false);
negatif.clear();
Phaser.Actions.SetVisible(positif.getChildren(), false);
positif.clear();
alan.anims.play('turn');
}
}
//
</script>
</div>
</body>
</html>