renamed to v7
This commit is contained in:
parent
0524e9ec75
commit
f59e32ec25
14 changed files with 0 additions and 2035 deletions
198
js_v6/Block.js
198
js_v6/Block.js
|
@ -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
|
||||
};
|
||||
}
|
170
js_v6/Hex.js
170
js_v6/Hex.js
|
@ -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]+')';
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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<twoD.length;i++){
|
||||
if(twoD[i][0] == oneD[0] && twoD[i][1] == oneD[1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 = 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+hex.sides)%hex.sides;
|
||||
//calculate the index
|
||||
var curIndex = index+y;
|
||||
//making sure the block exists at this side and index
|
||||
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(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(hex,curSide,curIndex,deleting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function consolidateBlocks(hex,side,index){
|
||||
//record which sides have been changed
|
||||
var sidesChanged =[];
|
||||
var deleting=[];
|
||||
var deletedBlocks = [];
|
||||
//add start case
|
||||
deleting.push([side,index]);
|
||||
//fill deleting
|
||||
floodFill(hex,side,index,deleting);
|
||||
//make sure there are more than 3 blocks to be deleted
|
||||
if(deleting.length<3){return;}
|
||||
var i;
|
||||
for(i=0; i<deleting.length;i++) {
|
||||
var arr = deleting[i];
|
||||
//just making sure the arrays are as they should be
|
||||
if(arr !== undefined && arr.length==2) {
|
||||
//add to sides changed if not in there
|
||||
if(sidesChanged.indexOf(arr[0])==-1){
|
||||
sidesChanged.push(arr[0]);
|
||||
}
|
||||
//mark as deleted
|
||||
hex.blocks[arr[0]][arr[1]].deleted = 1;
|
||||
deletedBlocks.push(hex.blocks[arr[0]][arr[1]]);
|
||||
}
|
||||
}
|
||||
|
||||
// add scores
|
||||
var now = MainHex.ct;
|
||||
if(now - hex.lastCombo < settings.comboTime ){
|
||||
settings.comboTime = (1/settings.creationSpeedModifier) * (waveone.nextGen/16.666667) * 3;
|
||||
hex.comboMultiplier += 1;
|
||||
hex.lastCombo = now;
|
||||
var coords = findCenterOfBlocks(deletedBlocks);
|
||||
hex.texts.push(new Text(coords['x'],coords['y'],"x "+hex.comboMultiplier.toString(),"bold Q","#fff",fadeUpAndOut));
|
||||
}
|
||||
else{
|
||||
settings.comboTime = 240;
|
||||
hex.lastCombo = now;
|
||||
hex.comboMultiplier = 1;
|
||||
}
|
||||
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;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
function drawTimer() {
|
||||
if(gameState==1){
|
||||
var leftVertexes = [];
|
||||
var rightVertexes = [];
|
||||
if(MainHex.ct - MainHex.lastCombo < settings.comboTime){
|
||||
for(var i=0;i<6;i++){
|
||||
var done = (MainHex.ct -MainHex.lastCombo);
|
||||
if(done<(settings.comboTime)*(5-i)*(1/6)){
|
||||
leftVertexes.push(calcSide(i,i+1,1,1));
|
||||
rightVertexes.push(calcSide(12-i,11-i,1,1));
|
||||
}
|
||||
else{
|
||||
leftVertexes.push(calcSide(i,i+1,1-((done*6)/settings.comboTime)%(1),1));
|
||||
rightVertexes.push(calcSide(12-i,11-i,1-((done*6)/settings.comboTime)%(1),1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(rightVertexes.length !== 0) drawSide(rightVertexes);
|
||||
if(leftVertexes.length !== 0) drawSide(leftVertexes);
|
||||
}
|
||||
}
|
||||
|
||||
function calcSide(startVertex,endVertex,fraction,offset){
|
||||
startVertex = (startVertex+offset)%12;
|
||||
endVertex = (endVertex+offset)%12;
|
||||
ctx.globalAlpha=1;
|
||||
ctx.beginPath();
|
||||
ctx.lineCap = "round";
|
||||
|
||||
var radius = (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth ;
|
||||
var halfRadius = radius/2;
|
||||
var triHeight = radius *(Math.sqrt(3)/2);
|
||||
var Vertexes =[
|
||||
[(halfRadius*3)/2,triHeight/2],
|
||||
[radius,0],
|
||||
[(halfRadius*3)/2,-triHeight/2],
|
||||
[halfRadius,-triHeight],
|
||||
[0,-triHeight],
|
||||
[-halfRadius,-triHeight],
|
||||
[-(halfRadius*3)/2,-triHeight/2],
|
||||
[-radius,0],
|
||||
[-(halfRadius*3)/2,triHeight/2],
|
||||
[-halfRadius,triHeight],
|
||||
[0,triHeight],
|
||||
[halfRadius,triHeight]
|
||||
].reverse();
|
||||
var startX =trueCanvas.width/2 + Vertexes[startVertex][0];
|
||||
var startY =trueCanvas.height/2 + Vertexes[startVertex][1];
|
||||
var endX = trueCanvas.width/2 + Vertexes[endVertex][0];
|
||||
var endY = trueCanvas.height/2 + Vertexes[endVertex][1];
|
||||
return [[startX,startY],[((endX-startX)*fraction)+startX,((endY-startY)*fraction)+startY]];
|
||||
}
|
||||
function drawSide(vertexes){
|
||||
if (gameState === 0) {
|
||||
ctx.strokeStyle = hexColorsToTintedColors[MainHex.lastColorScored];
|
||||
} else {
|
||||
ctx.strokeStyle = MainHex.lastColorScored;
|
||||
}
|
||||
ctx.lineWidth =4*settings.scale;
|
||||
ctx.moveTo(vertexes[0][0][0],vertexes[0][0][1]);
|
||||
ctx.lineTo(vertexes[0][1][0],vertexes[0][1][1]);
|
||||
for(var i=1;i<vertexes.length;i++){
|
||||
ctx.lineTo(vertexes[i][1][0],vertexes[i][1][1]);
|
||||
ctx.moveTo(vertexes[i][1][0],vertexes[i][1][1]);
|
||||
}
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
|
||||
}
|
|
@ -1,315 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
initialize();
|
||||
$('#bottombar').hide();
|
||||
});
|
||||
|
||||
function showbottombar() {
|
||||
var isOffline = 'onLine' in navigator && !navigator.onLine;
|
||||
if (isOffline) {
|
||||
setTimeout(showbottombar, 1000);
|
||||
} else {
|
||||
window.iframeHasLoaded = true;
|
||||
if (gameState != 1) {
|
||||
$('#bottombar').fadeIn(150, 'linear');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hidebottombar() {
|
||||
$('#bottombar').fadeOut(150, 'linear');
|
||||
}
|
||||
|
||||
function initialize(a) {
|
||||
window.lastTime = Date.now();
|
||||
window.iframHasLoaded = false;
|
||||
window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
|
||||
window.hexColorsToTintedColors = {
|
||||
"#e74c3c": "rgb(241,163,155)",
|
||||
"#f1c40f": "rgb(246,223,133)",
|
||||
"#3498db": "rgb(151,201,235)",
|
||||
"#2ecc71": "rgb(150,227,183)"
|
||||
};
|
||||
|
||||
window.rgbToHex = {
|
||||
"rgb(231,76,60)": "#e74c3c",
|
||||
"rgb(241,196,15)": "#f1c40f",
|
||||
"rgb(52,152,219)": "#3498db",
|
||||
"rgb(46,204,113)": "#2ecc71"
|
||||
};
|
||||
|
||||
window.rgbColorsToTintedColors = {
|
||||
"rgb(231,76,60)": "rgb(241,163,155)",
|
||||
"rgb(241,196,15)": "rgb(246,223,133)",
|
||||
"rgb(52,152,219)": "rgb(151,201,235)",
|
||||
"rgb(46,204,113)": "rgb(150,227,183)"
|
||||
};
|
||||
|
||||
window.hexagonBackgroundColor = 'rgb(236, 240, 241)';
|
||||
window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';
|
||||
window.centerBlue = 'rgb(44,62,80)';
|
||||
window.angularVelocityConst = 4;
|
||||
window.scoreOpacity = 0;
|
||||
window.textOpacity = 0;
|
||||
window.prevGameState = undefined;
|
||||
|
||||
//render.js
|
||||
window.op = 0;
|
||||
window.saveState = localStorage.getItem("saveState") || "{}";
|
||||
if (saveState !== "{}") {
|
||||
op = 1;
|
||||
}
|
||||
|
||||
//input.js
|
||||
//all of main.js
|
||||
|
||||
//main.js
|
||||
window.textShown = false;
|
||||
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
|
||||
window.setTimeout(callback, 1000 / framerate);
|
||||
};
|
||||
})();
|
||||
|
||||
$('#clickToExit').bind('click', toggleDevTools);
|
||||
window.settings;
|
||||
|
||||
if (/Mobile|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
||||
settings = {
|
||||
platform: "mobile",
|
||||
startDist: 227,
|
||||
creationDt: 40,
|
||||
baseScale: 1.4,
|
||||
scale: 1,
|
||||
prevScale: 1,
|
||||
baseHexWidth: 87,
|
||||
hexWidth: 87,
|
||||
baseBlockHeight: 20,
|
||||
blockHeight: 20,
|
||||
rows: 7,
|
||||
speedModifier: 0.73,
|
||||
creationSpeedModifier: 0.73,
|
||||
comboTime: 240
|
||||
};
|
||||
} else {
|
||||
settings = {
|
||||
platform: "nonmobile",
|
||||
baseScale: 1,
|
||||
startDist: 340,
|
||||
creationDt: 9,
|
||||
scale: 1,
|
||||
prevScale: 1,
|
||||
hexWidth: 65,
|
||||
baseHexWidth: 87,
|
||||
baseBlockHeight: 20,
|
||||
blockHeight: 15,
|
||||
rows: 8,
|
||||
speedModifier: 0.65,
|
||||
creationSpeedModifier: 0.65,
|
||||
comboTime: 240
|
||||
};
|
||||
|
||||
$("#inst_main_body").html("The goal of Hextris is to stop blocks from leaving the inside of the outer gray hexagon<br><br>Either press the right and left arrow keys or tap the left and right sides of the screen to rotate the Hexagon<br><br>Clear blocks by making 3 or more blocks of the same color touch<br><br>Get points by clearing blocks<br><br>Time left before your combo streak disappears is indicated shown by <span style='color:#f1c40f;'>the</span> <span style='color:#e74c3c'>colored<span> <span style='color:#3498db'>lines</span> <span style='color:#2ecc71'>in</span> the outer hexagon<br><br>Pause by pressing <i class = 'fa fa-pause'></i> or the letter <b>p</b><br>Restart by pressing <i class = 'fa fa-refresh'></i> or <b>enter</b><br>Bring up this menu by pressing <i class = 'fa fa-info-circle'><br><br><a href = 'https://github.com/Hextris/hextris/issues'>Found a bug? Go here</a");
|
||||
}
|
||||
|
||||
window.canvas = document.getElementById('canvas');
|
||||
window.ctx = canvas.getContext('2d');
|
||||
window.trueCanvas = {
|
||||
width: canvas.width,
|
||||
height: canvas.height
|
||||
};
|
||||
scaleCanvas();
|
||||
|
||||
window.framerate = 60;
|
||||
window.history = {};
|
||||
window.score = 0;
|
||||
window.isGameOver = 3;
|
||||
window.scoreAdditionCoeff = 1;
|
||||
window.prevScore = 0;
|
||||
window.numHighScores = 3;
|
||||
|
||||
highscores = [];
|
||||
if (localStorage.getItem('highscores')) {
|
||||
try {
|
||||
highscores = JSON.parse(localStorage.getItem('highscores'));
|
||||
} catch (e) {
|
||||
highscores = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.blocks = [];
|
||||
window.MainHex;
|
||||
|
||||
window.gdx = 0;
|
||||
window.gdy = 0;
|
||||
|
||||
window.devMode = 0;
|
||||
window.lastGen = undefined;
|
||||
window.prevTimeScored = undefined;
|
||||
window.nextGen = undefined;
|
||||
window.spawnLane = 0;
|
||||
window.importing = 0;
|
||||
window.importedHistory = undefined;
|
||||
window.startTime = undefined;
|
||||
|
||||
window.gameState;
|
||||
setStartScreen();
|
||||
|
||||
if (a != 1) {
|
||||
window.canRestart = 1;
|
||||
window.onblur = function(e) {
|
||||
if (gameState == 1) {
|
||||
pause();
|
||||
}
|
||||
};
|
||||
|
||||
$('#startBtn').off();
|
||||
|
||||
if (settings.platform == 'mobile') {
|
||||
$('#startBtn').on('touchstart', startBtnHandler);
|
||||
} else {
|
||||
$('#startBtn').on('mousedown', startBtnHandler);
|
||||
}
|
||||
|
||||
document.addEventListener('touchmove', function(e) {
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
$(window).resize(scaleCanvas);
|
||||
$(window).unload(function() {
|
||||
|
||||
if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState());
|
||||
else localStorage.setItem("saveState", "{}");
|
||||
});
|
||||
|
||||
addKeyListeners();
|
||||
(function(i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r;
|
||||
i[r] = i[r] || function() {
|
||||
(i[r].q = i[r].q || []).push(arguments)
|
||||
}, i[r].l = 1 * new Date();
|
||||
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
|
||||
a.async = 1;
|
||||
a.src = g;
|
||||
m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
||||
ga('create', 'UA-51272720-1', 'teamsnowman.github.io');
|
||||
ga('send', 'pageview');
|
||||
|
||||
document.addEventListener("pause", handlePause, false);
|
||||
document.addEventListener("backbutton", handlePause, false);
|
||||
document.addEventListener("menubutton", handlePause, false); //menu button on android
|
||||
|
||||
setTimeout(function() {
|
||||
if (settings.platform == "mobile") {
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTapBefore, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTap, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
document.body.addEventListener('touchstart', handleTapBefore, false);
|
||||
} else {
|
||||
try {
|
||||
document.body.removeEventListener('mousedown', handleClickBefore, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
document.body.removeEventListener('mousedown', handleClick, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
document.body.addEventListener('mousedown', handleClickBefore, false);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function startBtnHandler() {
|
||||
setTimeout(function() {
|
||||
if (settings.platform == "mobile") {
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTapBefore, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTap, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
document.body.addEventListener('touchstart', handleTap, false);
|
||||
} else {
|
||||
try {
|
||||
document.body.removeEventListener('mousedown', handleClickBefore, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
document.body.removeEventListener('mousedown', handleClick, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
document.body.addEventListener('mousedown', handleClick, false);
|
||||
}
|
||||
}, 5);
|
||||
|
||||
if (!canRestart) return false;
|
||||
|
||||
if ($('#helpScreen').is(':visible')) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
|
||||
if (importing == 1) {
|
||||
init(1);
|
||||
} else {
|
||||
resumeGame();
|
||||
}
|
||||
}
|
||||
|
||||
function handlePause() {
|
||||
if (gameState == 1 || gameState == 2) {
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
function handleTap(e) {
|
||||
handleClickTap(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
|
||||
}
|
||||
|
||||
function handleClick(e) {
|
||||
handleClickTap(e.clientX, e.clientY);
|
||||
}
|
||||
|
||||
function handleTapBefore(e) {
|
||||
var x = e.changedTouches[0].clientX;
|
||||
var y = e.changedTouches[0].clientY;
|
||||
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClickBefore(e) {
|
||||
var x = e.clientX;
|
||||
var y = e.clientY;
|
||||
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
}
|
168
js_v6/input.js
168
js_v6/input.js
|
@ -1,168 +0,0 @@
|
|||
function addKeyListeners() {
|
||||
keypress.register_combo({
|
||||
keys: "left",
|
||||
on_keydown: function() {
|
||||
if (MainHex && gameState !== 0) {
|
||||
MainHex.rotate(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "right",
|
||||
on_keydown: function() {
|
||||
if (MainHex && gameState !== 0){
|
||||
MainHex.rotate(-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "a",
|
||||
on_keydown: function() {
|
||||
if (MainHex && gameState !== 0) {
|
||||
MainHex.rotate(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "d",
|
||||
on_keydown: function() {
|
||||
if (MainHex && gameState !== 0){
|
||||
MainHex.rotate(-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "p",
|
||||
on_keydown: function(){pause();}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "space",
|
||||
on_keydown: function(){pause();}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "q",
|
||||
on_keydown: function() {
|
||||
if (devMode) toggleDevTools();
|
||||
}
|
||||
});
|
||||
|
||||
keypress.register_combo({
|
||||
keys: "enter",
|
||||
on_keydown: function() {
|
||||
if (gameState==2 || gameState==1 || importing == 1) {
|
||||
init(1);
|
||||
}
|
||||
if (gameState===0) {
|
||||
resumeGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#pauseBtn").on('touchstart mousedown', function() {
|
||||
if (gameState != 1 && gameState != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($('#helpScreen').is(":visible")) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
|
||||
pause();
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#colorBlindBtn").on('touchstart mousedown', function() {
|
||||
window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"];
|
||||
|
||||
window.hexColorsToTintedColors = {
|
||||
"#8e44ad": "rgb(229,152,102)",
|
||||
"#f1c40f": "rgb(246,223,133)",
|
||||
"#3498db": "rgb(151,201,235)",
|
||||
"#d35400": "rgb(210,180,222)"
|
||||
};
|
||||
|
||||
window.rgbToHex = {
|
||||
"rgb(142,68,173)": "#8e44ad",
|
||||
"rgb(241,196,15)": "#f1c40f",
|
||||
"rgb(52,152,219)": "#3498db",
|
||||
"rgb(211,84,0)": "#d35400"
|
||||
};
|
||||
|
||||
window.rgbColorsToTintedColors = {
|
||||
"rgb(142,68,173)": "rgb(229,152,102)",
|
||||
"rgb(241,196,15)": "rgb(246,223,133)",
|
||||
"rgb(52,152,219)": "rgb(151,201,235)",
|
||||
"rgb(46,204,113)": "rgb(210,180,222)"
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
||||
$("#restartBtn").on('touchstart', function() {
|
||||
init(1);
|
||||
canRestart = false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
$("#restartBtn").on('mousedown', function() {
|
||||
init(1);
|
||||
canRestart = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleClickTap(x,y) {
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameState == 2 && canRestart) {
|
||||
setTimeout(function(){
|
||||
if(tweetblock) {
|
||||
tweetblock = false;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
init(1);
|
||||
}
|
||||
return;
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MainHex || gameState === 0 || gameState==-1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < window.innerWidth/2) {
|
||||
if (gameState != 1 && gameState != -2 && gameState != -1 ){
|
||||
if (importing === 0) {
|
||||
resumeGame();
|
||||
}
|
||||
else {
|
||||
init(1);
|
||||
}
|
||||
}
|
||||
|
||||
MainHex.rotate(1);
|
||||
}
|
||||
if (x > window.innerWidth/2) {
|
||||
if (gameState != 1 && gameState != -2 && gameState != -1) {
|
||||
if (importing === 0) {
|
||||
resumeGame();
|
||||
}
|
||||
else {
|
||||
init(1);
|
||||
}
|
||||
}
|
||||
MainHex.rotate(-1);
|
||||
}
|
||||
}
|
327
js_v6/main.js
327
js_v6/main.js
|
@ -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('<i class="fa fa-pause fa-2x"></i>');
|
||||
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");
|
||||
}
|
|
@ -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);
|
||||
}
|
113
js_v6/render.js
113
js_v6/render.js
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
211
js_v6/view.js
211
js_v6/view.js
|
@ -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': "<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press p to resume</div><div style='height:100px;line-height:100px;cursor:pointer;'></div>",
|
||||
'pausedMobile': "<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press <i class='fa fa-play'></i> to resume</div><div style='height:100px;line-height:100px;cursor:pointer;'></div>",
|
||||
'start': "<div class='centeredHeader unselectable' style='line-height:80px;'>Press enter to start</div>",
|
||||
'gameover': "<div class='centeredHeader unselectable'> Game Over: " + score + " pts</div><br><div style='font-size:24px;' class='centeredHeader unselectable'> High Scores:</div><table class='tg' style='margin:0px auto'> "
|
||||
|
||||
};
|
||||
|
||||
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'] += "<tr> <th class='tg-031e'>" + (i + 1) + ".</th> <th class='tg-031e'>" + highscores[i] + " pts</th> </tr>";
|
||||
}
|
||||
}
|
||||
|
||||
var restartText;
|
||||
if (settings.platform == 'mobile') {
|
||||
restartText = 'Tap anywhere to restart!';
|
||||
} else {
|
||||
restartText = 'Press enter (or click anywhere!) to restart!';
|
||||
}
|
||||
|
||||
messages['gameover'] += "</table><br><div class='unselectable centeredSubHeader'>" + restartText + "</div>";
|
||||
|
||||
if (allZ) {
|
||||
for (i = 0; i < highscores.length; i++) {
|
||||
if (highscores[i] !== 0) {
|
||||
allZ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
messages['gameover'] += "<div class='fltrt' id='tweetStuff'><a class='tweet' href='https://twitter.com/intent/tweet?text=Can you beat my score of "+ score +" points at&button_hashtag=hextris ? http://hextris.github.io/hextris' data-lang='en' data-related='hextris:hextris'>Share Your Score on Twitter!!!</a></div>"
|
||||
$("#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('<i class="fa fa-pause fa-2x"></i>');
|
||||
} else {
|
||||
$("#pauseBtnInner").html('<i class="fa fa-play fa-2x"></i>');
|
||||
}
|
||||
}
|
||||
|
||||
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('<i class="fa fa-pause fa-2x"></i>');
|
||||
$('.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('<i class="fa fa-play fa-2x"></i>');
|
||||
prevGameState = gameState;
|
||||
gameState = -1;
|
||||
}
|
||||
}
|
198
js_v6/wavegen.js
198
js_v6/wavegen.js
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue