From 63ae6b7b826cc9728e2204cdea0fea92e99a627d Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Fri, 17 Apr 2020 14:18:27 -0400 Subject: [PATCH] move all files to their own folder --- LICENSE => docs/LICENSE | 0 index.html => docs/index.html | 48 +- pixelmix.ttf => docs/pixelmix.ttf | Bin {scripts => docs/scripts}/game.js | 2124 ++++++++++++++-------------- {scripts => docs/scripts}/index.js | 56 +- 5 files changed, 1114 insertions(+), 1114 deletions(-) rename LICENSE => docs/LICENSE (100%) rename index.html => docs/index.html (96%) rename pixelmix.ttf => docs/pixelmix.ttf (100%) rename {scripts => docs/scripts}/game.js (97%) rename {scripts => docs/scripts}/index.js (86%) diff --git a/LICENSE b/docs/LICENSE similarity index 100% rename from LICENSE rename to docs/LICENSE diff --git a/index.html b/docs/index.html similarity index 96% rename from index.html rename to docs/index.html index 09bb064..cd14837 100644 --- a/index.html +++ b/docs/index.html @@ -1,25 +1,25 @@ - - - - - title - - - - - - - + + + + + title + + + + + + + \ No newline at end of file diff --git a/pixelmix.ttf b/docs/pixelmix.ttf similarity index 100% rename from pixelmix.ttf rename to docs/pixelmix.ttf diff --git a/scripts/game.js b/docs/scripts/game.js similarity index 97% rename from scripts/game.js rename to docs/scripts/game.js index e9c1394..dcd3fee 100644 --- a/scripts/game.js +++ b/docs/scripts/game.js @@ -1,1063 +1,1063 @@ -function createCanvas(id) { - var tempCanvas = document.createElement("canvas"); - tempCanvas.id = id; - tempCanvas.width = canvases.cvs.width; - tempCanvas.height = canvases.cvs.height; - tempCanvas.style = "image-rendering:pixelated;image-rendering: crisp-edges;display:none";//display:none; - - document.body.appendChild(tempCanvas); - - canvases[`${id}cvs`] = document.getElementById(id); - canvases[`${id}ctx`] = canvases[`${id}cvs`].getContext("2d"); -} - -function startLoops() { - try {draw} catch (err){console.warn(bug+" no draw function found");return null;} - try {update} catch (err){console.warn(bug+" no update function found");return null;} - try {input} catch (err){seperateInputLoop=false;} - onAssetsLoaded(); - - requestAnimationFrame(drawLoop); - setInterval(updateLoop,1000/updateFPS); - - if(seperateInputLoop) { - setInterval(inputLoop,4); - } -} - -function mousePosition() { - if(drawMode===0) { - return {x:(mousePos.x)-camera.x,y:(mousePos.y)-camera.y}; - } else if(drawMode===1) { - var xoff = canvases.cvs.width/2; - var yoff = canvases.cvs.height/2; - return {x:((mousePos.x-xoff)/camera.zoom+xoff)-camera.x,y:((mousePos.y-yoff)/camera.zoom+yoff)-camera.y}; - } else { - var xoff = canvases.cvs.width/2; - var yoff = canvases.cvs.height/2; - var tempPos = {x:((mousePos.x-xoff)/camera.zoom+xoff)-camera.x,y:((mousePos.y-yoff)/camera.zoom+yoff)-camera.y}; - - var center = {x:-camera.x + cw/2, y:-camera.y + ch/2}; - var tempAngle = pointTo(center,tempPos) - camera.angle; - var tempDist = dist(center,tempPos); - - return {x:center.x + (Math.cos(tempAngle) * tempDist),y:center.y + (Math.sin(tempAngle) * tempDist)} - } -} - -function addStyle() { - var tempStyle = document.createElement("style"); - tempStyle.id="gamejsstyle"; - document.head.appendChild(tempStyle); - var tempMeta = document.createElement("meta"); - tempMeta.setAttribute("charset","utf-8"); - document.head.appendChild(tempMeta); -} - -function rand(min,max) { - return Math.floor(Math.random() * (max - min + 1)) + min; -} - -function radToDeg(rad) {return rad / Math.PI * 180;} -function degToRad(deg) {return deg * Math.PI / 180;} - -function velocity(angle) { - return {x:Math.sin(angle),y:Math.cos(angle)}; -} - -function pointTo(point,targetPoint) { - var adjacent = (targetPoint.x - point.x); - var opposite = (targetPoint.y - point.y); - var h = Math.atan2(opposite, adjacent); - return h; -} - -function loadImagesAndSounds() { - var curpath=""; - context = new AudioContext(); - sfxVolumeNode = context.createGain(); - sfxVolumeNode.connect(context.destination); - bmgVolumeNode = context.createGain(); - bmgVolumeNode.connect(context.destination); - deeper(images,"image"); - deeper(audio,"sound"); - function deeper(curpos,type) { - let addedPath=""; - for(let j=0;jcw-32&&mousePos.y<32) { - if(mousePress[0]&&ImTierdMakemenuwork) { - clickSound.play(); - paused=true; - optionsMenu=!optionsMenu; - } - optionsHover = 25; - } else { - optionsHover = 0; - } - if(mousePos.xcw-64&&mousePos.y<32) { - pauseHover = 25; - if(mousePress[0]) { - clickSound.play(); - paused=!paused; - } - } else { - pauseHover = 0; - } - -} -function addFont() { - var tempStyle = document.createElement("style"); - tempStyle.innerHTML = ` - @font-face { - font-family: 'PixelArial11'; - src: url("./pixelmix.ttf") format('truetype'); - font-weight: 900; - font-style: normal; - - } - html {font-family: 'PixelArial11' !important; font-size: 16px;} - `; - document.head.appendChild(tempStyle); - canvases.ctx.textBaseline = "hanging"; - canvases.ctx.textAlign = "left"; -} -var scaleDefault = 1; -function img(img,x,y,angle=0,sx=scaleDefault,sy=scaleDefault) { - var half = img.drawLimitSize; - if((x+half>drawLimitLeft&&x-halfdrawLimitTop&&y-halfmaxWidth) { //if the string is too big, divide up into smaller strings - var tempTxt = txtList[i].split(" "); //split into individual words - var tempStr=""; //string for measuring size - var addAmount=0; //track where in the txtList we are - txtList.splice(i,1); //remove the too long string - for(let j=0;j= rect2.x - rect2.w/2 && - rect1.x - rect1.w/2 <= rect2.x + rect2.w/2 && - rect1.y + rect1.h/2 >= rect2.y - rect2.h/2 && - rect1.y - rect1.h/2 <= rect2.y + rect2.h/2) { - return true; - } else { - return false; - } -} - -function rectpoint(rect,point) { - if(rect.x + rect.w/2 >= point.x && - rect.x - rect.w/2 <= point.x && - rect.y + rect.h/2 >= point.y && - rect.y - rect.h/2 <= point.y ) { - return true; - } else { - return false; - } -} - -function circlerect(circle,rect) { //credit: https://yal.cc/rectangle-circle-intersection-test/ - let rectHalfWidth = rect.w/2; - let rectHalfHeight = rect.h/2; - let deltaX = circle.x - Math.max(rect.x - rectHalfWidth, Math.min(circle.x, rect.x + rectHalfWidth)); - let deltaY = circle.y - Math.max(rect.y - rectHalfHeight, Math.min(circle.y, rect.y + rectHalfHeight)); - return (deltaX * deltaX + deltaY * deltaY) < (circle.r * circle.r); -} - -function circleOnSideRect(circle,rect) { - let rectHalfWidth = rect.w/2; - let rectHalfHeight = rect.h/2; - let left = rect.x - rectHalfWidth; - let right = rect.x + rectHalfWidth; - let top = rect.y - rectHalfHeight; - let bottom = rect.y + rectHalfHeight; - let cx = circle.x; - let cy = circle.y; - if(cy < top && cx > left && cx < right) { // top side - return 0; - } else if(cy > bottom && cx > left && cx < right) { // bottom side - return 2; - } else if (cx < left && cy > top && cy < bottom) { // left side - return 3; - } else if (cx > right && cy > top && cy < bottom) { // right side - return 1; - } else { - let returnValue=0; // 0 = top, 1 = right, 2 = bottom, 3 = left - let topleft = dist (circle,{x:left,y:top}); - let topright = dist (circle,{x:right,y:top}); - let bottomleft = dist (circle,{x:left,y:bottom}); - let bottomright = dist (circle,{x:right,y:bottom}); - switch(Math.min(topleft,topright,bottomleft,bottomright)) { // find what corner the cricle is closer to, then determine what side it is closer to - case topleft: - var m = slope(rect,{x:left,y:top}); - var mperp = -(1/m); - var b = yIntercept(rect,m); - var bperp = yIntercept(circle,mperp); - var mid = POI(m,b,mperp,bperp); - if(cx left2 && cx < right2) { // top side - return 0; - } else if(cy > bottom2 && cx > left2 && cx < right2) { // bottom side - return 2; - } else if (cx < left2 && cy > top2 && cy < bottom2) { // left side - return 3; - } else if (cx > right2 && cy > top2 && cy < bottom2) { // right side - return 1; - } else { - let returnValue=0; // 0 = top, 1 = right, 2 = bottom, 3 = left - let determiningPoint = {x:cx,y:cy}; - let topleft = dist (determiningPoint,{x:left2,y:top2}); - let topright = dist (determiningPoint,{x:right2,y:top2}); - let bottomleft = dist (determiningPoint,{x:left2,y:bottom2}); - let bottomright = dist (determiningPoint,{x:right2,y:bottom2}); - switch(Math.min(topleft,topright,bottomleft,bottomright)) { // find what corner the point is closer to, then determine what side it is closer to - case topleft: - var m = slope(rect2,{x:left2,y:top2}); - var mperp = -(1/m); - var b = yIntercept(rect2,m); - var bperp = yIntercept(determiningPoint,mperp); - var mid = POI(m,b,mperp,bperp); - if(cxedge.right) { - rect.v.x *= -1; - rect.x = edge.right-rw; - } - if(rx-rwedge.bottom) { - rect.v.y *= -1; - rect.y = edge.bottom-rh; - } - if(ry-rhedge.right) { - circle.v.x *= -1; - circle.x = edge.right-cr; - } - if(cx-credge.bottom) { - circle.v.y *= -1; - circle.y = edge.bottom-cr; - } - if(cy-cr