Skip to content

Commit

Permalink
prototype for pause feature
Browse files Browse the repository at this point in the history
  • Loading branch information
irapha committed Oct 20, 2014
1 parent d46b7b8 commit a74ef2c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
13 changes: 10 additions & 3 deletions index.html
Expand Up @@ -192,14 +192,20 @@
border: 2px dashed white;
z-index:8;
}
#pause-button {
float:left;
color: white;
padding: 4px;
border: 2px solid white;
cursor: pointer;
}
#mute-button {
position: absolute;
top: 10px;
left: 10px;
float:left;
color: white;
padding: 4px;
border: 2px solid white;
cursor: pointer;
margin-left: 10px;
}
#feedback-button {
position: absolute;
Expand Down Expand Up @@ -298,6 +304,7 @@
</head>

<body>
<div id='pause-button'>| |</div>
<div id='mute-button'>Mute</div>
<a href="raphaelgontijolopes@gmail.com"><div id='feedback-button'>Feedback</div></a>
<div id='startmenu' align="center">
Expand Down
85 changes: 54 additions & 31 deletions scripts/main.js
Expand Up @@ -12,6 +12,7 @@ var selectedPlanet;
var bluePlanets = [];
var redPlanets = [];
var starterPlanetSelected = 0;
var isPaused = false;
var inDebug = false;

function setupLevel() {
Expand Down Expand Up @@ -865,44 +866,66 @@ setupLevel();
initialDraw();
requestStarterPlanet();

var mainLoop = setInterval(function() {
if(starterPlanetSelected === 1){
var whoWon = 0;
var mainLoop;
var aiChecks;

updatePopulations();
updatePiePlanets();
// wipeZeroedPlanets(); //TODO: commented this out... Why is this necessary?
if(!inDebug) {
updateAIConnectionsVisibility(); //DEBUG
}
deleteConnectionsToChaoticPlanets();
updatePlanetScales();
writePlanetPopulations();
whoWon = checkWinState();
if(whoWon === 1 || whoWon === 2){

if(whoWon === 1) {
whoWon = "You";
}else {
whoWon = "A.I.";
var startGame = function() {
mainLoop = setInterval(function() {
if(starterPlanetSelected === 1){
var whoWon = 0;

updatePopulations();
updatePiePlanets();
// wipeZeroedPlanets(); //TODO: commented this out... Why is this necessary?
if(!inDebug) {
updateAIConnectionsVisibility(); //DEBUG
}
deleteConnectionsToChaoticPlanets();
updatePlanetScales();
writePlanetPopulations();
whoWon = checkWinState();
if(whoWon === 1 || whoWon === 2){

if(whoWon === 1) {
whoWon = "You";
}else {
whoWon = "A.I.";
}

$(".planet").unbind();
$("#endmenu").show();
$("#whowon").html(whoWon+" won!");
delete whoWon;
$(".planet").unbind();
$("#endmenu").show();
$("#whowon").html(whoWon+" won!");
delete whoWon;

clearInterval(mainLoop);
clearInterval(aiChecks);
clearInterval(mainLoop);
clearInterval(aiChecks);
}
}
}
}, 33);
}, 33);

var aiChecks = setInterval(function() {
if(starterPlanetSelected === 1) {
ai.updateConnections();
aiChecks = setInterval(function() {
if(starterPlanetSelected === 1) {
ai.updateConnections();
}
}, 5000);
}

startGame();

$("#pause-button").click(function() {
if(!isPaused) {
isPaused = true;
$("#pause-button").html("&nbsp;>&nbsp;");
clearInterval(mainLoop);
clearInterval(aiChecks);
$("#whowon").html("PAUSED");
} else {
isPaused = false;
$("#pause-button").html("|&nbsp;|");
startGame();
$("#whowon").html("");
}
}, 5000);
});

var playing = true;
$('#mute-button').click(function() {
Expand Down

0 comments on commit a74ef2c

Please sign in to comment.