hextris/js/update.js
2014-08-18 20:09:46 -04:00

71 lines
1.8 KiB
JavaScript

//remember to update history function to show the respective iter speeds
function update() {
var now = MainHex.ct;
if (gameState == 1) {
waveone.update();
if (now - waveone.prevTimeScored > 1000) {
waveone.prevTimeScored = now;
}
}
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 * 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 * settings.scale;
}
}
}
for(i = 0; i < blocks.length;i++){
if (blocks[i].removed == 1) {
blocks.splice(i,1);
i--;
}
}
MainHex.ct++;
}