-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
352 lines (295 loc) · 11.9 KB
/
app.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
const canvas = document.querySelector("canvas");
const desc = document.querySelector(".main-desc");
let helps = [
"Fivem ATM Hacking Minigame recreated by Walker V",
"Navigate with W,A,S,D and confirm with Space for the left code block.",
"Use the Arrow Keys and ENTER for the right code block"
]
setInterval(() => {
let help = helps[Math.floor(Math.random()*helps.length)]
desc.innerText = help;
}, 10000);
let width = 18;
let height = 10;
let blockSize = 50;
var countdown;
const app = new PIXI.Application({
view: canvas,
width: width*blockSize,
height: height*blockSize,
backgroundColor: 0x181818
});
app.ticker.maxFPS = 5;
const graphics = new PIXI.Graphics();
let state = "main";
const mainScene = new PIXI.Container();
const gameScene = new PIXI.Container();
var updateScene;
const style = new PIXI.TextStyle({ fill: "#21B700", fontSize: 50 });
const startGame = new PIXI.Text("Start Game", style);
startGame.interactive = true;
startGame.buttonMode = true;
startGame.anchor.set(0.5, 0.5);
startGame.position.set((width*blockSize)/2, (height*blockSize)/2);
startGame.on('click', () => {
app.stage.removeChild(mainScene);
app.stage.addChild(gameScene);
updateScene = createGameScene(gameScene);
state = "game";
});
mainScene.addChild(startGame);
const winScene = new PIXI.Container();
const success = new PIXI.Text("ATM Hacked Successfully", style);
success.anchor.set(0.5, 0.5);
success.position.set((width*blockSize)/2, (height*blockSize)/2);
winScene.addChild(success);
const loseScene = new PIXI.Container();
const failure = new PIXI.Text("Failure", style);
failure.anchor.set(0.5, 0.5);
failure.position.set((width*blockSize)/2, (height*blockSize)/2);
loseScene.addChild(failure);
function createGameScene() {
for(let w=0; w<width; w++){
for(let h=0; h<height; h++){
graphics.lineStyle(2, 0xD7F0D7, 1);
graphics.beginFill(0x181818);
graphics.drawRect(w*blockSize, h*blockSize, blockSize, blockSize);
graphics.endFill();
}
}
graphics.beginFill(0x181818);
graphics.drawRect(3*blockSize,0, 12*blockSize, blockSize);
graphics.endFill();
gameScene.addChild(graphics);
const strstyle = new PIXI.TextStyle({ fill: "#21B700", fontSize: 25, fontWeight: "bold"});
for(let w=0; w<width; w++){
for(let h=1; h<height; h++){
let str = genStr(1);
let strText = new PIXI.Text(str, strstyle);
strText.position.set((w*blockSize)+18, (h*blockSize)+12);
gameScene.addChild(strText);
setInterval(() => {
let str2 = genStr(1);
strText.text = str2;
}, 200);
}
}
let firstF = genStr(1);
let firstS = genStr(1);
let firstT = genStr(1);
let secondF = genStr(1);
let secondS = genStr(1);
let secondT = genStr(1);
let firstRandomX = randomInteger(0, width-3);
let firstRandomY = randomInteger(1, height-1);
let secondRandomX = randomInteger(0, width-3);
let secondRandomY = randomInteger(1, height-1);
while(firstRandomX == secondRandomX || firstRandomX+1 == secondRandomX || firstRandomX+2 == secondRandomX || secondRandomX+1 == firstRandomX || secondRandomX+2 == firstRandomX){
secondRandomX = randomInteger(0, width-3);
}
let savedZones = new PIXI.Graphics();
savedZones.lineStyle(2, 0xD7F0D7, 1);
savedZones.beginFill(0x181818);
savedZones.drawRect(firstRandomX*blockSize, firstRandomY*blockSize, blockSize, blockSize);
savedZones.drawRect((firstRandomX+1)*blockSize, firstRandomY*blockSize, blockSize, blockSize);
savedZones.drawRect((firstRandomX+2)*blockSize, firstRandomY*blockSize, blockSize, blockSize);
savedZones.drawRect(secondRandomX*blockSize, secondRandomY*blockSize, blockSize, blockSize);
savedZones.drawRect((secondRandomX+1)*blockSize, secondRandomY*blockSize, blockSize, blockSize);
savedZones.drawRect((secondRandomX+2)*blockSize, secondRandomY*blockSize, blockSize, blockSize);
savedZones.endFill();
gameScene.addChild(savedZones);
let firstTextF = new PIXI.Text(firstF, strstyle);
firstTextF.position.set((firstRandomX*blockSize)+18, (firstRandomY*blockSize)+12);
gameScene.addChild(firstTextF);
let firstTextS = new PIXI.Text(firstS, strstyle);
firstTextS.position.set(((firstRandomX+1)*blockSize)+18, (firstRandomY*blockSize)+12);
gameScene.addChild(firstTextS);
let firstTextT = new PIXI.Text(firstT, strstyle);
firstTextT.position.set(((firstRandomX+2)*blockSize)+18, (firstRandomY*blockSize)+12);
gameScene.addChild(firstTextT);
let secondTextF = new PIXI.Text(secondF, strstyle);
secondTextF.position.set((secondRandomX*blockSize)+18, (secondRandomY*blockSize)+12);
gameScene.addChild(secondTextF);
let secondTextS = new PIXI.Text(secondS, strstyle);
secondTextS.position.set(((secondRandomX+1)*blockSize)+18, (secondRandomY*blockSize)+12);
gameScene.addChild(secondTextS);
let secondTextT = new PIXI.Text(secondT, strstyle);
secondTextT.position.set(((secondRandomX+2)*blockSize)+18, (secondRandomY*blockSize)+12);
gameScene.addChild(secondTextT);
let firstSaved = new PIXI.Container();
let startZone1 = new PIXI.Graphics();
startZone1.lineStyle(2, 0xA8BFA6, 1);
startZone1.beginFill(0xD6F4D4);
startZone1.drawRect(0*blockSize, 0*blockSize, blockSize, blockSize);
startZone1.drawRect(1*blockSize, 0*blockSize, blockSize, blockSize);
startZone1.drawRect(2*blockSize, 0*blockSize, blockSize, blockSize);
startZone1.endFill();
firstSaved.addChild(startZone1);
let firstTextFS = new PIXI.Text(firstF, strstyle);
firstTextFS.position.set((0*blockSize)+18, (0*blockSize)+12);
firstSaved.addChild(firstTextFS);
let firstTextSS = new PIXI.Text(firstS, strstyle);
firstTextSS.position.set((1*blockSize)+18, (0*blockSize)+12);
firstSaved.addChild(firstTextSS);
let firstTextTS = new PIXI.Text(firstT, strstyle);
firstTextTS.position.set((2*blockSize)+18, (0*blockSize)+12);
firstSaved.addChild(firstTextTS);
let secondSaved = new PIXI.Container();
let startZone2 = new PIXI.Graphics();
startZone2.lineStyle(2, 0xA8BFA6, 1);
startZone2.beginFill(0xD6F4D4);
startZone2.drawRect((width-3)*blockSize, 0*blockSize, blockSize, blockSize);
startZone2.drawRect((width-2)*blockSize, 0*blockSize, blockSize, blockSize);
startZone2.drawRect((width-1)*blockSize, 0*blockSize, blockSize, blockSize);
startZone2.endFill();
secondSaved.addChild(startZone2);
let secondTextFS = new PIXI.Text(secondF, strstyle);
secondTextFS.position.set(((width-3)*blockSize)+18, (0*blockSize)+12);
secondSaved.addChild(secondTextFS);
let secondTextSS = new PIXI.Text(secondS, strstyle);
secondTextSS.position.set(((width-2)*blockSize)+18, (0*blockSize)+12);
secondSaved.addChild(secondTextSS);
let secondTextTS = new PIXI.Text(secondT, strstyle);
secondTextTS.position.set(((width-1)*blockSize)+18, (0*blockSize)+12);
secondSaved.addChild(secondTextTS);
gameScene.addChild(firstSaved);
gameScene.addChild(secondSaved);
let time = new PIXI.Text("15:00", strstyle);
time.position.set((width*blockSize)/2, blockSize/2);
time.anchor.set(0.5,0.5);
gameScene.addChild(time);
const keysMaps = {};
const speed = 10;
document.onkeydown = (event) => {
keysMaps[event.code] = true;
};
document.onkeyup = (event) => {
keysMaps[event.code] = false;
};
let countdown = new Countdown(time, 15);
countdown.start();
let completed = 0;
let spaceUsed = false;
let enterUsed = false;
return (delay) => {
if (keysMaps['KeyA'] && (firstSaved.position.x>0)) {
firstSaved.position.x -= blockSize;
}
if (keysMaps['KeyD'] && (firstSaved.position.x<(width*blockSize)-(3*blockSize))) {
firstSaved.position.x += blockSize;
}
if (keysMaps['KeyW'] && (firstSaved.position.y>0)) {
firstSaved.position.y -= blockSize;
}
if (keysMaps['KeyS'] && (firstSaved.position.y<(height-1)*blockSize)) {
firstSaved.position.y += blockSize;
}
if (keysMaps['ArrowLeft'] && secondSaved.position.x > -15*blockSize) {
secondSaved.position.x -= blockSize;
}
if (keysMaps['ArrowRight'] && secondSaved.position.x<0) {
secondSaved.position.x += blockSize;
}
if (keysMaps['ArrowUp'] && (secondSaved.position.y>0)) {
secondSaved.position.y -= blockSize;
}
if (keysMaps['ArrowDown'] && (secondSaved.position.y<(height-1)*blockSize)) {
secondSaved.position.y += blockSize;
}
if (keysMaps['Space'] ){
if(firstSaved.position.x == firstRandomX*blockSize && firstSaved.position.y == firstRandomY*blockSize){
if(spaceUsed == false) {
completed++;
spaceUsed = true;
}
} else {
app.stage.removeChild(gameScene);
app.stage.addChild(loseScene)
}
}
if (keysMaps['Enter'] ){
let x = 750+secondSaved.position.x;
if(x == secondRandomX*blockSize && secondSaved.position.y == secondRandomY*blockSize){
if(enterUsed == false) {
completed++;
enterUsed = true;
}
} else {
app.stage.removeChild(gameScene);
app.stage.addChild(loseScene);
}
}
if(completed == 2){
countdown.stop();
}
}
}
app.stage.addChild(mainScene);
app.ticker.add(
(delay) => {
if (state === "game") {
updateScene(delay);
}
}
);
function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function genStr(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
function Countdown(elem, seconds) {
var that = {};
that.elem = elem;
that.seconds = seconds;
that.totalTime = seconds * 100;
that.usedTime = 0;
that.startTime = +new Date();
that.timer = null;
that.count = function() {
that.usedTime = Math.floor((+new Date() - that.startTime) / 10);
var tt = that.totalTime - that.usedTime;
if (tt <= 0) {
that.elem.text = '00.00';
clearInterval(that.timer);
app.stage.removeChild(gameScene);
app.stage.addChild(loseScene)
} else {
var mi = Math.floor(tt / (60 * 100));
var ss = Math.floor((tt - mi * 60 * 100) / 100);
var ms = tt - Math.floor(tt / 100) * 100;
that.elem.text = that.fillZero(ss) + "." + that.fillZero(ms);
}
};
that.init = function() {
if(that.timer){
clearInterval(that.timer);
that.elem.text = '00.00';
that.totalTime = seconds * 100;
that.usedTime = 0;
that.startTime = +new Date();
that.timer = null;
}
};
that.start = function() {
if(!that.timer){
that.timer = setInterval(that.count, 1);
}
};
that.stop = function() {
if (that.timer) clearInterval(that.timer);
app.stage.removeChild(gameScene);
app.stage.addChild(winScene);
};
that.fillZero = function(num) {
return num < 10 ? '0' + num : num;
};
return that;
}