clock to hex
This commit is contained in:
parent
f27cb24988
commit
be3706a346
5 changed files with 38 additions and 38 deletions
10
js/Block.js
10
js/Block.js
|
@ -1,5 +1,5 @@
|
|||
function Block(fallingLane, color, iter, distFromHex, settled) {
|
||||
// whether or not a block is rested on the center clock or another block
|
||||
// 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
|
||||
|
@ -8,15 +8,15 @@ function Block(fallingLane, color, iter, distFromHex, settled) {
|
|||
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 clock
|
||||
//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 clock
|
||||
//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 clock
|
||||
//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;
|
||||
|
@ -29,7 +29,7 @@ function Block(fallingLane, color, iter, distFromHex, settled) {
|
|||
this.initLen = settings.creationDt;
|
||||
//side which block is attached too
|
||||
this.attachedLane = 0;
|
||||
//distance from center clock
|
||||
//distance from center hex
|
||||
this.distFromHex = distFromHex || settings.startDist * settings.scale ;
|
||||
|
||||
this.incrementOpacity = function() {
|
||||
|
|
|
@ -7,39 +7,39 @@ function search(twoD,oneD){
|
|||
}
|
||||
return false;
|
||||
}
|
||||
function floodFill(clock, side, index, deleting) {
|
||||
if (clock.blocks[side] === undefined || clock.blocks[side][index] === undefined) {
|
||||
function floodFill(hex, side, index, deleting) {
|
||||
if (hex.blocks[side] === undefined || hex.blocks[side][index] === undefined) {
|
||||
//just makin sure stuff exists
|
||||
return;
|
||||
}
|
||||
|
||||
//store the color
|
||||
var color = clock.blocks[side][index].color;
|
||||
var color = hex.blocks[side][index].color;
|
||||
//nested for loops for navigating the blocks
|
||||
for(var x =-1;x<2;x++){
|
||||
for(var y =-1;y<2;y++){
|
||||
//make sure the they aren't diagonals
|
||||
if(Math.abs(x)==Math.abs(y)){continue;}
|
||||
//calculate the side were exploring using mods
|
||||
var curSide =(side+x+clock.sides)%clock.sides;
|
||||
var curSide =(side+x+hex.sides)%hex.sides;
|
||||
//calculate the index
|
||||
var curIndex = index+y;
|
||||
//making sure the block exists at this side and index
|
||||
if(clock.blocks[curSide] === undefined){continue;}
|
||||
if(clock.blocks[curSide][curIndex] !== undefined){
|
||||
if(hex.blocks[curSide] === undefined){continue;}
|
||||
if(hex.blocks[curSide][curIndex] !== undefined){
|
||||
// checking equivalency of color, if its already been explored, and if it isn't already deleted
|
||||
if(clock.blocks[curSide][curIndex].color == color && search(deleting,[curSide,curIndex]) === false && clock.blocks[curSide][curIndex].deleted == 0 ) {
|
||||
if(hex.blocks[curSide][curIndex].color == color && search(deleting,[curSide,curIndex]) === false && hex.blocks[curSide][curIndex].deleted == 0 ) {
|
||||
//add this to the array of already explored
|
||||
deleting.push([curSide,curIndex]);
|
||||
//recall with next block explored
|
||||
floodFill(clock,curSide,curIndex,deleting);
|
||||
floodFill(hex,curSide,curIndex,deleting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function consolidateBlocks(clock,side,index){
|
||||
function consolidateBlocks(hex,side,index){
|
||||
//record which sides have been changed
|
||||
var sidesChanged =[];
|
||||
var deleting=[];
|
||||
|
@ -47,7 +47,7 @@ function consolidateBlocks(clock,side,index){
|
|||
//add start case
|
||||
deleting.push([side,index]);
|
||||
//fill deleting
|
||||
floodFill(clock,side,index,deleting);
|
||||
floodFill(hex,side,index,deleting);
|
||||
//make sure there are more than 3 blocks to be deleted
|
||||
if(deleting.length<3){return;}
|
||||
var i;
|
||||
|
@ -60,24 +60,24 @@ function consolidateBlocks(clock,side,index){
|
|||
sidesChanged.push(arr[0]);
|
||||
}
|
||||
//mark as deleted
|
||||
clock.blocks[arr[0]][arr[1]].deleted = 1;
|
||||
deletedBlocks.push(clock.blocks[arr[0]][arr[1]]);
|
||||
hex.blocks[arr[0]][arr[1]].deleted = 1;
|
||||
deletedBlocks.push(hex.blocks[arr[0]][arr[1]]);
|
||||
}
|
||||
}
|
||||
// add scores
|
||||
var now = MainHex.ct;
|
||||
if(now - clock.lastCombo < 240 ){
|
||||
clock.comboMultiplier += 1;
|
||||
clock.lastCombo = now;
|
||||
if(now - hex.lastCombo < 240 ){
|
||||
hex.comboMultiplier += 1;
|
||||
hex.lastCombo = now;
|
||||
var coords = findCenterOfBlocks(deletedBlocks);
|
||||
clock.texts.push(new Text(coords['x'],coords['y'],"x "+clock.comboMultiplier.toString(),"bold Q","#fff",fadeUpAndOut));
|
||||
hex.texts.push(new Text(coords['x'],coords['y'],"x "+hex.comboMultiplier.toString(),"bold Q","#fff",fadeUpAndOut));
|
||||
}
|
||||
else{
|
||||
clock.lastCombo = now;
|
||||
clock.comboMultiplier = 1;
|
||||
hex.lastCombo = now;
|
||||
hex.comboMultiplier = 1;
|
||||
}
|
||||
var adder = deleting.length * deleting.length * clock.comboMultiplier;
|
||||
clock.texts.push(new Text(clock.x,clock.y,"+ "+adder.toString(),"bold Q ",deletedBlocks[0].color,fadeUpAndOut));
|
||||
clock.lastColorScored = deletedBlocks[0].color;
|
||||
var adder = deleting.length * deleting.length * hex.comboMultiplier;
|
||||
hex.texts.push(new Text(hex.x,hex.y,"+ "+adder.toString(),"bold Q ",deletedBlocks[0].color,fadeUpAndOut));
|
||||
hex.lastColorScored = deletedBlocks[0].color;
|
||||
score += adder;
|
||||
}
|
||||
|
|
16
js/main.js
16
js/main.js
|
@ -180,13 +180,13 @@ function init(b) {
|
|||
gameState = 1;
|
||||
$("#restartBtn").show();
|
||||
$("#pauseBtn").show();
|
||||
if(saveState.clock !== undefined) gameState = 1;
|
||||
if(saveState.hex !== undefined) gameState = 1;
|
||||
|
||||
scaleCanvas();
|
||||
settings.blockHeight = settings.baseBlockHeight * settings.scale;
|
||||
settings.hexWidth = settings.baseHexWidth * settings.scale;
|
||||
MainHex = saveState.clock || new Hex(settings.hexWidth);
|
||||
if (saveState.clock) {
|
||||
MainHex = saveState.hex || new Hex(settings.hexWidth);
|
||||
if (saveState.hex) {
|
||||
MainHex.playThrough += 1;
|
||||
}
|
||||
MainHex.sideLength = settings.hexWidth;
|
||||
|
@ -374,13 +374,13 @@ function updateHighScore(){
|
|||
localStorage.setItem('highscores', highscores);
|
||||
|
||||
}
|
||||
function isInfringing(clock){
|
||||
for(var i=0;i<clock.sides;i++){
|
||||
function isInfringing(hex){
|
||||
for(var i=0;i<hex.sides;i++){
|
||||
var subTotal=0;
|
||||
for (var j=0;j<clock.blocks[i].length;j++){
|
||||
subTotal+=clock.blocks[i][j].deleted ;
|
||||
for (var j=0;j<hex.blocks[i].length;j++){
|
||||
subTotal+=hex.blocks[i][j].deleted ;
|
||||
}
|
||||
if (clock.blocks[i].length- subTotal>settings.rows){
|
||||
if (hex.blocks[i].length- subTotal>settings.rows){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ function exportSaveState() {
|
|||
|
||||
if(gameState == 1 || gameState == -1 || (gameState === 0 && localStorage.getItem('saveState') !== undefined)) {
|
||||
state = {
|
||||
clock: $.extend(true, {}, MainHex),
|
||||
hex: $.extend(true, {}, MainHex),
|
||||
blocks: $.extend(true, [], blocks),
|
||||
score: score,
|
||||
wavegen: waveone,
|
||||
|
@ -12,7 +12,7 @@ function exportSaveState() {
|
|||
comboMultiplier:comboMultiplier
|
||||
};
|
||||
|
||||
state.clock.blocks.map(function(a){
|
||||
state.hex.blocks.map(function(a){
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
a[i] = $.extend(true, {}, a[i]);
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ function blockDestroyed() {
|
|||
}
|
||||
}
|
||||
|
||||
function waveGen(clock) {
|
||||
function waveGen(hex) {
|
||||
this.lastGen = 0;
|
||||
this.last = 0;
|
||||
this.nextGen = 2000; // - 1500; //delay before starting
|
||||
this.start = 0;
|
||||
this.colors = colors;
|
||||
this.ct = 0;
|
||||
this.clock = clock;
|
||||
this.hex = hex;
|
||||
this.difficulty = 1;
|
||||
this.dt = 0;
|
||||
this.update = function() {
|
||||
|
|
Loading…
Reference in a new issue