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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
var cvs,WGL,vpw,vph,hdiv;
var fsh="varying lowp vec4 vC;void main(void){gl_FragColor=vC;}";
var vsh="attribute vec3 vp;attribute vec4 vc;uniform mat4 mmodelview;uniform mat4 mprojection;varying lowp vec4 vC;void main(void){gl_Position=mprojection*mmodelview*vec4(vp,1.);vC=vc;}";
var shp;
var vbufsize=4096;
var vbo,ibo;
var vb=new Float32Array(vbufsize*7);
var ib=new Uint16Array(vbufsize*6/4);
var Mprojection,Mmodelview;
var primc;
var kst=[];
var pos=[-2.5,-7.4,20];
var ofs=[0.9,3.5,20];
var pp;
var lines=[];
var spheres=[];
var linesold=[];
var spheresold=[];
var survival=-1,survivalsw=-1;
var health,state;
var CLines=0;
var CSpheres=0;
var ismobile=false;
var deathcounter=0;
var brutemode=false;
var Line=function()
{
if(Math.random()>0.5)
{
this.x1=-10;this.x2=10;
this.y1=9.8-Math.random()*19.6;
this.y2=9.8-Math.random()*19.6;
}
else
{
this.y1=-10;this.y2=10;
this.x1=9.8-Math.random()*19.6;
this.x2=9.8-Math.random()*19.6;
}
this.c=0;
}
Line.prototype.coltest=function(x,y)
{
var d=Math.abs((this.y2-this.y1)*x-(this.x2-this.x1)*y+this.x2*this.y1-this.y2*this.x1)/
Math.sqrt((this.y2-this.y1)*(this.y2-this.y1)+(this.x2-this.x1)*(this.x2-this.x1));
var a=Math.atan(x/y);while(a>Math.PI/4)a-=Math.PI/2;while(a<-Math.PI/4)a+=Math.PI/2;
var df=0.1*1/Math.cos(a);
if(d<df)return true;else return false;
}
var Sphere=function()
{
this.x=10-Math.random()*20;
this.y=10-Math.random()*20;
this.timer=0;this.r=0.2;
}
Sphere.prototype.update=function()
{
var d=Math.sqrt((this.x-pp.x)*(this.x-pp.x)+(this.y-pp.y)*(this.y-pp.y));
if(d<0.5&&this.timer===0)this.timer=1;
if(this.timer>0&&state===0)
{
++this.timer;health+=0.01;
this.r+=0.02;if(health>1)health=1;
}
if(this.timer>25)this.timer=-1;
}
Sphere.prototype.draw=function(x,y,a)
{
if(this.timer!==-1)pushSphere(x,y,0,this.r,[0,1,0,a*(0.6-this.timer*0.6/25)]);
}
function createShader(sh,t)
{
var shader=WGL.createShader(t);
WGL.shaderSource(shader,sh);
WGL.compileShader(shader);
if(!WGL.getShaderParameter(shader,WGL.COMPILE_STATUS))
{
alert("shader error..."+WGL.getShaderInfoLog(shader));
return null;
}
return shader;
}
function pushQuad(a)
{
if(primc>=vbufsize/4)batchGL();
for(var i=0;i<4;++i)
for(var j=0;j<7;++j)vb[primc*7*4+i*7+j]=a[i*7+j];
++primc;
}
function pushCube(x1,y1,x2,y2,thx,thz,col)
{
var dd=new v3d(x2-x1,y2-y1);dd.n();dd.ms(thx);
var de=dd.mm(buildRotationMatrix(Math.PI/2,0,0,1));
var df=dd.mm(buildRotationMatrix(-Math.PI/2,0,0,1));
var a=new v3d(x1+de.x,y1+de.y),b=new v3d(x1+df.x,y1+df.y);
var c=new v3d(x2+de.x,y2+de.y),d=new v3d(x2+df.x,y2+df.y);
pushQuad([
a.x,a.y,0,col[0],col[1],col[2],col[3],
b.x,b.y,0,col[0],col[1],col[2],col[3],
d.x,d.y,0,col[0],col[1],col[2],col[3],
c.x,c.y,0,col[0],col[1],col[2],col[3]
]);
pushQuad([
a.x,a.y,thz,col[0],col[1],col[2],col[3],
b.x,b.y,thz,col[0],col[1],col[2],col[3],
d.x,d.y,thz,col[0],col[1],col[2],col[3],
c.x,c.y,thz,col[0],col[1],col[2],col[3]
]);
pushQuad([
a.x,a.y,0,col[0],col[1],col[2],col[3],
a.x,a.y,thz,col[0],col[1],col[2],col[3],
b.x,b.y,thz,col[0],col[1],col[2],col[3],
b.x,b.y,0,col[0],col[1],col[2],col[3]
]);
pushQuad([
c.x,c.y,0,col[0],col[1],col[2],col[3],
c.x,c.y,thz,col[0],col[1],col[2],col[3],
d.x,d.y,thz,col[0],col[1],col[2],col[3],
d.x,d.y,0,col[0],col[1],col[2],col[3]
]);
pushQuad([
a.x,a.y,0,col[0],col[1],col[2],col[3],
a.x,a.y,thz,col[0],col[1],col[2],col[3],
c.x,c.y,thz,col[0],col[1],col[2],col[3],
c.x,c.y,0,col[0],col[1],col[2],col[3]
]);
pushQuad([
b.x,b.y,0,col[0],col[1],col[2],col[3],
b.x,b.y,thz,col[0],col[1],col[2],col[3],
d.x,d.y,thz,col[0],col[1],col[2],col[3],
d.x,d.y,0,col[0],col[1],col[2],col[3]
]);
}
function pushSphere(x,y,z,r,col)
{
for(var i=0;i<12;++i)
for(var j=0;j<12;++j)
{
var r1=r*Math.sin(i*Math.PI/12);
var a=new v3d(x+r1*Math.cos(j*Math.PI/12*2),y+r1*Math.sin(j*Math.PI/12*2),z+r*Math.cos(i*Math.PI/12));
var b=new v3d(x+r1*Math.cos((j+1)*Math.PI/12*2),y+r1*Math.sin((j+1)*Math.PI/12*2),z+r*Math.cos(i*Math.PI/12));
r1=r*Math.sin((i+1)*Math.PI/12);
var c=new v3d(x+r1*Math.cos(j*Math.PI/12*2),y+r1*Math.sin(j*Math.PI/12*2),z+r*Math.cos((i+1)*Math.PI/12));
var d=new v3d(x+r1*Math.cos((j+1)*Math.PI/12*2),y+r1*Math.sin((j+1)*Math.PI/12*2),z+r*Math.cos((i+1)*Math.PI/12));
pushQuad([
a.x,a.y,a.z,col[0],col[1],col[2],col[3],
b.x,b.y,b.z,col[0],col[1],col[2],col[3],
d.x,d.y,d.z,col[0],col[1],col[2],col[3],
c.x,c.y,c.z,col[0],col[1],col[2],col[3]
]);
}
}
function survivalNext()
{
linesold=lines.slice(0);spheresold=spheres.slice(0);
survivalsw=0;CLines=Math.floor(CLines*1.6);CSpheres=CLines<40?0:CLines<80?5:10;
lines.length=0;spheres.length=0;++survival;
for(var i=0;i<CLines;++i)lines.push(new Line());
for(var i=0;i<CSpheres;++i)spheres.push(new Sphere());
document.getElementById("HUDDiv").innerHTML="Lines: "+CLines+" Mode: Sometimes Naïve! Level: "+survival+(brutemode?" Brute Mode!!":"");
}
function survivalInit()
{
document.getElementById("winDiv").style.display="none";
document.getElementById("loseDiv").style.display="none";
document.getElementById("HUDDiv").style.display="block";
document.getElementById("resetbtn").style.display="none";
document.getElementById("selDiv").style.display="none";
document.getElementById("easybtn").style.display="none";
document.getElementById("normalbtn").style.display="none";
document.getElementById("hardbtn").style.display="none";
document.getElementById("extremebtn").style.display="none";
document.getElementById("easy2btn").style.display="none";
document.getElementById("survivalbtn").style.display="none";
document.getElementById("healthDiv").style.display="block";
document.getElementById("brutesw").style.display="none";
lines.length=0;spheres.length=0;survival=0;survivalsw=-1;
CLines=10;CSpheres=0;health=1;state=0;pp=new v3d(-9.9,-9.9);
document.getElementById("HUDDiv").innerHTML="Lines: "+CLines+" Mode: Sometimes Naïve! Level: "+survival+(brutemode?" Brute Mode!!":"");
for(var i=0;i<CLines;++i)lines.push(new Line());
for(var i=0;i<CSpheres;++i)spheres.push(new Sphere());
}
function gameInit(cl,cs,cd)
{
document.getElementById("winDiv").style.display="none";
document.getElementById("loseDiv").style.display="none";
document.getElementById("HUDDiv").style.display="block";
document.getElementById("resetbtn").style.display="none";
document.getElementById("selDiv").style.display="none";
document.getElementById("easybtn").style.display="none";
document.getElementById("normalbtn").style.display="none";
document.getElementById("hardbtn").style.display="none";
document.getElementById("extremebtn").style.display="none";
document.getElementById("easy2btn").style.display="none";
document.getElementById("survivalbtn").style.display="none";
document.getElementById("healthDiv").style.display="block";
document.getElementById("brutesw").style.display="none";
CLines=Math.floor(cl);CSpheres=cs;survival=-1;survivalsw=-1;
document.getElementById("HUDDiv").innerHTML="Lines: "+CLines+" Mode: "+cd+(brutemode?" Brute Mode!!":"");
lines.length=0;spheres.length=0;
pp=new v3d(-9.9,-9.9);health=1;state=0;
for(var i=0;i<CLines;++i)lines.push(new Line());
for(var i=0;i<CSpheres;++i)spheres.push(new Sphere());
}
function reset()
{
document.getElementById("winDiv").style.display="none";
document.getElementById("loseDiv").style.display="none";
document.getElementById("HUDDiv").style.display="none";
document.getElementById("resetbtn").style.display="none";
document.getElementById("selDiv").style.display="block";
document.getElementById("easybtn").style.display="block";
document.getElementById("normalbtn").style.display="block";
document.getElementById("hardbtn").style.display="block";
document.getElementById("extremebtn").style.display="block";
document.getElementById("easy2btn").style.display="block";
document.getElementById("survivalbtn").style.display="block";
document.getElementById("healthDiv").style.display="none";
document.getElementById("brutesw").style.display="block";
document.getElementById("p1sbtn").style.display="none";
}
function init()
{
window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame;
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
)
ismobile=true;
cvs=document.getElementById("glCvs");
if(!window.devicePixelRatio)window.devicePixelRatio=1;
cvs.width=window.innerWidth*(ismobile?0.9:0.6);
cvs.height=cvs.width/16*9;
cvs.style.width=cvs.width+"px";
cvs.style.height=cvs.height+"px";
document.getElementById("containerDiv").style.width=cvs.width+"px";
document.getElementById("containerDiv").style.height=cvs.height+"px";
cvs.width=cvs.width*window.devicePixelRatio;
cvs.height=cvs.height*window.devicePixelRatio;
vpw=cvs.width;vph=cvs.height;
hdiv=document.getElementById("healthDiv");pp=new v3d(-9.9,-9.9);
try
{WGL=cvs.getContext("webgl")||cvs.getContext("experimental-webgl");}
catch(e){WGL=null;}
if(!WGL){alert("WebGL is not supported by your browser...");return;}
WGL.clearColor(0.5,0.5,0.5,1.0);
WGL.clearDepth(1);
WGL.enable(WGL.DEPTH_TEST);
WGL.depthFunc(WGL.LESS);
WGL.enable(WGL.BLEND);
WGL.blendFunc(WGL.SRC_ALPHA,WGL.ONE_MINUS_SRC_ALPHA);
WGL.clear(WGL.COLOR_BUFFER_BIT|WGL.DEPTH_BUFFER_BIT);
WGL.viewport(0,0,cvs.width,cvs.height);
shp=WGL.createProgram();
var fshs=createShader(fsh,WGL.FRAGMENT_SHADER);
var vshs=createShader(vsh,WGL.VERTEX_SHADER);
WGL.attachShader(shp,vshs);WGL.attachShader(shp,fshs);
WGL.linkProgram(shp);
if(!WGL.getProgramParameter(shp,WGL.LINK_STATUS))
{
alert("shader link error...");
}
WGL.useProgram(shp);
vbo=WGL.createBuffer();
WGL.bindBuffer(WGL.ARRAY_BUFFER,vbo);
WGL.bufferData(WGL.ARRAY_BUFFER,vb,WGL.STATIC_DRAW);
var vpp=WGL.getAttribLocation(shp,"vp");
var vcp=WGL.getAttribLocation(shp,"vc");
WGL.enableVertexAttribArray(vpp);
WGL.enableVertexAttribArray(vcp);
WGL.bindBuffer(WGL.ARRAY_BUFFER,vbo);
WGL.vertexAttribPointer(vpp,3,WGL.FLOAT,false,7*4,0);
WGL.vertexAttribPointer(vcp,4,WGL.FLOAT,false,7*4,3*4);
for(var i=0,n=0,p=0;i<vbufsize/4;++i)
{
ib[p++]=n;ib[p++]=n+1;
ib[p++]=n+2;ib[p++]=n+2;
ib[p++]=n+3;ib[p++]=n;
n+=4;
}
ibo=WGL.createBuffer();
WGL.bindBuffer(WGL.ELEMENT_ARRAY_BUFFER,ibo);
WGL.bufferData(WGL.ELEMENT_ARRAY_BUFFER,ib,WGL.STATIC_DRAW);
document.addEventListener('keydown',function(e){kst[e.keyCode]=1;});
document.addEventListener('keyup',function(e){kst[e.keyCode]=0;});
window.addEventListener('deviceorientation',
function(e)
{
if(!ismobile||window.orientation===0)
{
if(e.gamma>=10)kst[68]=1;else kst[68]=0;//>
if(e.gamma<=-10)kst[65]=1;else kst[65]=0;//<
if(e.beta>=10)kst[83]=1;else kst[83]=0;//V
if(e.beta<=-10)kst[87]=1;else kst[87]=0;//^
}
if(window.orientation===90&&ismobile)
{
if(e.gamma>=10)kst[87]=1;else kst[87]=0;//^
if(e.gamma<=-10)kst[83]=1;else kst[83]=0;//V
if(e.beta>=10)kst[68]=1;else kst[68]=0;//>
if(e.beta<=-10)kst[65]=1;else kst[65]=0;//<
}
if(window.orientation===-90&&ismobile)
{
if(e.gamma>=10)kst[83]=1;else kst[83]=0;//V
if(e.gamma<=-10)kst[87]=1;else kst[87]=0;//^
if(e.beta>=10)kst[65]=1;else kst[65]=0;//<
if(e.beta<=-10)kst[68]=1;else kst[68]=0;//>
}
});
document.getElementById("brutesw").addEventListener('mouseenter',
function(){document.getElementById("brutesw").style.backgroundColor=brutemode?"rgba(0,255,0,0.7)":"rgba(192,192,192,0.7)";}
);
document.getElementById("brutesw").addEventListener('mouseleave',
function(){document.getElementById("brutesw").style.backgroundColor=brutemode?"rgba(0,255,0,0.6)":"rgba(192,192,192,0.6)";}
);
document.getElementById("brutesw").addEventListener('mousedown',
function(){document.getElementById("brutesw").style.backgroundColor=brutemode?"rgba(0,255,0,0.8)":"rgba(192,192,192,0.8)";}
);
document.getElementById("brutesw").addEventListener('click',
function(){brutemode=!brutemode;document.getElementById("brutesw").style.backgroundColor=brutemode?"rgba(0,255,0,0.7)":"rgba(192,192,192,0.7)";}
);
state=2;requestAnimationFrame(mainloop);
}
function mainloop()
{
WGL.clearColor(0.5,0.5,0.5,1.0);
WGL.clearDepth(1);
WGL.clear(WGL.COLOR_BUFFER_BIT|WGL.DEPTH_BUFFER_BIT);
primc=0;
Mmodelview=buildIdentityMatrix();
if(kst[82]===1){pos=[0,-2,26];ofs=[0.9,3.5,20];}//0.2 0.6 9
if(state===0&&survivalsw===-1)
{
if(kst[87]===1&&pp.y<= 9.9)pp.y+=0.04;//W
if(kst[83]===1&&pp.y>=-9.9)pp.y-=0.04;//S
if(kst[65]===1&&pp.x>=-9.9)pp.x-=0.04;//A
if(kst[68]===1&&pp.x<= 9.9)pp.x+=0.04;//D
if(Math.sqrt((pp.x-9.9)*(pp.x-9.9)+(pp.y-9.9)*(pp.y-9.9))<0.1)
{
if(survival!==-1)survivalNext();
else
{
document.getElementById("winDiv").style.display="block";
document.getElementById("resetbtn").style.display="block";
state=1;
}
}
if(health<0)
{
document.getElementById("loseDiv").style.display="block";
document.getElementById("resetbtn").style.display="block";
state=-1;if(++deathcounter>=5)
document.getElementById("p1sbtn").style.display="block";
}
}
pos[0]=pp.x*0.75+1-ofs[0];pos[1]=pp.y*0.75+1-ofs[1];pos[2]=ofs[2];
Mmodelview=buildLookAtMatrix(pos,[pp.x*0.75+1,pp.y*0.75+1,pp.z*0.75],[0,0,1]);
/*if(kst[74]===1)ofs[0]+=0.1;//J
if(kst[76]===1)ofs[0]-=0.1;//L
if(kst[73]===1)ofs[1]+=0.1;//I
if(kst[75]===1)ofs[1]-=0.1;//K
if(kst[85]===1)ofs[2]+=0.1;//U
if(kst[79]===1)ofs[2]-=0.1;//O*/
if(kst[81]===1&&ofs[2]>10){ofs[0]-=0.01;ofs[1]-=0.03;ofs[2]-=0.45;}
if(kst[69]===1&&ofs[2]<30){ofs[0]+=0.01;ofs[1]+=0.03;ofs[2]+=0.45;}
if(survivalsw===-1)
{
pushCube(-10,-10,-10, 10,.05,.1,[0.01,0.01,0.01,0.8]);
pushCube( 10,-10, 10, 10,.05,.1,[0.01,0.01,0.01,0.8]);
pushCube(-10,-10, 10,-10,.05,.1,[0.01,0.01,0.01,0.8]);
pushCube(-10, 10, 10, 10,.05,.1,[0.01,0.01,0.01,0.8]);
var leathality=0.0025;
if(CLines<=40)leathality=survival===-1?0.004:0.003;
if(CLines>=160)leathality=survival===-1?0.002:0.0015;
if(CLines>=200)leathality=0.001;
for(var i=0;i<CLines;++i)
{
if(state===1)
pushCube(lines[i].x1,lines[i].y1,lines[i].x2,lines[i].y2,0.05,.1,[lines[i].c,0,0,0.8]);
else
{
if(lines[i].coltest(pp.x,pp.y))
{
if(state===0)
{
health-=leathality;
if(brutemode)
{
if(lines[i].c<=0.1)lines[i].c=0.09;else health=-1;
}
else
if(lines[i].c<1)lines[i].c+=0.01;
}
pushCube(lines[i].x1,lines[i].y1,lines[i].x2,lines[i].y2,0.05,.1,[1,1-lines[i].c,1-lines[i].c,0.8]);
}
else
{
if(brutemode&&Math.abs(lines[i].c-0.09)<1e-6)lines[i].c=0.5;
pushCube(lines[i].x1,lines[i].y1,lines[i].x2,lines[i].y2,0.05,.1,[lines[i].c,0,0,0.8]);
}
}
}
for(var i=0;i<CSpheres;++i){spheres[i].update();spheres[i].draw(spheres[i].x,spheres[i].y,1);}
pushCube(pp.x,pp.y-0.1,pp.x,pp.y+0.1,.1,.2,[0,1,0,1]);
}
else
{
pp.x=pp.y=9.9-19.8*survivalsw/60;
pos[0]=pp.x*0.75+1-ofs[0];pos[1]=pp.y*0.75+1-ofs[1];pos[2]=ofs[2];
Mmodelview=buildLookAtMatrix(pos,[pp.x*0.75+1,pp.y*0.75+1,pp.z*0.75],[0,0,1]);
var dold=-20*(survivalsw/60);
var dnew=20+dold;
pushCube(-10+dold,-10+dold,-10+dold, 10+dold,.05,.1,[0.01,0.01,0.01,0.8-0.8*(survivalsw/60)]);
pushCube( 10+dold,-10+dold, 10+dold, 10+dold,.05,.1,[0.01,0.01,0.01,0.8-0.8*(survivalsw/60)]);
pushCube(-10+dold,-10+dold, 10+dold,-10+dold,.05,.1,[0.01,0.01,0.01,0.8-0.8*(survivalsw/60)]);
pushCube(-10+dold, 10+dold, 10+dold, 10+dold,.05,.1,[0.01,0.01,0.01,0.8-0.8*(survivalsw/60)]);
for(var i=0;i<linesold.length;++i)
pushCube(linesold[i].x1+dold,linesold[i].y1+dold,linesold[i].x2+dold,linesold[i].y2+dold,0.05,.1,[linesold[i].c,0,0,0.8-0.8*(survivalsw/60)]);
for(var i=0;i<spheresold.length;++i)
spheresold[i].draw(spheresold[i].x+dold,spheresold[i].y+dold,1-survivalsw/60);
pushCube(-10+dnew,-10+dnew,-10+dnew, 10+dnew,.05,.1,[0.01,0.01,0.01,0.8*(survivalsw/60)]);
pushCube( 10+dnew,-10+dnew, 10+dnew, 10+dnew,.05,.1,[0.01,0.01,0.01,0.8*(survivalsw/60)]);
pushCube(-10+dnew,-10+dnew, 10+dnew,-10+dnew,.05,.1,[0.01,0.01,0.01,0.8*(survivalsw/60)]);
pushCube(-10+dnew, 10+dnew, 10+dnew, 10+dnew,.05,.1,[0.01,0.01,0.01,0.8*(survivalsw/60)]);
for(var i=0;i<lines.length;++i)
pushCube(lines[i].x1+dnew,lines[i].y1+dnew,lines[i].x2+dnew,lines[i].y2+dnew,0.05,.1,[lines[i].c,0,0,0.8*(survivalsw/60)]);
for(var i=0;i<spheres.length;++i)
spheres[i].draw(spheres[i].x+dnew,spheres[i].y+dnew,survivalsw/60);
pushCube(pp.x,pp.y-0.1,pp.x,pp.y+0.1,.1,.2,[0,1,0,1]);
health*=1.007864155;if(health>1)health=1;
if(++survivalsw===60)
{
survivalsw=-1;linesold.length=0;
spheresold.length=0;pp.x=pp.y=-9.9;
}
}
batchGL();
hdiv.style.width=health*100+"%";
hdiv.style.backgroundColor="rgba("+Math.floor(255*(1-health))+","+Math.floor(255*health)+",0,0.6)";
requestAnimationFrame(mainloop);
}
function batchGL()
{
Mprojection=buildProjectionMatrix3D(800,450,60,0.1,100);
var mpp=WGL.getUniformLocation(shp,"mprojection");
WGL.uniformMatrix4fv(mpp,false,Mprojection);
var mvpp=WGL.getUniformLocation(shp,"mmodelview");
WGL.uniformMatrix4fv(mvpp,false,Mmodelview);
WGL.bindBuffer(WGL.ARRAY_BUFFER,vbo);
WGL.bufferData(WGL.ARRAY_BUFFER,vb,WGL.STATIC_DRAW);
WGL.drawElements(WGL.TRIANGLES,6*primc,WGL.UNSIGNED_SHORT,0);
primc=0;
}
function p1s()
{
if(state!==-1||deathcounter<5)return;
document.getElementById("winDiv").style.display="none";
document.getElementById("loseDiv").style.display="none";
document.getElementById("HUDDiv").style.display="block";
document.getElementById("resetbtn").style.display="none";
document.getElementById("p1sbtn").style.display="none";
document.getElementById("selDiv").style.display="none";
document.getElementById("easybtn").style.display="none";
document.getElementById("normalbtn").style.display="none";
document.getElementById("hardbtn").style.display="none";
document.getElementById("extremebtn").style.display="none";
document.getElementById("easy2btn").style.display="none";
document.getElementById("survivalbtn").style.display="none";
document.getElementById("healthDiv").style.display="block";
document.getElementById("brutesw").style.display="none";
document.getElementById("HUDDiv").innerHTML+=" +1s'er!";
health=1;state=0;deathcounter=0;
}
|