added far higher difficulty cap
This commit is contained in:
parent
3ae8fb1291
commit
1ccccea7ad
3 changed files with 661 additions and 648 deletions
|
@ -1,303 +1,315 @@
|
|||
$(document).ready(function(){
|
||||
initialize();
|
||||
$('#bottombar').hide();
|
||||
$(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');
|
||||
}
|
||||
}
|
||||
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');
|
||||
$('#bottombar').fadeOut(150, 'linear');
|
||||
}
|
||||
|
||||
function initialize(a) {
|
||||
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.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.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.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;
|
||||
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;}
|
||||
//render.js
|
||||
window.op = 0;
|
||||
window.saveState = localStorage.getItem("saveState") || "{}";
|
||||
if (saveState !== "{}") {
|
||||
op = 1;
|
||||
}
|
||||
|
||||
//input.js
|
||||
//all of main.js
|
||||
//input.js
|
||||
//all of main.js
|
||||
|
||||
//main.js
|
||||
window.textShown = false;
|
||||
//main.js
|
||||
window.textShown = false;
|
||||
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
|
||||
window.setTimeout(callback, 1000 / framerate);
|
||||
};
|
||||
})();
|
||||
window.requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
|
||||
window.setTimeout(callback, 1000 / framerate);
|
||||
};
|
||||
})();
|
||||
|
||||
$('#clickToExit').bind('click', toggleDevTools);
|
||||
window.settings;
|
||||
$('#clickToExit').bind('click', toggleDevTools);
|
||||
window.settings;
|
||||
|
||||
if(/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:6,
|
||||
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.62,
|
||||
creationSpeedModifier:0.62,
|
||||
comboTime:240
|
||||
};
|
||||
if (/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.55,
|
||||
creationSpeedModifier: 0.55,
|
||||
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 = 'url'>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();
|
||||
$("#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 = 'url'>Found a bug? Go here</a");
|
||||
}
|
||||
|
||||
window.framerate = 60;
|
||||
window.history = {};
|
||||
window.score = 0;
|
||||
window.isGameOver = 3;
|
||||
window.scoreAdditionCoeff = 1;
|
||||
window.prevScore = 0;
|
||||
window.numHighScores = 3;
|
||||
window.canvas = document.getElementById('canvas');
|
||||
window.ctx = canvas.getContext('2d');
|
||||
window.trueCanvas = {
|
||||
width: canvas.width,
|
||||
height: canvas.height
|
||||
};
|
||||
scaleCanvas();
|
||||
|
||||
window.highscores = [];
|
||||
if(localStorage.getItem('highscores')) {
|
||||
try {
|
||||
highscores = JSON.parse(localStorage.getItem('highscores'));
|
||||
} catch (e) {
|
||||
highscores = [];
|
||||
}
|
||||
}
|
||||
window.framerate = 60;
|
||||
window.history = {};
|
||||
window.score = 0;
|
||||
window.isGameOver = 3;
|
||||
window.scoreAdditionCoeff = 1;
|
||||
window.prevScore = 0;
|
||||
window.numHighScores = 3;
|
||||
|
||||
writeHighScores();
|
||||
window.highscores = [];
|
||||
if (localStorage.getItem('highscores')) {
|
||||
try {
|
||||
highscores = JSON.parse(localStorage.getItem('highscores'));
|
||||
} catch (e) {
|
||||
highscores = [];
|
||||
}
|
||||
}
|
||||
|
||||
window.blocks = [];
|
||||
window.MainHex;
|
||||
writeHighScores();
|
||||
|
||||
window.gdx = 0;
|
||||
window.gdy = 0;
|
||||
window.blocks = [];
|
||||
window.MainHex;
|
||||
|
||||
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.gdx = 0;
|
||||
window.gdy = 0;
|
||||
|
||||
window.gameState;
|
||||
setStartScreen();
|
||||
window.devMode = 0;
|
||||
window.lastGen = undefined;
|
||||
window.prevTimeScored = undefined;
|
||||
window.nextGen = undefined;
|
||||
window.spawnLane = 0;
|
||||
window.importing = 0;
|
||||
window.importedHistory = undefined;
|
||||
window.startTime = undefined;
|
||||
|
||||
if (a != 1) {
|
||||
window.canRestart = 1;
|
||||
window.onblur = function (e) {
|
||||
if (gameState==1) {
|
||||
pause();
|
||||
}
|
||||
};
|
||||
window.gameState;
|
||||
setStartScreen();
|
||||
|
||||
$('#startBtn').off();
|
||||
if (a != 1) {
|
||||
window.canRestart = 1;
|
||||
window.onblur = function(e) {
|
||||
if (gameState == 1) {
|
||||
pause();
|
||||
}
|
||||
};
|
||||
|
||||
if (settings.platform == 'mobile') {
|
||||
$('#startBtn').on('touchstart',startBtnHandler);
|
||||
// $('.helpText').on('touchstart',function(){if (gameState != 2) showHelp});
|
||||
} else {
|
||||
$('#startBtn').on('mousedown',startBtnHandler);
|
||||
// $('.helpText').on('mousedown',function(){if (gameState != 2) showHelp});
|
||||
}
|
||||
$('#startBtn').off();
|
||||
|
||||
document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
|
||||
$(window).resize(scaleCanvas);
|
||||
$(window).unload(function(){
|
||||
if (settings.platform == 'mobile') {
|
||||
$('#startBtn').on('touchstart', startBtnHandler);
|
||||
} else {
|
||||
$('#startBtn').on('mousedown', startBtnHandler);
|
||||
}
|
||||
|
||||
if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState());
|
||||
else localStorage.clear();
|
||||
});
|
||||
document.addEventListener('touchmove', function(e) {
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
$(window).resize(scaleCanvas);
|
||||
$(window).unload(function() {
|
||||
|
||||
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');
|
||||
if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState());
|
||||
else localStorage.clear();
|
||||
});
|
||||
|
||||
document.addEventListener("pause", handlePause, false);
|
||||
document.addEventListener("backbutton", handlePause, false);
|
||||
document.addEventListener("menubutton", handlePause, false); //menu button on android
|
||||
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');
|
||||
|
||||
setTimeout(function(){
|
||||
if(settings.platform == "mobile"){
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTapBefore ,false);
|
||||
} catch (e) {
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
document.body.removeEventListener('mousedown', handleClick, false);
|
||||
} catch (e) {
|
||||
|
||||
document.body.addEventListener('mousedown', handleClickBefore, false);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
document.body.addEventListener('mousedown', handleClickBefore, false);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function startBtnHandler() {
|
||||
setTimeout(function(){
|
||||
if(settings.platform == "mobile"){
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTapBefore ,false);
|
||||
} catch (e) {
|
||||
setTimeout(function() {
|
||||
if (settings.platform == "mobile") {
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTapBefore, false);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
document.body.removeEventListener('touchstart', handleTap ,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) {
|
||||
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) {
|
||||
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");
|
||||
}
|
||||
document.body.addEventListener('mousedown', handleClick, false);
|
||||
}
|
||||
}, 5);
|
||||
|
||||
if (importing == 1) {
|
||||
init(1);
|
||||
} else {
|
||||
resumeGame();
|
||||
}
|
||||
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();
|
||||
}
|
||||
if (gameState == 1 || gameState == 2) {
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
function handleTap(e) {
|
||||
handleClickTap(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
|
||||
handleClickTap(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
|
||||
}
|
||||
|
||||
function handleClick(e) {
|
||||
handleClickTap(e.clientX, e.clientY);
|
||||
handleClickTap(e.clientX, e.clientY);
|
||||
}
|
||||
|
||||
function handleTapBefore(e) {
|
||||
var x = e.changedTouches[0].clientX;
|
||||
var y = e.changedTouches[0].clientY;
|
||||
var x = e.changedTouches[0].clientX;
|
||||
var y = e.changedTouches[0].clientY;
|
||||
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClickBefore(e) {
|
||||
var x = e.clientX;
|
||||
var y = e.clientY;
|
||||
var x = e.clientX;
|
||||
var y = e.clientY;
|
||||
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
if (x < 120 && y < 50 && $('.helpText').is(':visible')) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
493
js/main.js
493
js/main.js
|
@ -1,313 +1,314 @@
|
|||
function scaleCanvas() {
|
||||
canvas.width = $(window).width();
|
||||
canvas.height = $(window).height();
|
||||
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;
|
||||
}
|
||||
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
|
||||
};
|
||||
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);
|
||||
if (window.devicePixelRatio) {
|
||||
var cw = $("#canvas").attr('width');
|
||||
var ch = $("#canvas").attr('height');
|
||||
|
||||
trueCanvas = {
|
||||
width:cw,
|
||||
height:ch
|
||||
};
|
||||
$("#canvas").attr('width', cw * window.devicePixelRatio);
|
||||
$("#canvas").attr('height', ch * window.devicePixelRatio);
|
||||
$("#canvas").css('width', cw);
|
||||
$("#canvas").css('height', ch);
|
||||
|
||||
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
||||
}
|
||||
trueCanvas = {
|
||||
width: cw,
|
||||
height: ch
|
||||
};
|
||||
|
||||
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleDevTools() {
|
||||
$('#devtools').toggle();
|
||||
$('#devtools').toggle();
|
||||
}
|
||||
|
||||
function resumeGame() {
|
||||
gameState = 1;
|
||||
hideUIElements();
|
||||
$('#pauseBtn').show();
|
||||
$('#restartBtn').show();
|
||||
importing = 0;
|
||||
startTime = Date.now();
|
||||
setTimeout(function(){
|
||||
if ((gameState == 1 || gameState == 2) && !$('#helpScreen').is(':visible')) {
|
||||
$('.helpText').fadeOut(150, "linear");
|
||||
}
|
||||
}, 7000);
|
||||
|
||||
checkVisualElements();
|
||||
gameState = 1;
|
||||
hideUIElements();
|
||||
$('#pauseBtn').show();
|
||||
$('#restartBtn').show();
|
||||
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').fadeIn(150, "linear");
|
||||
if (!$('.helpText').is(":visible")) $('.helpText').fadeIn(150, "linear");
|
||||
if (!$('#pauseBtn').is(':visible')) $('#pauseBtn').fadeIn(150, "linear");
|
||||
if (!$('#restartBtn').is(':visible')) $('#restartBtn').fadeIn(150, "linear");
|
||||
}
|
||||
|
||||
function hideUIElements() {
|
||||
$('#pauseBtn').hide();
|
||||
$('#restartBtn').hide();
|
||||
$('#startBtn').hide();
|
||||
$("#attributions").hide();
|
||||
$("#bottombar").hide();
|
||||
$('#pauseBtn').hide();
|
||||
$('#restartBtn').hide();
|
||||
$('#startBtn').hide();
|
||||
$("#attributions").hide();
|
||||
$("#bottombar").hide();
|
||||
}
|
||||
|
||||
function init(b) {
|
||||
if (b) {
|
||||
hidebottombar();
|
||||
|
||||
if (b) {
|
||||
hidebottombar();
|
||||
|
||||
if ($('#helpScreen').is(":visible")) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
|
||||
checkVisualElements();
|
||||
|
||||
setTimeout(function() {
|
||||
$('.helpText').fadeOut(150, "linear");
|
||||
}, 7000);
|
||||
clearSaveState();
|
||||
}
|
||||
|
||||
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;
|
||||
scoreOpacity = 0;
|
||||
gameState = 1;
|
||||
$("#restartBtn").show();
|
||||
$("#pauseBtn").show();
|
||||
if(saveState.hex !== undefined) gameState = 1;
|
||||
if ($('#helpScreen').is(":visible")) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
|
||||
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;
|
||||
checkVisualElements();
|
||||
|
||||
var i;
|
||||
var block;
|
||||
if(saveState.blocks) {
|
||||
saveState.blocks.map(function(o){
|
||||
if (rgbToHex[o.color]) {
|
||||
o.color = rgbToHex[o.color];
|
||||
}
|
||||
});
|
||||
setTimeout(function() {
|
||||
$('.helpText').fadeOut(150, "linear");
|
||||
}, 7000);
|
||||
clearSaveState();
|
||||
}
|
||||
|
||||
for(i=0; i<saveState.blocks.length; i++) {
|
||||
block = saveState.blocks[i];
|
||||
blocks.push(block);
|
||||
}
|
||||
}
|
||||
else {
|
||||
blocks = [];
|
||||
}
|
||||
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;
|
||||
scoreOpacity = 0;
|
||||
gameState = 1;
|
||||
$("#restartBtn").show();
|
||||
$("#pauseBtn").show();
|
||||
if (saveState.hex !== undefined) gameState = 1;
|
||||
|
||||
gdx = saveState.gdx || 0;
|
||||
gdy = saveState.gdy || 0;
|
||||
comboTime = saveState.comboTime || 0;
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
var i;
|
||||
var block;
|
||||
if (saveState.blocks) {
|
||||
saveState.blocks.map(function(o) {
|
||||
if (rgbToHex[o.color]) {
|
||||
o.color = rgbToHex[o.color];
|
||||
}
|
||||
});
|
||||
|
||||
MainHex.blocks.map(function(i){
|
||||
i.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 = [];
|
||||
}
|
||||
|
||||
MainHex.y = -100;
|
||||
gdx = saveState.gdx || 0;
|
||||
gdy = saveState.gdy || 0;
|
||||
comboTime = saveState.comboTime || 0;
|
||||
|
||||
startTime = Date.now();
|
||||
waveone = saveState.wavegen || new waveGen(MainHex);
|
||||
|
||||
MainHex.texts = []; //clear texts
|
||||
MainHex.delay = 15;
|
||||
hideText();
|
||||
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] = {};
|
||||
}
|
||||
iter *= settings.speedModifier;
|
||||
if (!history[MainHex.ct]) {
|
||||
history[MainHex.ct] = {};
|
||||
}
|
||||
|
||||
history[MainHex.ct].block = {
|
||||
blocklane:blocklane,
|
||||
color:color,
|
||||
iter:iter
|
||||
};
|
||||
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));
|
||||
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();
|
||||
$('#devtoolsText').html(JSON.stringify(history));
|
||||
toggleDevTools();
|
||||
}
|
||||
|
||||
function setStartScreen() {
|
||||
$('#startBtn').show();
|
||||
init();
|
||||
if (isStateSaved()) {
|
||||
importing = 0;
|
||||
} else {
|
||||
importing = 1;
|
||||
}
|
||||
$('#startBtn').show();
|
||||
init();
|
||||
if (isStateSaved()) {
|
||||
importing = 0;
|
||||
} else {
|
||||
importing = 1;
|
||||
}
|
||||
|
||||
$('#pauseBtn').hide();
|
||||
$('#restartBtn').show();
|
||||
$('#startBtn').show();
|
||||
$('#attributions').show();
|
||||
showbottombar();
|
||||
$('#pauseBtn').hide();
|
||||
$('#restartBtn').show();
|
||||
$('#startBtn').show();
|
||||
$('#attributions').show();
|
||||
showbottombar();
|
||||
|
||||
gameState = 0;
|
||||
requestAnimFrame(animLoop);
|
||||
gameState = 0;
|
||||
requestAnimFrame(animLoop);
|
||||
}
|
||||
|
||||
function animLoop() {
|
||||
switch (gameState) {
|
||||
case 1:
|
||||
requestAnimFrame(animLoop);
|
||||
if (!MainHex.delay) {
|
||||
update();
|
||||
} else {
|
||||
MainHex.delay--;
|
||||
}
|
||||
render();
|
||||
if (checkGameOver() && !importing) {
|
||||
|
||||
var saveState = localStorage.getItem("saveState") || "{}";
|
||||
saveState = JSONfn.parse(saveState);
|
||||
gameState = 2;
|
||||
switch (gameState) {
|
||||
case 1:
|
||||
requestAnimFrame(animLoop);
|
||||
if (!MainHex.delay) {
|
||||
update();
|
||||
} else {
|
||||
MainHex.delay--;
|
||||
}
|
||||
render();
|
||||
if (checkGameOver() && !importing) {
|
||||
|
||||
setTimeout(function(){
|
||||
enableRestart();
|
||||
}, 150);
|
||||
var saveState = localStorage.getItem("saveState") || "{}";
|
||||
saveState = JSONfn.parse(saveState);
|
||||
gameState = 2;
|
||||
|
||||
if ($('#helpScreen').is(':visible')) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
setTimeout(function() {
|
||||
enableRestart();
|
||||
}, 150);
|
||||
|
||||
if ($('#pauseBtn').is(':visible')) $('#pauseBtn').fadeOut(150, "linear");
|
||||
if ($('#restartBtn').is(':visible')) $('#restartBtn').fadeOut(150, "linear");
|
||||
if (!$('.helpText').is(':visible')) $('.helpText').fadeIn(150, "linear");
|
||||
if ($('#helpScreen').is(':visible')) {
|
||||
$('#helpScreen').fadeOut(150, "linear");
|
||||
}
|
||||
|
||||
showbottombar();
|
||||
canRestart = 0;
|
||||
clearSaveState();
|
||||
}
|
||||
break;
|
||||
|
||||
case 0:
|
||||
requestAnimFrame(animLoop);
|
||||
if (importing) {
|
||||
update();
|
||||
}
|
||||
|
||||
render();
|
||||
break;
|
||||
|
||||
case -1:
|
||||
requestAnimFrame(animLoop);
|
||||
render();
|
||||
break;
|
||||
if ($('#pauseBtn').is(':visible')) $('#pauseBtn').fadeOut(150, "linear");
|
||||
if ($('#restartBtn').is(':visible')) $('#restartBtn').fadeOut(150, "linear");
|
||||
if (!$('.helpText').is(':visible')) $('.helpText').fadeIn(150, "linear");
|
||||
|
||||
case 2:
|
||||
requestAnimFrame(animLoop);
|
||||
update();
|
||||
render();
|
||||
break;
|
||||
showbottombar();
|
||||
canRestart = 0;
|
||||
clearSaveState();
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
requestAnimFrame(animLoop);
|
||||
fadeOutObjectsOnScreen();
|
||||
render();
|
||||
break;
|
||||
case 0:
|
||||
requestAnimFrame(animLoop);
|
||||
if (importing) {
|
||||
update();
|
||||
}
|
||||
|
||||
case 4:
|
||||
setTimeout(function(){initialize(1);}, 1);
|
||||
render();
|
||||
return;
|
||||
render();
|
||||
break;
|
||||
|
||||
default:
|
||||
initialize();
|
||||
setStartScreen();
|
||||
break;
|
||||
}
|
||||
case -1:
|
||||
requestAnimFrame(animLoop);
|
||||
render();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
requestAnimFrame(animLoop);
|
||||
update();
|
||||
render();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
requestAnimFrame(animLoop);
|
||||
fadeOutObjectsOnScreen();
|
||||
render();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
setTimeout(function() {
|
||||
initialize(1);
|
||||
}, 1);
|
||||
render();
|
||||
return;
|
||||
|
||||
default:
|
||||
initialize();
|
||||
setStartScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function enableRestart() {
|
||||
canRestart = 1;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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)) {
|
||||
if(highscores.indexOf(score) == -1){
|
||||
highscores.push(score);
|
||||
}
|
||||
writeHighScores();
|
||||
gameOverDisplay();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for (var i = 0; i < MainHex.sides; i++) {
|
||||
if (isInfringing(MainHex)) {
|
||||
if (highscores.indexOf(score) == -1) {
|
||||
highscores.push(score);
|
||||
}
|
||||
writeHighScores();
|
||||
gameOverDisplay();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function showHelp(){
|
||||
if (gameState == 1) {
|
||||
pause();
|
||||
}
|
||||
function showHelp() {
|
||||
if (gameState == 1) {
|
||||
pause();
|
||||
}
|
||||
|
||||
$('#helpScreen').fadeToggle(150, "linear");
|
||||
}
|
||||
$('#helpScreen').fadeToggle(150, "linear");
|
||||
}
|
352
js/wavegen.js
352
js/wavegen.js
|
@ -1,198 +1,198 @@
|
|||
function blockDestroyed() {
|
||||
if (waveone.nextGen > 1350) {
|
||||
waveone.nextGen -= 25 * settings.creationSpeedModifier;
|
||||
} else {
|
||||
waveone.nextGen = 1350;
|
||||
}
|
||||
if (waveone.nextGen > 1350) {
|
||||
waveone.nextGen -= 30 * settings.creationSpeedModifier;
|
||||
} else if (waveone.nextGen > 900) {
|
||||
waveone.nextGen -= 15 * settings.creationSpeedModifier;
|
||||
} else {
|
||||
waveone.nextGen = 900;
|
||||
}
|
||||
|
||||
if (waveone.difficulty < 15) {
|
||||
waveone.difficulty += 0.04;
|
||||
} else {
|
||||
waveone.difficulty = 15;
|
||||
}
|
||||
if (waveone.difficulty < 25) {
|
||||
waveone.difficulty += 0.13 * settings.speedModifier;
|
||||
} else {
|
||||
waveone.difficulty = 25;
|
||||
}
|
||||
}
|
||||
|
||||
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 += 16.6666667;
|
||||
this.computeDifficulty();
|
||||
if ((this.dt - this.lastGen)*settings.creationSpeedModifier > this.nextGen) {
|
||||
if (this.nextGen > 1350) {
|
||||
this.nextGen -= 10 * ((this.nextGen/1300)) * settings.creationSpeedModifier;
|
||||
}
|
||||
}
|
||||
};
|
||||
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 += 16.6666667;
|
||||
this.computeDifficulty();
|
||||
if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) {
|
||||
if (this.nextGen > 900) {
|
||||
this.nextGen -= 10 * ((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.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 < 15) {
|
||||
if (this.difficulty < 8) {
|
||||
this.difficulty += (this.dt - this.last)/(2000000);
|
||||
}
|
||||
else {
|
||||
this.difficulty += (this.dt - this.last)/(40000000);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.computeDifficulty = function() {
|
||||
if (this.difficulty < 25) {
|
||||
if (this.difficulty < 8) {
|
||||
this.difficulty += (this.dt - this.last) / (3666667) * settings.speedModifier;
|
||||
} else if (this.difficulty < 15) {
|
||||
this.difficulty += (this.dt - this.last) / (63333333) * settings.speedModifier;
|
||||
} else {
|
||||
this.difficulty += (this.dt - this.last) / (150000000) * 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);
|
||||
}
|
||||
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]);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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.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];
|
||||
}
|
||||
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);
|
||||
}
|
||||
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.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.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.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.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.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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
|
||||
// rest of generation functions
|
||||
// rest of generation functions
|
||||
|
||||
this.currentFunction = this.randomGeneration;
|
||||
}
|
||||
this.currentFunction = this.randomGeneration;
|
||||
}
|
Loading…
Reference in a new issue