From f59e32ec25705777062464ac00c362763ceb37d7 Mon Sep 17 00:00:00 2001 From: Garrett Finucane Date: Fri, 22 Aug 2014 22:07:46 -0400 Subject: [PATCH] renamed to v7 --- js_v6/Block.js | 198 ------------------------ js_v6/Hex.js | 170 --------------------- js_v6/Text.js | 27 ---- js_v6/checking.js | 87 ----------- js_v6/comboTimer.js | 71 --------- js_v6/initialization.js | 315 -------------------------------------- js_v6/input.js | 168 --------------------- js_v6/main.js | 327 ---------------------------------------- js_v6/math.js | 14 -- js_v6/render.js | 113 -------------- js_v6/save-state.js | 63 -------- js_v6/update.js | 73 --------- js_v6/view.js | 211 -------------------------- js_v6/wavegen.js | 198 ------------------------ 14 files changed, 2035 deletions(-) delete mode 100644 js_v6/Block.js delete mode 100644 js_v6/Hex.js delete mode 100644 js_v6/Text.js delete mode 100644 js_v6/checking.js delete mode 100644 js_v6/comboTimer.js delete mode 100644 js_v6/initialization.js delete mode 100644 js_v6/input.js delete mode 100644 js_v6/main.js delete mode 100644 js_v6/math.js delete mode 100644 js_v6/render.js delete mode 100644 js_v6/save-state.js delete mode 100644 js_v6/update.js delete mode 100644 js_v6/view.js delete mode 100644 js_v6/wavegen.js diff --git a/js_v6/Block.js b/js_v6/Block.js deleted file mode 100644 index c710f31..0000000 --- a/js_v6/Block.js +++ /dev/null @@ -1,198 +0,0 @@ -function Block(fallingLane, color, iter, distFromHex, settled) { - // whether or not a block is rested on the center hex or another block - this.settled = (settled === undefined) ? 0 : 1; - this.height = settings.blockHeight; - //the lane which the block was shot from - this.fallingLane = fallingLane; - - this.checked=0; - //the angle at which the block falls - this.angle = 90 - (30 + 60 * fallingLane); - //for calculating the rotation of blocks attached to the center hex - this.angularVelocity = 0; - this.targetAngle = this.angle; - this.color = color; - //blocks that are slated to be deleted after a valid score has happened - this.deleted = 0; - //blocks slated to be removed from falling and added to the hex - this.removed = 0; - //value for the opacity of the white blcok drawn over falling block to give it the glow as it attaches to the hex - this.tint = 0; - //value used for deletion animation - this.opacity = 1; - //boolean for when the block is expanding - this.initializing = 1; - this.ict = MainHex.ct; - //speed of block - this.iter = iter; - //number of iterations before starting to drop - this.initLen = settings.creationDt; - //side which block is attached too - this.attachedLane = 0; - //distance from center hex - this.distFromHex = distFromHex || settings.startDist * settings.scale ; - - this.incrementOpacity = function() { - if (this.deleted) { - //add shakes - if (this.opacity >= 0.925) { - var tLane = this.attachedLane - MainHex.position; - tLane = MainHex.sides - tLane; - while (tLane < 0) { - tLane += MainHex.sides; - } - - tLane %= MainHex.sides; - MainHex.shakes.push({lane:tLane, magnitude:3 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); - } - //fade out the opacity - this.opacity = this.opacity - 0.075 * MainHex.dt; - if (this.opacity <= 0) { - //slate for final deletion - this.opacity = 0; - this.deleted = 2; - if (gameState == 1 || gameState==0) { - localStorage.setItem("saveState", exportSaveState()); - } - } - } - }; - - this.getIndex = function (){ - //get the index of the block in its stack - var parentArr = MainHex.blocks[this.attachedLane]; - for (var i = 0; i < parentArr.length; i++) { - if (parentArr[i] == this) { - return i; - } - } - }; - - this.draw = function(attached, index) { - this.height = settings.blockHeight; - if (Math.abs(settings.scale - settings.prevScale) > 0.000000001) { - this.distFromHex *= (settings.scale/settings.prevScale); - } - - this.incrementOpacity(); - if(attached === undefined) - attached = false; - - if(this.angle > this.targetAngle) { - this.angularVelocity -= angularVelocityConst * MainHex.dt; - } - else if(this.angle < this.targetAngle) { - this.angularVelocity += angularVelocityConst * MainHex.dt; - } - - if (Math.abs(this.angle - this.targetAngle + this.angularVelocity) <= Math.abs(this.angularVelocity)) { //do better soon - this.angle = this.targetAngle; - this.angularVelocity = 0; - } - else { - this.angle += this.angularVelocity; - } - - this.width = 2 * this.distFromHex / Math.sqrt(3); - this.widthWide = 2 * (this.distFromHex + this.height) / Math.sqrt(3); - //this.widthWide = this.width + this.height + 3; - var p1; - var p2; - var p3; - var p4; - if (this.initializing) { - var rat = ((MainHex.ct - this.ict)/this.initLen); - if (rat > 1) { - rat = 1; - } - p1 = rotatePoint((-this.width / 2) * rat, this.height / 2, this.angle); - p2 = rotatePoint((this.width / 2) * rat, this.height / 2, this.angle); - p3 = rotatePoint((this.widthWide / 2) * rat, -this.height / 2, this.angle); - p4 = rotatePoint((-this.widthWide / 2) * rat, -this.height / 2, this.angle); - if ((MainHex.ct - this.ict) >= this.initLen) { - this.initializing = 0; - } - } else { - p1 = rotatePoint(-this.width / 2, this.height / 2, this.angle); - p2 = rotatePoint(this.width / 2, this.height / 2, this.angle); - p3 = rotatePoint(this.widthWide / 2, -this.height / 2, this.angle); - p4 = rotatePoint(-this.widthWide / 2, -this.height / 2, this.angle); - } - - if (this.deleted) { - ctx.fillStyle = "#FFF"; - } else if (gameState === 0) { - if (this.color.charAt(0) == 'r') { - ctx.fillStyle = rgbColorsToTintedColors[this.color]; - } - else { - ctx.fillStyle = hexColorsToTintedColors[this.color]; - } - } - else { - ctx.fillStyle = this.color; - } - - ctx.globalAlpha = this.opacity; - var baseX = trueCanvas.width / 2 + Math.sin((this.angle) * (Math.PI / 180)) * (this.distFromHex + this.height / 2) + gdx; - var baseY = trueCanvas.height / 2 - Math.cos((this.angle) * (Math.PI / 180)) * (this.distFromHex + this.height / 2) + gdy; - ctx.beginPath(); - ctx.moveTo(baseX + p1.x, baseY + p1.y); - ctx.lineTo(baseX + p2.x, baseY + p2.y); - ctx.lineTo(baseX + p3.x, baseY + p3.y); - ctx.lineTo(baseX + p4.x, baseY + p4.y); - //ctx.lineTo(baseX + p1.x, baseY + p1.y); - ctx.closePath(); - ctx.fill(); - - if (this.tint) { - if (this.opacity < 1) { - if (gameState == 1 || gameState==0) { - localStorage.setItem("saveState", exportSaveState()); - } - - this.iter = 2.25; - this.tint = 0; - } - - ctx.fillStyle = "#FFF"; - ctx.globalAlpha = this.tint; - ctx.beginPath(); - ctx.moveTo(baseX + p1.x, baseY + p1.y); - ctx.lineTo(baseX + p2.x, baseY + p2.y); - ctx.lineTo(baseX + p3.x, baseY + p3.y); - ctx.lineTo(baseX + p4.x, baseY + p4.y); - ctx.lineTo(baseX + p1.x, baseY + p1.y); - ctx.closePath(); - ctx.fill(); - this.tint -= 0.02 * MainHex.dt; - if (this.tint < 0) { - this.tint = 0; - } - } - - ctx.globalAlpha = 1; - }; -} - -function findCenterOfBlocks(arr) { - var avgDFH = 0; - var avgAngle = 0; - for (var i = 0; i < arr.length; i++) { - avgDFH += arr[i].distFromHex; - var ang = arr[i].angle; - while (ang < 0) { - ang += 360; - } - - avgAngle += ang % 360; - } - - avgDFH /= arr.length; - avgAngle /= arr.length; - - return { - x:trueCanvas.width/2 + Math.cos(avgAngle * (Math.PI / 180)) * avgDFH, - y:trueCanvas.height/2 + Math.sin(avgAngle * (Math.PI / 180)) * avgDFH - }; -} diff --git a/js_v6/Hex.js b/js_v6/Hex.js deleted file mode 100644 index 9a52e87..0000000 --- a/js_v6/Hex.js +++ /dev/null @@ -1,170 +0,0 @@ -function Hex(sideLength) { - this.playThrough = 0; - this.fillColor = [44,62,80]; - this.tempColor = [44,62,80]; - this.angularVelocity = 0; - this.position = 0; - this.dy = 0; - this.dt = 1; - this.sides = 6; - this.blocks = []; - this.angle = 180 / this.sides; - this.targetAngle = this.angle; - this.shakes = []; - this.sideLength = sideLength; - this.strokeColor = 'blue'; - this.x = trueCanvas.width / 2; - this.y = trueCanvas.height / 2; - this.ct = 0; - this.lastCombo = this.ct - settings.comboTime; - this.lastColorScored = "#000"; - this.comboTime = 1; - this.texts = []; - this.lastRotate = Date.now(); - for (var i = 0; i < this.sides; i++) { - this.blocks.push([]); - } - - this.shake = function(obj) { //lane as in particle lane - var angle = 30 + obj.lane * 60; - angle *= Math.PI / 180; - var dx = Math.cos(angle) * obj.magnitude; - var dy = Math.sin(angle) * obj.magnitude; - gdx -= dx; - gdy += dy; - obj.magnitude /= 2 * this.dt; - if (obj.magnitude < 1) { - for (var i = 0; i < this.shakes.length; i++) { - if (this.shakes[i] == obj) { - this.shakes.splice(i, 1); - } - } - } - }; - - this.addBlock = function(block) { - if (!(gameState == 1 || gameState === 0)) return; - block.settled = 1; - block.tint = 0.6; - var lane = this.sides - block.fallingLane;// -this.position; - this.shakes.push({lane:block.fallingLane, magnitude:4.5 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); - lane += this.position; - lane = (lane + this.sides) % this.sides; - block.distFromHex = MainHex.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; - this.blocks[lane].push(block); - block.attachedLane = lane; - block.checked = 1; - }; - - this.doesBlockCollide = function(block, position, tArr) { - if (block.settled) { - return; - } - - if (position !== undefined) { - arr = tArr; - if (position <= 0) { - if (block.distFromHex - block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { - block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); - block.settled = 1; - block.checked = 1; - } else { - block.settled = 0; - block.iter = 1.5 + (waveone.difficulty/15) * 3; - } - } else { - if (arr[position - 1].settled && block.distFromHex - block.iter * this.dt * settings.scale - arr[position - 1].distFromHex - arr[position - 1].height <= 0) { - block.distFromHex = arr[position - 1].distFromHex + arr[position - 1].height; - block.settled = 1; - block.checked = 1; - } - else { - block.settled = 0; - block.iter = 1.5 + (waveone.difficulty/15) * 3; - } - } - } else { - var lane = this.sides - block.fallingLane;// -this.position; - lane += this.position; - - lane = (lane+this.sides) % this.sides; - var arr = this.blocks[lane]; - - if (arr.length > 0) { - if (block.distFromHex + block.iter * this.dt * settings.scale - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) { - block.distFromHex = arr[arr.length - 1].distFromHex + arr[arr.length - 1].height; - this.addBlock(block); - } - } else { - if (block.distFromHex + block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { - block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); - this.addBlock(block); - } - } - } - }; - - this.rotate = function(steps) { - if(Date.now()-this.lastRotate<75 && !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) return; - if (!(gameState === 1 || gameState === 0)) return; - this.position += steps; - if (!history[this.ct]) { - history[this.ct] = {}; - } - - if (!history[this.ct].rotate) { - history[this.ct].rotate = steps; - } - else { - history[this.ct].rotate += steps; - } - - while (this.position < 0) { - this.position += 6; - } - - this.position = this.position % this.sides; - this.blocks.forEach(function(blocks) { - blocks.forEach(function(block) { - block.targetAngle = block.targetAngle - steps * 60; - }); - }); - - this.targetAngle = this.targetAngle - steps * 60; - this.lastRotate = Date.now(); - }; - - this.draw = function() { - this.x = trueCanvas.width/2; - - if (gameState != -2) { - this.y = trueCanvas.height/2; - } - this.sideLength = settings.hexWidth; - gdx = 0; - gdy = 0; - for (var i = 0; i < this.shakes.length; i++) { - this.shake(this.shakes[i]); - } - if (this.angle > this.targetAngle) { - this.angularVelocity -= angularVelocityConst * this.dt; - } - else if(this.angle < this.targetAngle) { - this.angularVelocity += angularVelocityConst * this.dt; - } - - if (Math.abs(this.angle - this.targetAngle + this.angularVelocity) <= Math.abs(this.angularVelocity)) { //do better soon - this.angle = this.targetAngle; - this.angularVelocity = 0; - } - else { - this.angle += this.angularVelocity; - } - - drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle,arrayToColor(this.fillColor) , 0, 'rgba(0,0,0,0)'); - }; -} - -function arrayToColor(arr){ - return 'rgb(' + arr[0]+ ','+arr[1]+','+arr[2]+')'; -} diff --git a/js_v6/Text.js b/js_v6/Text.js deleted file mode 100644 index dfc08cb..0000000 --- a/js_v6/Text.js +++ /dev/null @@ -1,27 +0,0 @@ -function Text(x,y,text,font,color,incrementFunction){ - this.x = x; - this.y = y; - this.font = font; - this.color = color; - this.opacity =1; - this.text = text; - this.alive=1; - this.draw = function(){ - if (this.alive>0) { - ctx.globalAlpha = this.opacity; - renderText((this.x + gdx), (this.y + gdy),50,this.color,this.text); - ctx.globalAlpha =1; - incrementFunction(this); - return true; - } - else { - return false; - } - }; -} - -function fadeUpAndOut(text){ - text.opacity -= MainHex.dt * Math.pow(Math.pow((1-text.opacity), 1/3)+1,3)/100; - text.alive = text.opacity; - text.y -= 3 * MainHex.dt; -} diff --git a/js_v6/checking.js b/js_v6/checking.js deleted file mode 100644 index b104bdb..0000000 --- a/js_v6/checking.js +++ /dev/null @@ -1,87 +0,0 @@ -function search(twoD,oneD){ - // Searches a two dimensional array to see if it contains a one dimensional array. indexOf doesn't work in this case - for(var i=0;i
Either press the right and left arrow keys or tap the left and right sides of the screen to rotate the Hexagon

Clear blocks by making 3 or more blocks of the same color touch

Get points by clearing blocks

Time left before your combo streak disappears is indicated shown by the colored lines in the outer hexagon

Pause by pressing or the letter p
Restart by pressing or enter
Bring up this menu by pressing

Found a bug? Go here window.innerWidth/2) { - if (gameState != 1 && gameState != -2 && gameState != -1) { - if (importing === 0) { - resumeGame(); - } - else { - init(1); - } - } - MainHex.rotate(-1); - } -} diff --git a/js_v6/main.js b/js_v6/main.js deleted file mode 100644 index 2cafebc..0000000 --- a/js_v6/main.js +++ /dev/null @@ -1,327 +0,0 @@ -function scaleCanvas() { - canvas.width = $(window).width(); - canvas.height = $(window).height(); - - if (canvas.height > canvas.width) { - settings.scale = (canvas.width / 800) * settings.baseScale; - } else { - settings.scale = (canvas.height / 800) * settings.baseScale; - } - - trueCanvas = { - width: canvas.width, - height: canvas.height - }; - - if (window.devicePixelRatio) { - var cw = $("#canvas").attr('width'); - var ch = $("#canvas").attr('height'); - - $("#canvas").attr('width', cw * window.devicePixelRatio); - $("#canvas").attr('height', ch * window.devicePixelRatio); - $("#canvas").css('width', cw); - $("#canvas").css('height', ch); - - trueCanvas = { - width: cw, - height: ch - }; - - ctx.scale(window.devicePixelRatio, window.devicePixelRatio); - } -} - -function toggleDevTools() { - $('#devtools').toggle(); -} - -function resumeGame() { - gameState = 1; - hideUIElements(); - $('#pauseBtn').show(); - $('#restartBtn').hide(); - importing = 0; - startTime = Date.now(); - setTimeout(function() { - if ((gameState == 1 || gameState == 2) && !$('#helpScreen').is(':visible')) { - $('.helpText').fadeOut(150, "linear"); - } - }, 7000); - - checkVisualElements(); -} - -function checkVisualElements() { - if (!$('.helpText').is(":visible")) $('.helpText').fadeIn(150, "linear"); - if (!$('#pauseBtn').is(':visible')) $('#pauseBtn').fadeIn(150, "linear"); - if (!$('#restartBtn').is(':visible')) $('#restartBtn').fadeOut(150, "linear"); -} - -function hideUIElements() { - $('#pauseBtn').hide(); - $('#restartBtn').hide(); - $('#startBtn').hide(); - $("#attributions").hide(); - $("#bottombar").hide(); -} - -function init(b) { - if (b) { - hidebottombar(); - - - if ($('#helpScreen').is(":visible")) { - $('#helpScreen').fadeOut(150, "linear"); - } - - - setTimeout(function() { - $('.helpText').fadeOut(150, "linear"); - }, 7000); - clearSaveState(); - } - - $("#pauseBtnInner").html(''); - hideUIElements(); - var saveState = localStorage.getItem("saveState") || "{}"; - saveState = JSONfn.parse(saveState); - document.getElementById("canvas").className = ""; - history = {}; - importedHistory = undefined; - importing = 0; - isGameOver = 2; - score = saveState.score || 0; - prevScore = 0; - spawnLane = 0; - op = 0; - tweetblock=false; - scoreOpacity = 0; - gameState = 1; - $("#restartBtn").hide(); - $("#pauseBtn").show(); - if (saveState.hex !== undefined) gameState = 1; - - settings.blockHeight = settings.baseBlockHeight * settings.scale; - settings.hexWidth = settings.baseHexWidth * settings.scale; - MainHex = saveState.hex || new Hex(settings.hexWidth); - if (saveState.hex) { - MainHex.playThrough += 1; - } - MainHex.sideLength = settings.hexWidth; - - var i; - var block; - if (saveState.blocks) { - saveState.blocks.map(function(o) { - if (rgbToHex[o.color]) { - o.color = rgbToHex[o.color]; - } - }); - - for (i = 0; i < saveState.blocks.length; i++) { - block = saveState.blocks[i]; - blocks.push(block); - } - } else { - blocks = []; - } - - gdx = saveState.gdx || 0; - gdy = saveState.gdy || 0; - comboTime = saveState.comboTime || 0; - - for (i = 0; i < MainHex.blocks.length; i++) { - for (var j = 0; j < MainHex.blocks[i].length; j++) { - MainHex.blocks[i][j].height = settings.blockHeight; - MainHex.blocks[i][j].settled = 0; - } - } - - MainHex.blocks.map(function(i) { - i.map(function(o) { - if (rgbToHex[o.color]) { - o.color = rgbToHex[o.color]; - } - }); - }); - - MainHex.y = -100; - - startTime = Date.now(); - waveone = saveState.wavegen || new waveGen(MainHex); - - MainHex.texts = []; //clear texts - MainHex.delay = 15; - hideText(); -} - -function addNewBlock(blocklane, color, iter, distFromHex, settled) { //last two are optional parameters - iter *= settings.speedModifier; - if (!history[MainHex.ct]) { - history[MainHex.ct] = {}; - } - - history[MainHex.ct].block = { - blocklane: blocklane, - color: color, - iter: iter - }; - - if (distFromHex) { - history[MainHex.ct].distFromHex = distFromHex; - } - if (settled) { - blockHist[MainHex.ct].settled = settled; - } - blocks.push(new Block(blocklane, color, iter, distFromHex, settled)); -} - -function exportHistory() { - $('#devtoolsText').html(JSON.stringify(history)); - toggleDevTools(); -} - -function setStartScreen() { - $('#startBtn').show(); - init(); - if (isStateSaved()) { - importing = 0; - } else { - importing = 1; - } - - $('#pauseBtn').hide(); - $('#restartBtn').hide(); - $('#startBtn').show(); - $('#attributions').show(); - showbottombar(); - - gameState = 0; - requestAnimFrame(animLoop); -} - -function animLoop() { - switch (gameState) { - case 1: - requestAnimFrame(animLoop); - render(); - var now = Date.now(); - var dt = (now - lastTime)/16.666; - - if(gameState == 1 ){ - if(!MainHex.delay) { - update(dt); - } - else{ - MainHex.delay--; - } - } - - lastTime = now; - - if (checkGameOver() && !importing) { - var saveState = localStorage.getItem("saveState") || "{}"; - saveState = JSONfn.parse(saveState); - gameState = 2; - - setTimeout(function() { - enableRestart(); - }, 150); - - if ($('#helpScreen').is(':visible')) { - $('#helpScreen').fadeOut(150, "linear"); - } - - if ($('#pauseBtn').is(':visible')) $('#pauseBtn').fadeOut(150, "linear"); - if ($('#restartBtn').is(':visible')) $('#restartBtn').fadeOut(150, "linear"); - if (!$('.helpText').is(':visible')) $('.helpText').fadeIn(150, "linear"); - - showbottombar(); - canRestart = 0; - clearSaveState(); - } - break; - - case 0: - requestAnimFrame(animLoop); - render(); - break; - - case -1: - requestAnimFrame(animLoop); - render(); - break; - - case 2: - var now = Date.now(); - var dt = (now - lastTime)/16.666; - requestAnimFrame(animLoop); - update(dt); - render(); - lastTime = now; - break; - - case 3: - requestAnimFrame(animLoop); - fadeOutObjectsOnScreen(); - render(); - break; - - case 4: - setTimeout(function() { - initialize(1); - }, 1); - render(); - return; - - default: - initialize(); - setStartScreen(); - break; - } - - if (!(gameState == 1 || gameState == 2)) { - lastTime = Date.now(); - } -} - -function enableRestart() { - canRestart = 1; -} - -function isInfringing(hex) { - for (var i = 0; i < hex.sides; i++) { - var subTotal = 0; - for (var j = 0; j < hex.blocks[i].length; j++) { - subTotal += hex.blocks[i][j].deleted; - } - - if (hex.blocks[i].length - subTotal > settings.rows) { - return true; - } - } - return false; -} - -function checkGameOver() { - for (var i = 0; i < MainHex.sides; i++) { - if (isInfringing(MainHex)) { - $.get('http://54.183.184.126/' + String(score)) - if (highscores.indexOf(score) == -1) { - highscores.push(score); - } - writeHighScores(); - gameOverDisplay(); - return true; - } - } - return false; -} - -function showHelp() { - if($($("#pauseBtnInner").children()[0]).hasClass("fa-pause") && gameState != 0) { - return; - } - $("#openSideBar").fadeIn(150,"linear"); - $('#helpScreen').fadeToggle(150, "linear"); -} diff --git a/js_v6/math.js b/js_v6/math.js deleted file mode 100644 index fdf254f..0000000 --- a/js_v6/math.js +++ /dev/null @@ -1,14 +0,0 @@ -function rotatePoint(x, y, theta) { - var thetaRad = theta * (Math.PI / 180); - var rotX = Math.cos(thetaRad) * x - Math.sin(thetaRad) * y; - var rotY = Math.sin(thetaRad) * x + Math.cos(thetaRad) * y; - - return { - x: rotX, - y: rotY - }; -} - -function randInt(min, max) { - return Math.floor((Math.random() * max) + min); -} diff --git a/js_v6/render.js b/js_v6/render.js deleted file mode 100644 index 9002faa..0000000 --- a/js_v6/render.js +++ /dev/null @@ -1,113 +0,0 @@ -function render() { - var grey = '#bdc3c7'; - if (gameState === 0) { - grey = "rgb(220, 223, 225)"; - } - - ctx.clearRect(0, 0, trueCanvas.width, trueCanvas.height); - clearGameBoard(); - if (gameState === 1 || gameState === 2 || gameState === -1 || gameState === 0) { - if (op < 1) { - op += 0.01; - } - ctx.globalAlpha = op; - drawPolygon(trueCanvas.width / 2 , trueCanvas.height / 2 , 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, grey, false,6); - drawTimer(); - ctx.globalAlpha = 1; - } - - var i; - for (i = 0; i < MainHex.blocks.length; i++) { - for (var j = 0; j < MainHex.blocks[i].length; j++) { - var block = MainHex.blocks[i][j]; - block.draw(true, j); - } - } - - for (i = 0; i < blocks.length; i++) { - blocks[i].draw(); - } - - MainHex.draw(); - if (gameState ==1 || gameState ==-1 || gameState === 0) { - drawScoreboard(); - } - - for (i = 0; i < MainHex.texts.length; i++) { - var alive = MainHex.texts[i].draw(); - if(!alive){ - MainHex.texts.splice(i,1); - i--; - } - } - - if ((MainHex.ct < 400 && (gameState !== 0) && !MainHex.playThrough)) { - if (MainHex.ct > 350) { - ctx.globalAlpha = (50 - (MainHex.ct - 350))/50; - } - - if (MainHex.ct < 50) { - ctx.globalAlpha = (MainHex.ct)/50; - } - - renderBeginningText(); - ctx.globalAlpha = 1; - } - - if (gameState == -1) { - ctx.globalAlpha = 0.9; - ctx.fillStyle = 'rgb(236,240,241)'; - ctx.fillRect(0, 0, trueCanvas.width, trueCanvas.height); - ctx.globalAlpha = 1; - } - - settings.prevScale = settings.scale; - settings.hexWidth = settings.baseHexWidth * settings.scale; - settings.blockHeight = settings.baseBlockHeight * settings.scale; -} - -function renderBeginningText() { - renderText((trueCanvas.width)/2 + 1.5 * settings.scale, (trueCanvas.height)/2 - 208 * settings.scale, 35, '#2c3e50', 'Controls', '35px Roboto'); - renderText((trueCanvas.width)/2 - 85 * settings.scale, (trueCanvas.height)/2 - 169 * settings.scale, 20, '#2c3e50', 'Rotation:', '20px Roboto'); - renderText((trueCanvas.width)/2 - 21 * settings.scale, (trueCanvas.height)/2 - 141 * settings.scale, 12, '#2c3e50', 'Left', '12px Roboto'); - renderText((trueCanvas.width)/2 + 25 * settings.scale, (trueCanvas.height)/2 - 141 * settings.scale, 12, '#2c3e50', 'Right', '12px Roboto'); - drawKey("right",(trueCanvas.width)/2 + 23 * settings.scale - 35/2 * settings.scale, (trueCanvas.height)/2 - 195 * settings.scale); - drawKey("left",(trueCanvas.width)/2 - 23 * settings.scale - 35/2 * settings.scale, (trueCanvas.height)/2 - 195 * settings.scale); - renderText((trueCanvas.width)/2 + 1.5 * settings.scale, (trueCanvas.height)/2 - 125 * settings.scale, 20, '#2c3e50', 'Rotate the Hexagon to make combos of 3+ touching blocks!', '20px Roboto'); - renderText((trueCanvas.width)/2 + 1.5 * settings.scale, (trueCanvas.height)/2 - 105 * settings.scale, 20, '#2c3e50', 'Make combos in a row to receive a score multiplier!', '20px Roboto'); - renderText((trueCanvas.width)/2 + 1.5 * settings.scale, (trueCanvas.height)/2 - 85 * settings.scale, 20, '#2c3e50', 'Don\'t let the blocks stack outside of the gray Hexagon!', '20px Roboto'); -} - -function drawKey(key, x, y) { - ctx.save(); - ctx.beginPath(); - ctx.fillStyle = '#2c3e50'; - ctx.strokeStyle = '#2c3e50'; - ctx.lineWidth = 4 * settings.scale; - ctx.rect(x + 2.5 * settings.scale, y + 2.5 * settings.scale, 35 * settings.scale, 35 * settings.scale); - ctx.stroke(); - - switch (key) { - case "left": - ctx.translate(x + settings.scale * 28, y + settings.scale * 13); - ctx.rotate(3.14159); - ctx.font = "20px Fontawesome"; - ctx.scale(settings.scale, settings.scale); - ctx.fillText(String.fromCharCode("0xf04b"), 0, 0); - break; - case "right": - ctx.font = "20px Fontawesome"; - ctx.translate(x + settings.scale * 12.5, y + settings.scale * 27.5); - ctx.scale(settings.scale, settings.scale); - ctx.fillText(String.fromCharCode("0xf04b"), 0, 0); - break; - - default: - ctx.font = "35px Roboto"; - ctx.translate(x + settings.scale * 25 , y + settings.scale * 39.5); - ctx.scale(settings.scale, settings.scale); - ctx.fillText(key, 0, 0); - } - - ctx.restore(); -} diff --git a/js_v6/save-state.js b/js_v6/save-state.js deleted file mode 100644 index 52ac757..0000000 --- a/js_v6/save-state.js +++ /dev/null @@ -1,63 +0,0 @@ -function exportSaveState() { - var state = {}; - - if(gameState == 1 || gameState == -1 || (gameState === 0 && localStorage.getItem('saveState') !== undefined)) { - state = { - hex: $.extend(true, {}, MainHex), - blocks: $.extend(true, [], blocks), - score: score, - wavegen: waveone, - gdx: gdx, - gdy: gdy, - comboTime:settings.comboTime - }; - - state.hex.blocks.map(function(a){ - for (var i = 0; i < a.length; i++) { - a[i] = $.extend(true, {}, a[i]); - } - - a.map(descaleBlock); - }); - - for (var i = 0; i < state.blocks.length; i++) { - state.blocks[i] = $.extend(true, {}, state.blocks[i]); - } - - state.blocks.map(descaleBlock); - } - - localStorage.setItem('highscores', JSON.stringify(highscores)); - - return JSONfn.stringify(state); -} - -function descaleBlock(b) { - b.distFromHex /= settings.scale; -} - -function writeHighScores() { - highscores.sort( - function(a,b){ - a = parseInt(a, 10); - b = parseInt(b, 10); - if (a < b) { - return 1; - } else if (a > b) { - return -1; - }else { - return 0; - } - } - ); - highscores = highscores.slice(0,3); - localStorage.setItem("highscores", JSON.stringify(highscores)); -} - -function clearSaveState() { - localStorage.setItem("saveState", "{}"); -} - -function isStateSaved() { - return localStorage.getItem("saveState") != "{}" && localStorage.getItem("saveState") != undefined; -} diff --git a/js_v6/update.js b/js_v6/update.js deleted file mode 100644 index ab57878..0000000 --- a/js_v6/update.js +++ /dev/null @@ -1,73 +0,0 @@ - -//remember to update history function to show the respective iter speeds -function update(dt) { - MainHex.dt = dt; - if (gameState == 1) { - waveone.update(); - if (MainHex.ct - waveone.prevTimeScored > 1000) { - waveone.prevTimeScored = MainHex.ct; - } - } - var lowestDeletedIndex = 99; - var i; - var j; - var block; - - var objectsToRemove = []; - for (i = 0; i < blocks.length; i++) { - MainHex.doesBlockCollide(blocks[i]); - if (!blocks[i].settled) { - if (!blocks[i].initializing) blocks[i].distFromHex -= blocks[i].iter * dt * settings.scale; - } else if (!blocks[i].removed) { - blocks[i].removed = 1; - } - } - - for (i = 0; i < MainHex.blocks.length; i++) { - for (j = 0; j < MainHex.blocks[i].length; j++) { - if (MainHex.blocks[i][j].checked ==1 ) { - consolidateBlocks(MainHex,MainHex.blocks[i][j].attachedLane,MainHex.blocks[i][j].getIndex()); - MainHex.blocks[i][j].checked=0; - } - } - } - - for (i = 0; i < MainHex.blocks.length; i++) { - lowestDeletedIndex = 99; - for (j = 0; j < MainHex.blocks[i].length; j++) { - block = MainHex.blocks[i][j]; - if (block.deleted == 2) { - MainHex.blocks[i].splice(j,1); - blockDestroyed(); - if (j < lowestDeletedIndex) lowestDeletedIndex = j; - j--; - } - } - - if (lowestDeletedIndex < MainHex.blocks[i].length) { - for (j = lowestDeletedIndex; j < MainHex.blocks[i].length; j++) { - MainHex.blocks[i][j].settled = 0; - } - } - } - - for (i = 0; i < MainHex.blocks.length; i++) { - for (j = 0; j < MainHex.blocks[i].length; j++) { - block = MainHex.blocks[i][j]; - MainHex.doesBlockCollide(block, j, MainHex.blocks[i]); - - if (!MainHex.blocks[i][j].settled) { - MainHex.blocks[i][j].distFromHex -= block.iter * dt * settings.scale; - } - } - } - - for(i = 0; i < blocks.length;i++){ - if (blocks[i].removed == 1) { - blocks.splice(i,1); - i--; - } - } - - MainHex.ct += dt; -} diff --git a/js_v6/view.js b/js_v6/view.js deleted file mode 100644 index e1f164d..0000000 --- a/js_v6/view.js +++ /dev/null @@ -1,211 +0,0 @@ -// t: current time, b: begInnIng value, c: change In value, d: duration -function easeOutCubic(t, b, c, d) { - return c * ((t = t / d - 1) * t * t + 1) + b; -} - -function renderText(x, y, fontSize, color, text, font) { - ctx.save(); - if (!font) { - font = 'px/0 Roboto'; - } - - fontSize *= settings.scale; - ctx.font = fontSize + font; - ctx.textAlign = 'center'; - ctx.fillStyle = color; - ctx.fillText(text, x, y + (fontSize / 2) - 9 * settings.scale); - ctx.restore(); -} - -function drawScoreboard() { - if (scoreOpacity < 1) { - scoreOpacity += 0.01; - textOpacity += 0.01; - } - - ctx.globalAlpha = textOpacity; - var scoreSize = 50; - var scoreString = String(score); - if (scoreString.length == 6) { - scoreSize = 43; - } else if (scoreString.length == 7) { - scoreSize = 35; - } else if (scoreString.length == 8) { - scoreSize = 31; - } else if (scoreString.length == 9) { - scoreSize = 27; - } - - if (gameState === 0) { - renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome'); - renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 170 * settings.scale, 150, "#2c3e50", "Hextris"); - renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, trueCanvas.height / 2 + gdy + 100 * settings.scale, 20, "rgb(44,62,80)", 'Play!'); - } else if (gameState != 0 && textOpacity > 0) { - textOpacity -= 0.05; - renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome'); - renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 170 * settings.scale, 150, "#2c3e50", "Hextris"); - renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, trueCanvas.height / 2 + gdy + 100 * settings.scale, 20, "rgb(44,62,80)", 'Play!'); - ctx.globalAlpha = scoreOpacity; - renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, "rgb(236, 240, 241)", score); - } else { - ctx.globalAlpha = scoreOpacity; - renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, "rgb(236, 240, 241)", score); - } - - ctx.globalAlpha = 1; -} - -function clearGameBoard() { - drawPolygon(trueCanvas.width / 2, trueCanvas.height / 2, 6, trueCanvas.width / 2, 30, hexagonBackgroundColor, 0, 'rgba(0,0,0,0)'); -} - -function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor) { - ctx.fillStyle = fillColor; - ctx.lineWidth = lineWidth; - ctx.strokeStyle = lineColor; - - ctx.beginPath(); - var coords = rotatePoint(0, radius, theta); - ctx.moveTo(coords.x + x, coords.y + y); - var oldX = coords.x; - var oldY = coords.y; - for (var i = 0; i < sides; i++) { - coords = rotatePoint(oldX, oldY, 360 / sides); - ctx.lineTo(coords.x + x, coords.y + y); - oldX = coords.x; - oldY = coords.y; - } - - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.strokeStyle = 'rgba(0,0,0,0)'; -} - -function toggleClass(element, active) { - if ($(element).hasClass(active)) { - $(element).removeClass(active); - } else { - $(element).addClass(active); - } -} - -function showText(text) { - var messages = { - 'paused': "
Paused

Press p to resume
", - 'pausedMobile': "
Paused

Press to resume
", - 'start': "
Press enter to start
", - 'gameover': "
Game Over: " + score + " pts

High Scores:
" - - }; - - if (text == 'paused') { - if (settings.platform == 'mobile') { - text = 'pausedMobile'; - } - } - - if (text == 'gameover') { - var allZ = 1; - var i; - - for (i = 0; i < 3; i++) { - if (highscores.length > i) { - messages['gameover'] += ""; - } - } - - var restartText; - if (settings.platform == 'mobile') { - restartText = 'Tap anywhere to restart!'; - } else { - restartText = 'Press enter (or click anywhere!) to restart!'; - } - - messages['gameover'] += "
" + (i + 1) + ". " + highscores[i] + " pts

" + restartText + "
"; - - if (allZ) { - for (i = 0; i < highscores.length; i++) { - if (highscores[i] !== 0) { - allZ = 0; - } - } - } - } - messages['gameover'] += "
" - $("#overlay").html(messages[text]); - $("#overlay").fadeIn("1000", "swing"); - - if (text == 'gameover') { - - if (settings.platform == 'mobile') { - $('.tg').css('margin-top', '4px'); - } - } -} - -function setMainMenu() { - gameState = 4; - canRestart = false; - setTimeout(function() { - canRestart = 's'; - }, 500); - $('#restartBtn').hide(); - if ($($("#pauseBtn").children()[0]).attr('class').indexOf('pause') == -1) { - $("#pauseBtnInner").html(''); - } else { - $("#pauseBtnInner").html(''); - } -} - -function hideText() { - $("#overlay").fadeOut("1000", function() { - $("#overlay").html(""); - }) -} - -function gameOverDisplay() { - $("#attributions").show(); - var c = document.getElementById("canvas"); - c.className = "blur"; - showText('gameover'); - showbottombar(); -} - -function pause(o) { - writeHighScores(); - var message; - if (o) { - message = ''; - } else { - message = 'paused'; - } - - var c = document.getElementById("canvas"); - if (gameState == -1) { - $('#restartBtn').fadeOut(150, "linear"); - if ($('#helpScreen').is(':visible')) { - $('#helpScreen').fadeOut(150, "linear"); - } - - $("#pauseBtnInner").html(''); - $('.helpText').fadeOut(200, 'linear'); - hideText(); - hidebottombar(); - setTimeout(function() { - gameState = prevGameState; - }, 200) - - } else if (gameState != -2 && gameState !== 0 && gameState !== 2) { - $('#restartBtn').fadeIn(150, "linear"); - $('.helpText').fadeIn(200, 'linear'); - showbottombar(); - if (message == 'paused') { - showText(message); - } - - $("#pauseBtnInner").html(''); - prevGameState = gameState; - gameState = -1; - } -} diff --git a/js_v6/wavegen.js b/js_v6/wavegen.js deleted file mode 100644 index aca610e..0000000 --- a/js_v6/wavegen.js +++ /dev/null @@ -1,198 +0,0 @@ -function blockDestroyed() { - if (waveone.nextGen > 1350) { - waveone.nextGen -= 20 * settings.creationSpeedModifier; - } else if (waveone.nextGen > 600) { - waveone.nextGen -= 10 * settings.creationSpeedModifier; - } else { - waveone.nextGen = 600; - } - - if (waveone.difficulty < 35) { - waveone.difficulty += 0.11 * settings.speedModifier; - } else { - waveone.difficulty = 35; - } -} - -function waveGen(hex) { - this.lastGen = 0; - this.last = 0; - this.nextGen = 2300; - this.start = 0; - this.colors = colors; - this.ct = 0; - this.hex = hex; - this.difficulty = 1; - this.dt = 0; - this.update = function() { - this.currentFunction(); - this.dt = (settings.platform == 'mobile' ? 10.0 : 15) * MainHex.ct; - this.computeDifficulty(); - if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { - if (this.nextGen > 600) { - this.nextGen -= 14 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; - } - } - }; - - this.randomGeneration = function() { - if (this.dt - this.lastGen > this.nextGen) { - this.ct++; - this.lastGen = this.dt; - var fv = randInt(0, MainHex.sides); - addNewBlock(fv, colors[randInt(0, colors.length)], 1.6 + (this.difficulty / 15) * 3); - var lim = 5; - if (this.ct > lim) { - var nextPattern = randInt(0, 3 + 21); - if (nextPattern > 15) { - this.ct = 0; - this.currentFunction = this.doubleGeneration; - } else if (nextPattern > 10) { - this.ct = 0; - this.currentFunction = this.crosswiseGeneration; - } else if (nextPattern > 7) { - this.ct = 0; - this.currentFunction = this.spiralGeneration; - } else if (nextPattern > 4) { - this.ct = 0; - this.currentFunction = this.circleGeneration; - } else if (nextPattern > 1) { - this.ct = 0; - this.currentFunction = this.halfCircleGeneration; - } - } - } - }; - - this.computeDifficulty = function() { - if (this.difficulty < 35) { - if (this.difficulty < 8) { - this.difficulty += (this.dt - this.last) / (2066667) * settings.speedModifier; - } else if (this.difficulty < 15) { - this.difficulty += (this.dt - this.last) / (43333333) * settings.speedModifier; - } else { - this.difficulty += (this.dt - this.last) / (90000000) * settings.speedModifier; - } - } - }; - - this.circleGeneration = function() { - if (this.dt - this.lastGen > this.nextGen + 500) { - var numColors = randInt(1, 4); - if (numColors == 3) { - numColors = randInt(1, 4); - } - - var colorList = []; - nextLoop: for (var i = 0; i < numColors; i++) { - var q = randInt(0, colors.length); - for (var j in colorList) { - if (colorList[j] == colors[q]) { - i--; - continue nextLoop; - } - } - colorList.push(colors[q]); - } - - for (var i = 0; i < MainHex.sides; i++) { - addNewBlock(i, colorList[i % numColors], 1.5 + (this.difficulty / 15) * 3); - } - - this.ct += 15; - this.lastGen = this.dt; - this.shouldChangePattern(1); - } - }; - - this.halfCircleGeneration = function() { - if (this.dt - this.lastGen > (this.nextGen + 500) / 2) { - var numColors = randInt(1, 3); - var c = colors[randInt(0, colors.length)]; - var colorList = [c, c, c]; - if (numColors == 2) { - colorList = [c, colors[randInt(0, colors.length)], c]; - } - - var d = randInt(0, 6); - for (var i = 0; i < 3; i++) { - addNewBlock((d + i) % 6, colorList[i], 1.5 + (this.difficulty / 15) * 3); - } - - this.ct += 8; - this.lastGen = this.dt; - this.shouldChangePattern(); - } - }; - - this.crosswiseGeneration = function() { - if (this.dt - this.lastGen > this.nextGen) { - var ri = randInt(0, colors.length); - var i = randInt(0, colors.length); - addNewBlock(i, colors[ri], 0.6 + (this.difficulty / 15) * 3); - addNewBlock((i + 3) % MainHex.sides, colors[ri], 0.6 + (this.difficulty / 15) * 3); - this.ct += 1.5; - this.lastGen = this.dt; - this.shouldChangePattern(); - } - }; - - this.spiralGeneration = function() { - var dir = randInt(0, 2); - if (this.dt - this.lastGen > this.nextGen * (2 / 3)) { - if (dir) { - addNewBlock(5 - (this.ct % MainHex.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2)); - } else { - addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2)); - } - this.ct += 1; - this.lastGen = this.dt; - this.shouldChangePattern(); - } - }; - - this.doubleGeneration = function() { - if (this.dt - this.lastGen > this.nextGen) { - var i = randInt(0, colors.length); - addNewBlock(i, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3); - addNewBlock((i + 1) % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3); - this.ct += 2; - this.lastGen = this.dt; - this.shouldChangePattern(); - } - }; - - this.setRandom = function() { - this.ct = 0; - this.currentFunction = this.randomGeneration; - }; - - this.shouldChangePattern = function(x) { - if (x) { - var q = randInt(0, 4); - this.ct = 0; - switch (q) { - case 0: - this.currentFunction = this.doubleGeneration; - break; - case 1: - this.currentFunction = this.spiralGeneration; - break; - case 2: - this.currentFunction = this.crosswiseGeneration; - break; - } - } else if (this.ct > 8) { - if (randInt(0, 2) === 0) { - this.setRandom(); - return 1; - } - } - - return 0; - }; - - // rest of generation functions - - this.currentFunction = this.randomGeneration; -}