diff --git a/build.zip b/build.zip deleted file mode 100644 index 2a7a7b5d89faed7f6d97cf90b13c4f8fba7d6f13..0000000000000000000000000000000000000000 Binary files a/build.zip and /dev/null differ diff --git a/build/aimerthing.png b/build/aimerthing.png deleted file mode 100644 index 008e6b6e80db33849d27736bfc8fd4b031af8045..0000000000000000000000000000000000000000 Binary files a/build/aimerthing.png and /dev/null differ diff --git a/build/arw.png b/build/arw.png deleted file mode 100644 index f509667c3b90a211bad7a0c9ad450b281f67e4fe..0000000000000000000000000000000000000000 Binary files a/build/arw.png and /dev/null differ diff --git a/build/cursor.png b/build/cursor.png deleted file mode 100644 index ca76e84e80889ed8e2719e377c1aaeeb957afde9..0000000000000000000000000000000000000000 Binary files a/build/cursor.png and /dev/null differ diff --git a/build/gun.png b/build/gun.png deleted file mode 100644 index 0f28c2665e4de59a860284bd4a7312eb7e791d67..0000000000000000000000000000000000000000 Binary files a/build/gun.png and /dev/null differ diff --git a/build/hamster.png b/build/hamster.png deleted file mode 100644 index 1346ce776d46fed336d29c6b9af605e7030dc095..0000000000000000000000000000000000000000 Binary files a/build/hamster.png and /dev/null differ diff --git a/build/index.html b/build/index.html deleted file mode 100644 index b22f25d05b2f6dde9c0901e55d80558ec207ad87..0000000000000000000000000000000000000000 --- a/build/index.html +++ /dev/null @@ -1,66 +0,0 @@ -<canvas id="gameCanvas" width="600" height="400">no canvas support, try a newer browser</canvas> -<style>#gameCanvas { - display: block; - margin: auto; - width: 1200px; - height: 800px; - image-rendering: -moz-crisp-edges; - image-rendering: -webkit-crisp-edges; - image-rendering: pixelated; - cursor: none; - } - /* if the canvas can't fit the screen, shrink it, maintaining the aspect ratio */ - - aside { - float:left; - }</style> - -<script>var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(a){return a.raw=a};$jscomp.createTemplateTagFirstArgWithRaw=function(a,b){a.raw=b;return a};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)}; - var fntA=[[,,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1]],fntB=[[,1,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,1,1,1]],fntC=[[,,1,1,1,1],[,1,1,,,1,1],[,1,1],[,1,1],[,1,1],[,1,1,,,1,1],[,,1,1,1,1]],fntD=[[,1,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,1,1,1]],fntE=[[,,1,1,1,1,1],[,1,1,1,1,1,1],[,1,1],[,1,1,1,1,1],[,1,1],[,1,1,1,1,1,1],[,,1,1,1,1,1]],fntF=[[,,1,1,1,1,1],[,1,1,1,1,1, - 1],[,1,1],[,1,1,1,1,1],[,1,1],[,1,1],[,1,1]],fntG=[[,,1,1,1,1,1],[,1,1,1,1,1,1],,[,1,1],[,1,1,,1,1,1],[,1,1,,,1,1],[,1,1,1,1,1,1],[,,1,1,1,1]],fntH=[[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,1,1,1,1],[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,,1,1]],fntI=[[,1,1,1,1,1,1],[,,,1,1],[,,,1,1],[,,,1,1],[,,,1,1],[,,,1,1],[,1,1,1,1,1,1]],fntJ=[[,,1,1,1,1,1],[,,,,,1,1],[,,,,,1,1],[,,,,,1,1],[,,,,,1,1],[,1,1,,,1,1],[,,1,1,1,1]],fntK=[[,1,1,,,1,1],[,1,1,,,1,1],[,1,1,,1,1],[,1,1,1,1],[,1,1,,1,1],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1,1,1],[,1,1,1,,1,1],[,1,1,,,1,1],[,,1,1,1,1]],fntSlash=[[],[,,,,,,1],[,,,,,1],[,,,,1],[,,,1],[,,1],[,1]],fntColon=[[,1,1],[,1,1],[],[],[],[,1,1],[,1,1]],fntDot=[[],[],[],[],[],[,1,1],[,1,1]],fntNeg=[[],[],[],[,1,1,1,1,1,1],[],[],[]],fntINDEX={A:fntA,B:fntB,C:fntC,D:fntD,E:fntE,F:fntF,G:fntG,H:fntH,I:fntI, - J:fntJ,K:fntK,L:fntL,M:fntM,N:fntN,O:fntO,P:fntP,Q:fntQ,R:fntR,S:fntS,T:fntT,U:fntU,V:fntV,W:fntW,X:fntX,Y:fntY,Z:fntZ,1:fnt1,2:fnt2,3:fnt3,4:fnt4,5:fnt5,6:fnt6,7:fnt7,8:fnt8,9:fnt9,0:fnt0,"/":fntSlash,":":fntColon,".":fntDot,"-":fntNeg};var log=function(a,b){console.log("["+a+"] "+b)},fontStack='"Comic Sans MS"',id=0,pi=Math.PI;gPar=function(a){return(new URLSearchParams(window.location.search)).get(a)};var customLv=gPar("lv"),Canvas=function(a){this.c=document.getElementById(a);this.ctx=this.c.getContext("2d");this.w=this.c.width;this.h=this.c.height;this.tW=this.c.offsetWidth;this.tH=this.c.offsetHeight;this.scale=this.tW/this.w;this.camera={x:0,y:0};this.mousePos={x:0,y:0};this.realMousePos={x:0,y:0}}; - Canvas.prototype.fill=function(a){this.ctx.fillStyle=a;this.ctx.fillRect(0,0,this.w,this.h)};Canvas.prototype.getMousePos=function(a){var b=this.c.getBoundingClientRect(),e=this.c.width/b.width,d=this.c.height/b.height;this.mousePos.x=(a.clientX-b.left)*e+this.camera.x;this.mousePos.y=(a.clientY-b.top)*d+this.camera.y;return{x:(a.clientX-b.left)*e,y:(a.clientY-b.top)*d}};Canvas.prototype.translate=function(a,b){this.ctx.translate(a,b)};Canvas.prototype.rotate=function(a){this.ctx.rotate(a)}; - Canvas.prototype.drawImg=function(a,b,e,d,f,h,g,k){h=void 0===h?0:h;g=void 0===g?b+d/2:g;k=void 0===k?e+f/2:k;this.ctx.save();this.ctx.translate(g-this.camera.x,k-this.camera.y);this.ctx.rotate(h*pi/180);this.ctx.drawImage(a,-d/2,-f/2,d,f);this.ctx.restore()};Canvas.prototype.sliceImage=function(a,b,e,d,f,h,g,k,n,m){m=void 0===m?0:m;this.ctx.save();this.ctx.translate(b+d/2-this.camera.x,e+f/2-this.camera.y);this.ctx.rotate(m*pi/180);this.ctx.drawImage(a,h,g,k,n,-d/2,-f/2,d,f);this.ctx.restore()}; - Canvas.prototype.drawImage=function(a,b,e,d,f,h){this.drawImg(a,b,e,d,f,void 0===h?0:h)};Canvas.prototype.drawRect=function(a,b,e,d,f){this.ctx.fillStyle=void 0===f?"white":f;this.ctx.fillRect(a-this.camera.x,b-this.camera.y,e,d)};Canvas.prototype.strokeRect=function(a,b,e,d,f){this.ctx.strokeStyle=f;this.ctx.strokeRect(a-this.camera.x,b-this.camera.y,e,d)}; - Canvas.prototype.drawFont=function(a,b,e,d,f){this.ctx.fillStyle=d;this.ctx.textAlign=void 0===f?"start":f;this.ctx.fillText(a,b-this.camera.x,e-this.camera.y)}; - Canvas.prototype.dT=function(a,b,e,d,f,h,g,k,n){g=void 0===g?"start":g;k=void 0===k?"top":k;n=void 0===n?{}:n;a=a.toUpperCase();var m=a.split("");a=(7*m.length-1)*f;var l=7*d;switch(g){case "center":case "middle":b-=a/2;break;case "end":case "right":b-=a}switch(k){case "middle":case "center":e-=l/2;break;case "bottom":e-=l}g=0;var p=7*f;k=!1;m=$jscomp.makeIterator(m);for(l=m.next();!l.done;l=m.next()){l=l.value;this.ctx.fillStyle=h;var r=0,t=p;k&&(t-=.5*f,k=!1);n.shortFullStop&&"."==l&&(k=!0);l=fI[l]; - if(void 0!=l)for(var v in l){p=0;for(var u=$jscomp.makeIterator(l[v]),q=u.next();!q.done;q=u.next())1==q.value&&this.ctx.fillRect(b+p*f+g*t-this.camera.x,e+r*d-this.camera.y,f,d),p++;r++}g++;p=7*f}return{w:a}};Canvas.prototype.setFont=function(a,b){this.ctx.font=(void 0===b?"10":b)+"px "+a};Canvas.prototype.drawLine=function(a,b,e,d,f){this.ctx.strokeStyle=f;this.ctx.beginPath();this.ctx.moveTo(a-this.camera.x,b-this.camera.y);this.ctx.lineTo(e,d);this.ctx.stroke()}; - Canvas.prototype.mvCamera=function(a,b){this.camera.x+=a;this.camera.y+=b};Canvas.prototype.setCamera=function(a,b,e){this.camera.x=a;this.camera.y=b};var Entity=function(a,b,e,d){this.name=a;this.x=b;this.y=e;this.sprite=d};Entity.prototype.step=function(){console.log(this.name+" is stepping");console.log(this.name+" is at "+this.x+", "+this.y)};Entity.prototype.draw=function(){};Entity.prototype.intersects=function(a){return this.x<a.x+a.w&&this.x+this.w>a.x&&this.y<a.y+a.h&&this.y+this.h>a.y}; - var Room=function(a){this.id=id;id+=1;this.name=a;this.objects=[];this.hitboxes=[];this.background=[];this.w=c.w;this.h=c.h};Room.prototype.spawn=function(a){this.objects.push(a)};Room.prototype.step=function(){for(var a=$jscomp.makeIterator(this.objects),b=a.next();!b.done;b=a.next())b.value.step()};Room.prototype.draw=function(){for(var a=$jscomp.makeIterator(this.objects),b=a.next();!b.done;b=a.next())b.value.draw()};Room.prototype.drawGUI=function(){};Room.prototype.keyDown=function(a){}; - Room.prototype.keyHeld=function(a){};Room.prototype.click=function(a,b){};Room.prototype.mHeld=function(a,b){};Room.prototype.start=function(){};var fI=fntINDEX,c=new Canvas("gameCanvas");c.ctx||alert("Your browser does not support the canvas element");gameCtx=c.ctx;c.fill("#1c1c1c");c.setFont(fontStack);var gameStart=gameCtx.imageSmoothingEnabled=!1;c.dT("Death By Hamster",c.w/2,c.h/2-40,2,2,"white","middle"); - var images={mouse:{ingame:"./aimerthing.png",cursor:"./cursor.png"},level:{tileset:"./t.png"},player:{car:"./hamster.png",gun:"./gun.png"},ui:{a:"./arw.png"}},loader=new Room("loader"),loadingText="Loading...",loadingError=0;loader.drawGUI=function(){c.dT(loadingText,c.w/2,c.h/2,2,2,"white","middle");loadingError&&c.dT(loadingErrorText,c.w/2,c.h/2+20,1,1,"red","middle")};var rooms=[],loadedImages=0,totalImages=0,key$11;for(key$11 in images)for(var subkey$12 in images[key$11])totalImages++; - loadingText="Loading...";loadingText="Loading images ("+loadedImages+" / "+totalImages+")"; - for(var key in images)for(var subkey in images[key]){var IMG=new Image;IMG.addEventListener("load",function(){loadedImages++;loadingText="Loading images ("+loadedImages+" / "+totalImages+")";loadedImages==totalImages&&(loader.step=function(){cRoom=rooms[1]},loadingText="Loaded! Please wait...")});IMG.addEventListener("error",function(a){loadingError=1;loadingErrorText="Error loading image "+a.target.src});IMG.src=images[key][subkey];images[key][subkey]=IMG;loadingText="Loading images ("+loadedImages+ - " / "+totalImages+")"}var levels=[{data:"[[1,1,2],[1,1,3],[5,1,4],[1,1,1],[2,0,3],[2,0,2],[2,0,1],[4,0,0],[5,1,0],[5,2,0],[5,3,0],[5,4,0],[5,6,0],[5,5,0],[5,7,0],[6,8,0],[0,9,0],[0,10,0],[2,8,1],[2,8,2],[2,8,3],[8,8,4],[5,7,4],[5,5,4],[5,6,4],[5,4,4],[5,2,4],[5,3,4],[7,0,4],[1,2,3],[9,2,2],[1,2,1],[1,3,1],[1,3,2],[1,3,3],[1,4,3],[1,4,2],[1,4,1],[1,5,1],[1,5,2],[1,5,3],[1,6,3],[10,6,2],[1,6,1],[1,7,1],[1,7,2],[1,7,3]]"},{name:"First Floor"}]; - hamsterRef={file:images.player.car,nl:{x:1,y:1,w:32,h:16},b:{x:35,y:1,w:32,h:16},br:{x:1,y:20,w:32,h:16},r:{x:35,y:20,w:32,h:16}}; - for(var levelRef={file:images.level.tileset,"default":{x:0,y:0,w:32,h:32,type:"blank"},tiles:[{},{x:32,type:"floor"},{x:64,type:"wall"},{x:96,type:"wall"},{x:128,type:"wall"},{x:160,type:"wall"},{x:192,type:"wall"},{x:224,type:"wall"},{x:256,type:"wall"},{x:32,type:"floor"},{x:32,type:"floor"}]},$jscomp$iter$4=$jscomp.makeIterator(levelRef.tiles),$jscomp$key$tile=$jscomp$iter$4.next();!$jscomp$key$tile.done;$jscomp$key$tile=$jscomp$iter$4.next()){var tile=$jscomp$key$tile.value,key$13;for(key$13 in levelRef["default"])tile[key$13]|| - (tile[key$13]=levelRef["default"][key$13])}console.debug(images);var targFPS=60,frame=0,menu=new Room("menu");menu.s=0;menu.o=[{t:"Play",a:function(a){setRoom(4)}},{t:"Editor",a:function(a){setRoom(3)}}]; - menu.drawGUI=function(){c.dT("Death by Hamster",c.w/2,c.h/2-25,4,4,"white","middle","middle");c.dT("W/Up or S/Down to select",c.w/2,c.h/2,1,1,"gray","middle","middle");c.dT("Space or ENTER to activate",c.w/2,c.h/2+8,1,1,"gray","middle","middle");for(var a in menu.o){var b=c.dT(""+menu.o[a].t,c.w/2,c.h/2+50+20*a,2,2,"#fff","middle","top");if(menu.s==a){var e=images.ui.a,d=c.w/2+b.w/2+e.width-4;c.drawImg(e,c.w/2-b.w/2-e.width-4,c.h/2+50+20*a,2*e.width,2*e.height);c.drawImg(e,d,c.h/2+50+20*a,2*e.width, - 2*e.height,180)}}};var nextRoom=function(){roomI++;roomI>=rooms.length&&(roomI=0);cRoom=rooms[roomI];cRoom.start()},prevRoom=function(){roomI--;0>roomI&&(roomI=rooms.length-1);cRoom=rooms[roomI];cRoom.start()},setRoom=function(a){cRoom=rooms[a];cRoom.start()};menu.keyDown=function(a){if("ArrowUp"==a||"KeyW"==a)--menu.s,0>menu.s&&(menu.s=menu.o.length-1);if("ArrowDown"==a||"KeyS"==a)menu.s+=1,menu.s>menu.o.length-1&&(menu.s=0);"Space"!=a&&"Enter"!=a||menu.o[menu.s].a()};var gameRoom=new Room("Game"); - gameRoom.level=levels[0];var player=new Entity("Player",0,0);player.speed=0;player.maxSpeed=5;player.direction=0;player.accel=1;player.sprite=images.player.car;console.debug(player.sprite);player.crop=hamsterRef.nl;player.x=0;player.y=0;player.w=2*player.crop.w;player.h=2*player.crop.h; - player.step=function(){player.x+=player.speed*Math.cos(player.direction*pi/180);player.y+=player.speed*Math.sin(player.direction*pi/180);player.speed*=.009;for(var a=$jscomp.makeIterator(gameRoom.level),b=a.next();!b.done;b=a.next())b=b.value,player.x/64>b.x&&player.x/64<b.x+b.w&&player.y/64>b.y&&player.y/64<b.y+b.h&&(player.speed=0);c.setCamera(player.x-c.w/2,player.y-c.h/2)};console.log(player); - player.draw=function(){c.sliceImage(player.sprite,player.x,player.y,player.w,player.h,player.crop.x,player.crop.y,player.crop.w,player.crop.h,player.direction);var a=images.player.gun,b=player.x+player.w/2-13*Math.cos(player.direction*pi/180)-0*Math.sin(player.direction*pi/180),e=player.y+player.h/2-13*Math.sin(player.direction*pi/180)+0*Math.cos(player.direction*pi/180);player.gx=b;player.gy=e;player.aim=180*Math.atan2(c.mousePos.y-e,c.mousePos.x-b)/pi;c.drawImg(a,b,e,2*a.width,2*a.height,player.aim, - b,e)};player.shoot=function(){var a=new Entity("Bullet",player.gx,player.gy);a.speed=20;a.direction=player.aim;a.step=function(){for(var b=0;b<cRoom.objects.length;b++){var e=cRoom.objects[b];if(e!=a&&e.intersects(a)){e!=player&&(cRoom.objects.splice(b,1),cRoom.objects.splice(cRoom.objects.indexOf(a),1));return}}a.x+=a.speed*Math.cos(a.direction*pi/180);a.y+=a.speed*Math.sin(a.direction*pi/180)};a.draw=function(){c.drawRect(a.x,a.y,2,2,"white")};cRoom.spawn(a)};gameRoom.spawn(player); - gameRoom.keyDown=function(a){console.log(a);if("ArrowUp"==a||"KeyW"==a)player.speed+=2*player.accel,player.speed>player.maxSpeed&&(player.speed=player.maxSpeed);if("ArrowDown"==a||"KeyS"==a)player.speed-=1.5*player.accel,player.speed<-player.maxSpeed&&(player.speed=-player.maxSpeed);if("ArrowLeft"==a||"KeyA"==a)player.direction-=2.5,0>player.direction&&(player.direction=360);if("ArrowRight"==a||"KeyD"==a)player.direction+=2.5,360<player.direction&&(player.direction=0);"Space"==a&&player.shoot()}; - gameRoom.keyHeld=function(a){if("ArrowUp"==a||"KeyW"==a)player.speed+=1.9*player.accel,player.speed>player.maxSpeed&&(player.speed=player.maxSpeed);if("ArrowDown"==a||"KeyS"==a)player.speed-=1.53*player.accel,player.speed<-player.maxSpeed&&(player.speed=-player.maxSpeed);if("ArrowLeft"==a||"KeyA"==a)player.direction-=2.5,0>player.direction&&(player.direction=360);if("ArrowRight"==a||"KeyD"==a)player.direction+=2.5,360<player.direction&&(player.direction=0)};gameRoom.click=function(a){player.shoot()}; - gameRoom.start=function(){customLv&&(gameRoom.level=customLv);gameRoom.level=JSON.parse(gameRoom.level);for(var a={},b=$jscomp.makeIterator(gameRoom.level),e=b.next();!e.done;a={$jscomp$loop$prop$pooman$23:a.$jscomp$loop$prop$pooman$23,$jscomp$loop$prop$checkwall$22:a.$jscomp$loop$prop$checkwall$22},e=b.next())e=e.value,9===e[0]&&(player.x=64*e[1]+32,player.y=64*e[2]+32),10===e[0]&&(a.$jscomp$loop$prop$checkwall$22=function(d,f){for(var h=$jscomp.makeIterator(gameRoom.level),g=h.next();!g.done;g= - h.next())if(g=g.value,"wall"==levelRef.tiles[g[0]].type&&g[1]==d&&g[2]==f)return!0;return!1},a.$jscomp$loop$prop$pooman$23=new Entity("Human",64*e[1],64*e[2],images.mouse.cursor),a.$jscomp$loop$prop$pooman$23.step=function(d){return function(f){if(0>=d.$jscomp$loop$prop$pooman$23.timer){f=Math.floor(4*Math.random());d.$jscomp$loop$prop$pooman$23.direction=90*f;var h=Math.floor(d.$jscomp$loop$prop$pooman$23.x/64),g=Math.floor(d.$jscomp$loop$prop$pooman$23.y/64);0!==f||d.$jscomp$loop$prop$checkwall$22(h, - g-1)||(d.$jscomp$loop$prop$pooman$23.y-=64);1!==f||d.$jscomp$loop$prop$checkwall$22(h+1,g)||(d.$jscomp$loop$prop$pooman$23.x+=64);2!==f||d.$jscomp$loop$prop$checkwall$22(h,g+1)||(d.$jscomp$loop$prop$pooman$23.y+=64);3!==f||d.$jscomp$loop$prop$checkwall$22(h-1,g)||(d.$jscomp$loop$prop$pooman$23.x-=64);d.$jscomp$loop$prop$pooman$23.timer=90}d.$jscomp$loop$prop$pooman$23.timer--}}(a),a.$jscomp$loop$prop$pooman$23.draw=function(d){return function(f){c.drawImage(images.mouse.cursor,d.$jscomp$loop$prop$pooman$23.x, - d.$jscomp$loop$prop$pooman$23.y,64,64,d.$jscomp$loop$prop$pooman$23.direction);c.dT(d.$jscomp$loop$prop$pooman$23.timer+" :: "+d.$jscomp$loop$prop$pooman$23.direction,d.$jscomp$loop$prop$pooman$23.x,d.$jscomp$loop$prop$pooman$23.y,1,1,"white","middle","middle")}}(a),a.$jscomp$loop$prop$pooman$23.timer=90,gameRoom.spawn(a.$jscomp$loop$prop$pooman$23))}; - gameRoom.draw=function(){for(var a=$jscomp.makeIterator(gameRoom.level),b=a.next();!b.done;b=a.next())b=b.value,c.sliceImage(levelRef.file,64*b[1],64*b[2],64,64,levelRef.tiles[b[0]].x,0,32,32);for(a=0;a<cRoom.objects.length;a++)cRoom.objects[a].draw()};var editor=new Room("Editor");editor.i=0;editor.t=levelRef;editor.l=[];editor.n="LV1";editor.saving=!1;editor.sa=0;editor.start=function(a){editor.dPos=[15,65]}; - editor.draw=function(a){a=$jscomp.makeIterator(editor.l);for(var b=a.next();!b.done;b=a.next())b=b.value,c.sliceImage(levelRef.file,32*b[1]+editor.dPos[0],32*b[2]+editor.dPos[1],32,32,32*b[0],0,32,32),c.drawRect(editor.dPos[0],editor.dPos[1],1,1,"red")};editor.step=function(a){0>editor.i&&(editor.i=levelRef.tiles.length-1);editor.i>levelRef.tiles.length-1&&(editor.i=0)}; - editor.generate=function(a){editor.saving=1;a=encodeURIComponent(JSON.stringify(editor.l));a!=editor.data&&(a="?lvl="+a,document.getElementById("leveltext").innerText=a);editor.data=a;editor.saving=0;editor.sa=1}; - editor.click=function(a,b){if(50>b)516<a&&50>b&&(editor.saving||editor.generate(),editor.saveclick=!0);else{a=Math.floor((a-editor.dPos[0])/32);b=Math.floor((b-editor.dPos[1])/32);for(var e in editor.l)if(editor.l[e][1]==a&&editor.l[e][2]==b){editor.l[e]=[editor.i,a,b];return}editor.l.push([editor.i,a,b]);editor.sa=0}}; - editor.keyHeld=function(a){switch(a){case "KeyW":case "ArrowUp":editor.dPos[1]+=4;break;case "KeyS":case "ArrowDown":editor.dPos[1]-=4;break;case "KeyA":case "ArrowLeft":editor.dPos[0]+=4;break;case "KeyD":case "ArrowRight":editor.dPos[0]-=4}}; - editor.drawGUI=function(a){c.drawRect(0,0,c.w,50,"gray");c.dT("DBH Editor::"+editor.n,15,25,2,2,"#fff","start","middle");a=c.dT("Save",c.w-15,25,2,2,"#fff","end","middle");c.mousePos.x>c.w-30-a.w&&50>c.mousePos.y&&c.dT("Save",c.w-15,25,2,2,"#e5e5e5","end","middle");editor.sa&&c.dT("Save",c.w-15,25,2,2,"#1fdc2f","end","middle");editor.saving&&c.dT("Save",c.w-15,25,2,2,"#1fccdc","end","middle");c.sliceImage(editor.t.file,c.mousePos.x+16,c.mousePos.y+16,32,32,32*editor.i,0,32,32)};var lvlS=new Room("Level Select"); - lvlS.s=0;lvlS.o=levels;lvlS.drawGUI=function(){c.dT("Death by Hamster",c.w/2,25,2,2,"white","middle","top");c.dT("Level Select",c.w/2,44,1,1,"gray","middle","middle");for(var a in lvlS.o){var b=parseInt(a)+1;c.dT(""+b,20+32*b,70,2,2,"#fff","middle","middle");a==lvlS.s&&c.strokeRect(6+32*b,54,32,32,"#fff")}}; - lvlS.keyDown=function(a){if("ArrowUp"==a||"ArrowRight"==a||"KeyW"==a||"KeyD"==a)--lvlS.s,0>lvlS.s&&(lvlS.s=lvlS.o.length-1);if("ArrowDown"==a||"ArrowLeft"==a||"KeyW"==a||"KeyA"==a)lvlS.s+=1,lvlS.s>lvlS.o.length-1&&(lvlS.s=0);if("Space"==a||"Enter"==a)gameRoom.level=lvlS.o[lvlS.s].data,setRoom(2)};rooms.push(loader);rooms.push(menu);rooms.push(gameRoom);rooms.push(editor);rooms.push(lvlS);var roomI=gPar("goto")?gPar("goto"):0,cRoom=rooms[roomI],keysPressed={},keysLastPressed={}; - document.addEventListener("keydown",function(a){keysPressed[a.code]=!0});document.addEventListener("keyup",function(a){keysPressed[a.code]=!1;keysLastPressed[a.code]=!1});var lastTime=0,mse={x:0,y:0},lastClick={x:0,y:0},startclicked=!1,endclicked=!1;c.c.addEventListener("mousemove",function(a){mse=c.getMousePos(a)});c.c.addEventListener("mousedown",function(a){lastClick=c.getMousePos(a);mse=c.getMousePos(a);startclicked=!0}); - c.c.addEventListener("mouseup",function(a){lastClick=c.getMousePos(a);mse=c.getMousePos(a);endclicked=!0});window.onwheel=function(a){0<a.deltaY&&(editor.i+=1);0>a.deltaY&&--editor.i};cRoom.start(); - var gameLoop=setInterval(function(){c.tW=c.c.offsetWidth;c.tH=c.c.offsetHeight;c.scale=c.tW/c.w;frame++;c.fill("#151f1f");for(var a in keysPressed)keysPressed[a]&&(keysLastPressed[a]?keysLastPressed[a]&&cRoom.keyHeld(a):(cRoom.keyDown(a),keysLastPressed[a]=!0));startclicked&&(cRoom.click(lastClick.x,lastClick.y),startclicked=!1);cRoom.step();cRoom.draw();cRoom.drawGUI();c.dT("FPS:"+Math.round(1E3/(Date.now()-lastTime)),0+c.camera.x,0+c.camera.y,1,1,"#fafafa","left","top");switch(cRoom.name){case "menu":case "Editor":c.ctx.drawImage(images.mouse.cursor, - Math.round(mse.x),Math.round(mse.y),2*images.mouse.cursor.width,2*images.mouse.cursor.height);break;case "Game":c.ctx.drawImage(images.mouse.ingame,Math.round(mse.x)-16,Math.round(mse.y)-16,32,32)}lastTime=Date.now()},1E3/targFPS);</script> \ No newline at end of file diff --git a/build/t.png b/build/t.png deleted file mode 100644 index 0407f3076ee71a85e6fbb154bb333a3b4c19aa58..0000000000000000000000000000000000000000 Binary files a/build/t.png and /dev/null differ diff --git a/game.js b/game.js index beee64c9ffcc6c7421716793bd04a642aac597af..f4986607ffa4fba78825e7e4f4188723696f6706 100644 --- a/game.js +++ b/game.js @@ -413,7 +413,8 @@ var levels = [ "data": "[[1,1,2],[1,1,3],[5,1,4],[1,1,1],[2,0,3],[2,0,2],[2,0,1],[4,0,0],[5,1,0],[5,2,0],[5,3,0],[5,4,0],[5,6,0],[5,5,0],[5,7,0],[6,8,0],[0,9,0],[0,10,0],[2,8,1],[2,8,2],[2,8,3],[8,8,4],[5,7,4],[5,5,4],[5,6,4],[5,4,4],[5,2,4],[5,3,4],[7,0,4],[1,2,3],[9,2,2],[1,2,1],[1,3,1],[1,3,2],[1,3,3],[1,4,3],[1,4,2],[1,4,1],[1,5,1],[1,5,2],[1,5,3],[1,6,3],[10,6,2],[1,6,1],[1,7,1],[1,7,2],[1,7,3]]" }, { - "name": "First Floor" + "name": "First Floor", + "data": "[[1,1,1],[4,0,0],[5,1,0],[5,2,0],[5,3,0],[6,4,0],[7,4,1],[5,5,1],[5,6,1],[5,7,1],[5,8,1],[5,9,1],[5,10,1],[5,11,1],[5,12,1],[5,13,1],[5,14,1],[5,15,1],[5,16,1],[6,17,1],[2,17,2],[2,17,3],[2,17,4],[2,17,5],[9,2,2],[2,0,1],[2,0,2],[2,0,3],[2,0,4],[2,0,5],[2,0,6],[7,0,7],[5,1,7],[5,2,7],[5,3,7],[5,4,7],[5,5,7],[5,6,7],[5,7,7],[5,8,7],[5,10,7],[5,9,7],[5,12,7],[5,11,7],[5,13,7],[5,15,7],[5,14,7],[5,16,7],[8,17,7],[2,17,6],[1,2,1],[1,3,1],[1,3,2],[1,1,2],[1,1,3],[1,2,3],[1,3,3],[1,6,2],[1,8,4],[1,10,6],[1,11,4],[1,13,2],[1,15,4],[10,13,5],[10,9,5],[10,11,5],[1,12,3],[1,10,3],[1,14,5],[1,12,5],[1,8,6],[1,7,6],[1,4,6],[1,1,4],[1,2,4],[1,4,4],[1,4,3],[1,4,2],[1,5,2],[1,5,3],[1,5,4],[1,10,5],[1,10,4],[1,9,4],[10,9,3],[1,7,3],[1,8,3],[1,7,2],[1,8,2],[1,9,2],[1,10,2],[1,11,2],[10,11,3],[1,12,2],[1,7,5],[1,8,5],[1,6,3],[1,6,4],[1,7,4],[1,6,5],[1,6,6],[1,5,6],[1,4,5],[1,5,5],[1,3,4],[1,3,5],[1,3,6],[1,2,6],[1,2,5],[1,1,5],[1,1,6],[1,9,6],[1,11,6],[1,12,6],[1,13,6],[1,14,6],[1,12,4],[1,13,4],[10,13,3],[1,14,3],[1,14,4],[1,14,2],[1,15,2],[1,15,3],[1,15,5],[1,15,6],[1,16,6],[1,16,5],[1,16,4],[1,16,3],[1,16,2]]" }, ] @@ -503,9 +504,10 @@ var levelRef = { var humanRef = { "file": images.level.human, - "bladie": { - + "normie": { + "x": 0, "y": 0, "w": 32, "h": 32 } +} for (let tile of levelRef.tiles) { @@ -599,9 +601,9 @@ var gameRoom = new Room("Game"); gameRoom.level = levels[0]; var player = new Entity("Player", 0,0); player.speed = 0; -player.maxSpeed = 5; +player.maxSpeed = 20; player.direction = 0; -player.accel = 1; +player.accel = 2.5; player.sprite = images.player.car; console.debug(player.sprite); player.crop = hamsterRef.nl; @@ -612,9 +614,13 @@ player.h = player.crop.h*2; player.oldDir = 0; player.step = _=> { + // move in this.direction, which is an angle in degrees + player.x += player.speed * Math.cos(player.direction * pi / 180); + player.y += player.speed * Math.sin(player.direction * pi / 180); + player.speed *= 0.009; // check that the player won't go into a wall on the next step, and if so, stop. player.checkpoints = []; - for (let i = 0; i < 2; i++) { + for (let i = 0; i < 6; i++) { let carCx = player.x + player.w/2; let carCy = player.y + player.h/2; @@ -625,14 +631,28 @@ player.step = _=> { pointOx = -32; } else if (i==1) { pointOx = 32; + } else if (i==2){ + pointOx = -30; + pointOy = -15; + } else if (i==3){ + pointOx = -30; + pointOy = 15; + } else if (i==4){ + pointOx = 30; + pointOy = -15; + } else if (i==5){ + pointOx = 30; + pointOy = 15; } - + + // get gunx and guny by moving backwards (gunOx and gunOy) from the center of the car in this.direction let pointX = carCx - pointOx * Math.cos(player.direction * pi / 180) - pointOy * Math.sin(player.direction * pi / 180); let pointY = carCy - pointOx * Math.sin(player.direction * pi / 180) + pointOy * Math.cos(player.direction * pi / 180); player.checkpoints.push({x: pointX, y: pointY}); } + for (let checkpoint of player.checkpoints) { let x = checkpoint.x / 64; let y = checkpoint.y / 64; @@ -640,26 +660,21 @@ player.step = _=> { checkpoint.stuck = true; } } + if (player.checkpoints[0].stuck || player.checkpoints[1].stuck) { // move down sideways if stuck - let change = player.direction - player.oldDir; - player.direction -= change; - - let sChange = player.speed - player.oldSpeed; - player.speed -= sChange+0.01; + player.direction = player.oldDir; + player.x = player.xy[0]; + player.y = player.xy[1]; + player.speed -= 0.1; } - // move in this.direction, which is an angle in degrees - player.x += player.speed * Math.cos(player.direction * pi / 180); - player.y += player.speed * Math.sin(player.direction * pi / 180); - - player.speed *= 0.009; // keep the camera centered on the player c.setCamera(player.x - c.w/2, player.y - c.h/2); player.oldDir = player.direction; - player.oldSpeed = player.speed; + player.xy = [player.x, player.y] } @@ -696,6 +711,8 @@ player.draw = _=> { } + c.dT(`${Math.round(player.speed*100000)/100000}` ,player.x, player.y, 1,1, "white") + } player.shoot = () => { @@ -737,13 +754,13 @@ gameRoom.keyDown = (key) => { console.log(key); if (key == "ArrowUp" || key == "KeyW") { - player.speed += player.accel*2; + player.speed += player.accel; if (player.speed > player.maxSpeed) { player.speed = player.maxSpeed; } } if (key == "ArrowDown" || key == "KeyS") { - player.speed -= player.accel*1.5; + player.speed -= player.accel*.8 if (player.speed < -player.maxSpeed) { player.speed = -player.maxSpeed; } @@ -817,42 +834,48 @@ gameRoom.start = () =>{ } if(tile[0]===10){ - let pooman = new Entity("Human", (tile[1]*64),(tile[2]*64), images.mouse.cursor) - pooman.w = 64 - pooman.h = 64 + let pooman = new Entity("Human", (tile[1]*64),(tile[2]*64), images.level.human) + pooman.w = 26*2 + pooman.h = 16*2 + pooman.bh = Math.floor(Math.random()*3); + pooman.bb = Math.floor(Math.random()*3) + pooman.getT=_=>{ + pooman.tX = Math.floor((pooman.x + pooman.w) / 64) + pooman.tY = Math.floor((pooman.y + pooman.h) / 64) + } pooman.step = _=>{ + let xy = [pooman.x, pooman.y] if (pooman.timer<=0){ let director = Math.floor(Math.random()*4) pooman.direction = director*90; - let tX = Math.floor(pooman.x / 64) - let tY = Math.floor(pooman.y / 64) if (director === 0){ - if (!gameRoom.checkwall(tX,tY-1)){ - pooman.y -= 64; - } + pooman.y -= pooman.h; } if (director === 1){ - if (!gameRoom.checkwall(tX+1,tY)){ - pooman.x += 64; - } + pooman.x += pooman.w; } if (director === 2){ - if (!gameRoom.checkwall(tX,tY+1)){ - pooman.y += 64; - } + pooman.y += pooman.w; } if (director === 3){ - if (!gameRoom.checkwall(tX-1,tY)){ - pooman.x -= 64; - } + pooman.x -= pooman.h; + } + pooman.getT(); + if (gameRoom.checkwall(pooman.tX, pooman.tY)){ + pooman.x = xy[0] + pooman.y = xy[1] + pooman.step() + return } + pooman.timer = 90; } pooman.timer--; } pooman.draw = _=>{ - c.drawImage(images.mouse.cursor, pooman.x, pooman.y, 64, 64, pooman.direction); - // c.dT(`${pooman.timer} :: ${pooman.direction}`, pooman.x, pooman.y, 1, 1, "white", "middle", "middle"); + c.sliceImage(pooman.sprite, pooman.x, pooman.y, pooman.w, pooman.h, pooman.bb*pooman.w/2, 0, pooman.w/2, pooman.h/2, pooman.direction); + c.sliceImage(pooman.sprite, pooman.x, pooman.y, pooman.w, pooman.h, pooman.bh*pooman.w/2, pooman.h/2, pooman.w/2, pooman.h/2, pooman.direction); + c.dT(`${pooman.timer} :: ${pooman.direction}`, pooman.x, pooman.y, 1, 1, "white", "middle", "middle"); } pooman.timer = 90; gameRoom.spawn(pooman); @@ -875,7 +898,6 @@ let editor = new Room("Editor"); editor.i = 0; editor.t = levelRef; editor.l = [] -editor.n = "LV1" editor.saving = false editor.sa = 0 diff --git a/human.aseprite b/human.aseprite index bbf2d18c519bd69806ac0458053acf1603e986b1..4b248e6d50e11cc31e02db5d5a91a78c38019268 100644 Binary files a/human.aseprite and b/human.aseprite differ diff --git a/human.png b/human.png index 10ef95d45000bfd431d73903090245bd39b61fcf..f7fc3157c5dcbe489b0101f65267fdd0539a51a8 100644 Binary files a/human.png and b/human.png differ diff --git a/logothing.aseprite b/logothing.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..b8892089a508cec9c822858859518343a1f719d5 Binary files /dev/null and b/logothing.aseprite differ diff --git a/logothing.png b/logothing.png new file mode 100644 index 0000000000000000000000000000000000000000..f74c9e894ae45a570bafddddcd64d5c91a8cba79 Binary files /dev/null and b/logothing.png differ