//Copyright Chris Xiong 2018 //License: Expat (MIT) 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=[15,4,30]; var ofs=[0.9,3.5,20]; var mzw=50,mzh=35,ppx,ppy,ex,ey; var maz=[]; 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 cube(x,y,z,l,r,g,b,a) { var L=x-l/2,R=x+l/2; var B=y-l/2,T=y+l/2; var N=z-l/2,F=z+l/2; pushQuad([ L,B,N,r,g,b,a, L,T,N,r,g,b,a, R,T,N,r,g,b,a, R,B,N,r,g,b,a ]); pushQuad([ L,B,F,r,g,b,a, L,T,F,r,g,b,a, R,T,F,r,g,b,a, R,B,F,r,g,b,a ]); pushQuad([ L,B,N,r,g,b,a, L,T,N,r,g,b,a, L,T,F,r,g,b,a, L,B,F,r,g,b,a ]); pushQuad([ R,B,N,r,g,b,a, R,T,N,r,g,b,a, R,T,F,r,g,b,a, R,B,F,r,g,b,a ]); pushQuad([ L,B,N,r,g,b,a, R,B,N,r,g,b,a, R,B,F,r,g,b,a, L,B,F,r,g,b,a ]); pushQuad([ L,T,N,r,g,b,a, R,T,N,r,g,b,a, R,T,F,r,g,b,a, L,T,F,r,g,b,a ]); } 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 randint(c) {return Math.floor(Math.random()*c);} function genmaze() { for(var i=0;i=0&&cy>=0&&cx=0&&maz[ppx-1][ppy])--ppx;} if(e.code=='KeyW'){if(ppy+1=0&&maz[ppx][ppy-1])--ppy;} }); genmaze(); requestAnimationFrame(mainloop); } function mainloop() { const ofx=-9,ofy=-11; 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(); Mmodelview=buildLookAtMatrix(pos,[15,10,0],[0,0,1]); for(var i=0;i