From f27cb249881848fa4a1004c7b361c206989aa847 Mon Sep 17 00:00:00 2001 From: Garrett Finucane Date: Fri, 4 Jul 2014 12:42:44 -0400 Subject: [PATCH] Clock to Hex --- index.html | 2 +- js/Block.js | 18 ++++++++-------- js/{Clock.js => Hex.js} | 4 ++-- js/checking.js | 2 +- js/comboTimer.js | 8 +++---- js/input.js | 22 ++++++++++---------- js/main.js | 46 ++++++++++++++++++++--------------------- js/render.js | 24 ++++++++++----------- js/save-state.js | 2 +- js/update.js | 42 ++++++++++++++++++------------------- js/wavegen.js | 12 +++++------ 11 files changed, 91 insertions(+), 91 deletions(-) rename js/{Clock.js => Hex.js} (97%) diff --git a/index.html b/index.html index b00926f..a91864f 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@ - + diff --git a/js/Block.js b/js/Block.js index e382dc6..d12a06c 100644 --- a/js/Block.js +++ b/js/Block.js @@ -22,7 +22,7 @@ function Block(fallingLane, color, iter, distFromHex, settled) { this.opacity = 1; //boolean for when the block is expanding this.initializing = 1; - this.ict = MainClock.ct; + this.ict = MainHex.ct; //speed of block this.iter = iter; //number of iterations before starting to drop @@ -36,14 +36,14 @@ function Block(fallingLane, color, iter, distFromHex, settled) { if (this.deleted) { //add shakes if (this.opacity >= 0.925) { - var tLane = this.attachedLane - MainClock.position; - tLane = MainClock.sides - tLane; + var tLane = this.attachedLane - MainHex.position; + tLane = MainHex.sides - tLane; while (tLane < 0) { - tLane += MainClock.sides; + tLane += MainHex.sides; } - tLane %= MainClock.sides; - MainClock.shakes.push({lane:tLane, magnitude:3 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); + 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; @@ -60,7 +60,7 @@ function Block(fallingLane, color, iter, distFromHex, settled) { this.getIndex = function (){ //get the index of the block in its stack - var parentArr = MainClock.blocks[this.attachedLane]; + var parentArr = MainHex.blocks[this.attachedLane]; for (var i = 0; i < parentArr.length; i++) { if (parentArr[i] == this) { return i; @@ -100,12 +100,12 @@ function Block(fallingLane, color, iter, distFromHex, settled) { var p3; var p4; if (this.initializing) { - var rat = ((MainClock.ct - this.ict)/this.initLen); + var rat = ((MainHex.ct - this.ict)/this.initLen); 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 ((MainClock.ct - this.ict) == this.initLen) { + if ((MainHex.ct - this.ict) == this.initLen) { this.initializing = 0; } } else { diff --git a/js/Clock.js b/js/Hex.js similarity index 97% rename from js/Clock.js rename to js/Hex.js index 47dc220..3fe634b 100644 --- a/js/Clock.js +++ b/js/Hex.js @@ -1,4 +1,4 @@ -function Clock(sideLength) { +function Hex(sideLength) { this.playThrough = 0; this.fillColor = [44,62,80]; this.tempColor = [44,62,80]; @@ -49,7 +49,7 @@ function Clock(sideLength) { 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 = MainClock.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; + 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; diff --git a/js/checking.js b/js/checking.js index f5d2b73..ed0822a 100644 --- a/js/checking.js +++ b/js/checking.js @@ -65,7 +65,7 @@ function consolidateBlocks(clock,side,index){ } } // add scores - var now = MainClock.ct; + var now = MainHex.ct; if(now - clock.lastCombo < 240 ){ clock.comboMultiplier += 1; clock.lastCombo = now; diff --git a/js/comboTimer.js b/js/comboTimer.js index 627c331..1b4a433 100644 --- a/js/comboTimer.js +++ b/js/comboTimer.js @@ -1,7 +1,7 @@ function drawTimer(){ - if(MainClock.ct - MainClock.lastCombo < settings.comboMultiplier){ + if(MainHex.ct - MainHex.lastCombo < settings.comboMultiplier){ for(var i=0;i<6;i++){ - var done = (MainClock.ct -MainClock.lastCombo); + var done = (MainHex.ct -MainHex.lastCombo); if(done<(settings.comboMultiplier)*(5-i)*(1/6)){ drawSide(i,i+1,1,1); drawSide(12-i,11-i,1,1); @@ -22,9 +22,9 @@ function drawSide(startVertex,endVertex,fraction,offset){ ctx.beginPath(); ctx.lineCap = "round"; if (gameState === 0) { - ctx.strokeStyle = hexColorsToTintedColors[MainClock.lastColorScored]; + ctx.strokeStyle = hexColorsToTintedColors[MainHex.lastColorScored]; } else { - ctx.strokeStyle = MainClock.lastColorScored; + ctx.strokeStyle = MainHex.lastColorScored; } ctx.lineWidth =4; var radius = (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth + 2; diff --git a/js/input.js b/js/input.js index 0d32ebf..ce98d0c 100644 --- a/js/input.js +++ b/js/input.js @@ -1,8 +1,8 @@ keypress.register_combo({ keys: "left", on_keydown: function() { - if (MainClock && gameState !== 0) { - MainClock.rotate(1); + if (MainHex && gameState !== 0) { + MainHex.rotate(1); } } }); @@ -10,8 +10,8 @@ keypress.register_combo({ keypress.register_combo({ keys: "right", on_keydown: function() { - if (MainClock && gameState !== 0){ - MainClock.rotate(-1); + if (MainHex && gameState !== 0){ + MainHex.rotate(-1); } } }); @@ -20,8 +20,8 @@ keypress.register_combo({ keypress.register_combo({ keys: "a", on_keydown: function() { - if (MainClock && gameState !== 0) { - MainClock.rotate(1); + if (MainHex && gameState !== 0) { + MainHex.rotate(1); } } }); @@ -29,8 +29,8 @@ keypress.register_combo({ keypress.register_combo({ keys: "d", on_keydown: function() { - if (MainClock && gameState !== 0){ - MainClock.rotate(-1); + if (MainHex && gameState !== 0){ + MainHex.rotate(-1); } } }); @@ -108,7 +108,7 @@ $(document).ready(function(){ }, false); function handleClickTap(x) { - if (!MainClock || gameState === 0 || gameState==2 || gameState==-1) { + if (!MainHex || gameState === 0 || gameState==2 || gameState==-1) { return; } @@ -121,7 +121,7 @@ function handleClickTap(x) { init(1); } } - MainClock.rotate(1); + MainHex.rotate(1); } if (x > window.innerWidth/2) { if (gameState != 1 && gameState != -2 && gameState != -1) { @@ -132,6 +132,6 @@ function handleClickTap(x) { init(1); } } - MainClock.rotate(-1); + MainHex.rotate(-1); } } diff --git a/js/main.js b/js/main.js index c54efc5..14f074c 100644 --- a/js/main.js +++ b/js/main.js @@ -10,13 +10,13 @@ $(document).ready(function(){ } setTimeout(function(){ - document.body.addEventListener('mousedown', function(e) { - handleClickTap(e.clientX); - }, false); - document.body.addEventListener('touchstart', function(e) { - handleClickTap(e.changedTouches[0].clientX); - }, false); + document.body.addEventListener('touchstart', function(e) { + handleClickTap(e.changedTouches[0].clientX); + }, false); + //document.body.addEventListener('mousedown', function(e) { + //handleClickTap(e.clientX); + //}, false); }, 1); }); }); @@ -128,7 +128,7 @@ if(localStorage.getItem('highscores')) localStorage.setItem('highscores', highscores); var blocks = []; -var MainClock; +var MainHex; var gdx = 0; var gdy = 0; @@ -185,11 +185,11 @@ function init(b) { scaleCanvas(); settings.blockHeight = settings.baseBlockHeight * settings.scale; settings.hexWidth = settings.baseHexWidth * settings.scale; - MainClock = saveState.clock || new Clock(settings.hexWidth); + MainHex = saveState.clock || new Hex(settings.hexWidth); if (saveState.clock) { - MainClock.playThrough += 1; + MainHex.playThrough += 1; } - MainClock.sideLength = settings.hexWidth; + MainHex.sideLength = settings.hexWidth; count = 0; var i; @@ -214,14 +214,14 @@ function init(b) { gdy = saveState.gdy || 0; comboMultiplier = saveState.comboMultiplier || 0; - for(i=0; i 350) { - ctx.globalAlpha = (50 - (MainClock.ct - 350))/50; + if (MainHex.ct < 400 && (gameState != 0) && !MainHex.playThrough) { + if (MainHex.ct > 350) { + ctx.globalAlpha = (50 - (MainHex.ct - 350))/50; } - if (MainClock.ct < 50) { - ctx.globalAlpha = (MainClock.ct)/50; + if (MainHex.ct < 50) { + ctx.globalAlpha = (MainHex.ct)/50; } renderText((trueCanvas.width)/2 + 1.5 * settings.scale, (trueCanvas.height)/2 - 208 * settings.scale, 35, '#2c3e50', 'Controls', '35px Roboto'); diff --git a/js/save-state.js b/js/save-state.js index e6a9535..9a831a2 100644 --- a/js/save-state.js +++ b/js/save-state.js @@ -3,7 +3,7 @@ function exportSaveState() { if(gameState == 1 || gameState == -1 || (gameState === 0 && localStorage.getItem('saveState') !== undefined)) { state = { - clock: $.extend(true, {}, MainClock), + clock: $.extend(true, {}, MainHex), blocks: $.extend(true, [], blocks), score: score, wavegen: waveone, diff --git a/js/update.js b/js/update.js index ba9b704..5b2ff25 100644 --- a/js/update.js +++ b/js/update.js @@ -8,7 +8,7 @@ function update() { } if (importedHistory[count].rotate) { - MainClock.rotate(importedHistory[count].rotate); + MainHex.rotate(importedHistory[count].rotate); } } } @@ -25,7 +25,7 @@ function update() { var objectsToRemove = []; for (i = 0; i < blocks.length; i++) { - MainClock.doesBlockCollide(blocks[i]); + MainHex.doesBlockCollide(blocks[i]); if (!blocks[i].settled) { if (!blocks[i].initializing) blocks[i].distFromHex -= blocks[i].iter * settings.scale; } else if (!blocks[i].removed) { @@ -33,41 +33,41 @@ function update() { } } - for (i = 0; i < MainClock.blocks.length; i++) { - for (j = 0; j < MainClock.blocks[i].length; j++) { - if (MainClock.blocks[i][j].checked ==1 ) { - consolidateBlocks(MainClock,MainClock.blocks[i][j].attachedLane,MainClock.blocks[i][j].getIndex()); - MainClock.blocks[i][j].checked=0; + 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 < MainClock.blocks.length; i++) { + for (i = 0; i < MainHex.blocks.length; i++) { lowestDeletedIndex = 99; - for (j = 0; j < MainClock.blocks[i].length; j++) { - block = MainClock.blocks[i][j]; + for (j = 0; j < MainHex.blocks[i].length; j++) { + block = MainHex.blocks[i][j]; if (block.deleted == 2) { - MainClock.blocks[i].splice(j,1); + MainHex.blocks[i].splice(j,1); blockDestroyed(); if (j < lowestDeletedIndex) lowestDeletedIndex = j; j--; } } - if (lowestDeletedIndex < MainClock.blocks[i].length) { - for (j = lowestDeletedIndex; j < MainClock.blocks[i].length; j++) { - MainClock.blocks[i][j].settled = 0; + 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 < MainClock.blocks.length; i++) { - for (j = 0; j < MainClock.blocks[i].length; j++) { - block = MainClock.blocks[i][j]; - MainClock.doesBlockCollide(block, j, MainClock.blocks[i]); + 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 (!MainClock.blocks[i][j].settled) { - MainClock.blocks[i][j].distFromHex -= block.iter * settings.scale; + if (!MainHex.blocks[i][j].settled) { + MainHex.blocks[i][j].distFromHex -= block.iter * settings.scale; } } } @@ -78,6 +78,6 @@ function update() { i--; } } - MainClock.ct++; + MainHex.ct++; count++; } diff --git a/js/wavegen.js b/js/wavegen.js index dee4467..6e67e1b 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -37,7 +37,7 @@ function waveGen(clock) { if (this.dt - this.lastGen > this.nextGen) { this.ct++; this.lastGen = this.dt; - var fv = randInt(0, MainClock.sides); + var fv = randInt(0, MainHex.sides); addNewBlock(fv, colors[randInt(0, colors.length)], 1.6 + (this.difficulty/15) * 3); if (this.ct > 7) { var nextPattern = randInt(0, 20 + 4); @@ -91,7 +91,7 @@ function waveGen(clock) { colorList.push(colors[q]); } - for (var i = 0; i < MainClock.sides; i++) { + for (var i = 0; i < MainHex.sides; i++) { addNewBlock(i, colorList[i % numColors], 1.5 + (this.difficulty/15) * 3); } @@ -106,7 +106,7 @@ function waveGen(clock) { 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) % MainClock.sides, 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(); @@ -117,10 +117,10 @@ function waveGen(clock) { var dir = randInt(0, 2); if (this.dt - this.lastGen > this.nextGen * (5/9)) { if (dir) { - addNewBlock(5 - (this.ct % MainClock.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * (3/2)); + addNewBlock(5 - (this.ct % MainHex.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * (3/2)); } else { - addNewBlock(this.ct % MainClock.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * (3/2)); + addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * (3/2)); } this.ct += 1; this.lastGen = this.dt; @@ -132,7 +132,7 @@ function waveGen(clock) { 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) % MainClock.sides, 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();