').css({
width: Space.STAR_WIDTH + 'px',
height: Space.STAR_HEIGHT + 'px'
});
s2 = s1.clone();
Space.starsBack.append(s1).append(s2);
Space.drawStarAsync(s1, s2, 0);
Space.starsBack.data('speed', Space.STAR_SPEED * 2);
Space.startAnimation(Space.starsBack);
},
startAnimation: function(el) {
el.animate({bottom: '-3000px'}, el.data('speed'), 'linear', function() {
$(this).css('bottom', '0px');
Space.startAnimation($(this));
});
},
drawStarAsync: function(el, el2, num) {
var top = Math.floor(Math.random() * Space.STAR_HEIGHT) + 'px';
var left = Math.floor(Math.random() * Space.STAR_WIDTH) + 'px';
$('
').text('.').addClass('star').css({
top: top,
left: left
}).appendTo(el);
$('
').text('.').addClass('star').css({
top: top,
left: left
}).appendTo(el2);
if(num < Space.NUM_STARS) {
setTimeout(function() { Space.drawStarAsync(el, el2, num + 1); }, 100);
}
},
crash: function() {
if(Space.done) return;
Engine.keyLock = true;
Space.done = true;
clearInterval(Space._timer);
clearInterval(Space._shipTimer);
// Craaaaash!
$('body').removeClass('noMask').stop().animate({
backgroundColor: '#FFFFFF'
}, {
duration: 300,
progress: function() {
var cur = $('body').css('background-color');
var s = 'linear-gradient(rgba' + cur.substring(3, cur.length - 1) + ', 0) 0%, rgba' +
cur.substring(3, cur.length - 1) + ', 1) 100%)';
$('#notifyGradient').attr('style', 'background-color:'+cur+';background:-webkit-' + s + ';background:' + s);
},
complete: function() {
Space.stars.remove();
Space.starsBack.remove();
Space.stars = Space.starsBack = null;
$('#starsContainer').remove();
}
});
$('#spacePanel, .deleteSave, .share').animate({color: 'black'}, 300, 'linear');
$('#outerSlider').animate({top: '0px'}, 300, 'linear');
Engine.activeModule = Ship;
Ship.onArrival();
Button.cooldown($('#liftoffButton'));
Engine.event('progress', 'crash');
},
endGame: function() {
if(Space.done) return;
Engine.event('progress', 'win');
Space.done = true;
clearInterval(Space._timer);
clearInterval(Space._shipTimer);
clearTimeout(Engine._saveTimer);
clearTimeout(Outside._popTimeout);
clearTimeout(Engine._incomeTimeout);
clearTimeout(Events._eventTimeout);
clearTimeout(Room._fireTimer);
clearTimeout(Room._tempTimer);
for(var k in Room.Craftables) {
Room.Craftables[k].button = null;
}
for(var k in Room.TradeGoods) {
Room.TradeGoods[k].button = null;
}
delete Outside._popTimeout;
$('#hullRemaining', Space.panel).animate({opacity: 0}, 500, 'linear');
Space.ship.animate({
top: '350px',
left: '240px'
}, 3000, 'linear', function() {
setTimeout(function() {
Space.ship.animate({
top: '-100px'
}, 200, 'linear', function() {
// Restart everything! Play FOREVER!
$('#outerSlider').css({'left': '0px', 'top': '0px'});
$('#locationSlider, #worldPanel, #spacePanel, #notifications').remove();
$('#header').empty();
setTimeout(function() {
$('body').removeClass('noMask').stop().animate({
opacity: 0,
'background-color': '#FFF'
}, {
duration: 2000,
progress: function() {
var cur = $('body').css('background-color');
var s = 'linear-gradient(rgba' + cur.substring(3, cur.length - 1) + ', 0) 0%, rgba' +
cur.substring(3, cur.length - 1) + ', 1) 100%)';
$('#notifyGradient').attr('style', 'background-color:'+cur+';background:-webkit-' + s + ';background:' + s);
},
complete: function() {
$('#starsContainer, .deleteSave, .share').remove();
if(typeof Storage != 'undefined' && localStorage) {
localStorage.clear();
}
delete window.State;
Engine.options = {};
setTimeout(function() {
Engine.init();
$('body').animate({
opacity: 1
}, 500, 'linear');
}, 2000);
}
});
}, 2000);
});
}, 2000);
});
},
keyDown: function(event) {
switch(event.which) {
case 38: // Up
case 87:
Space.up = true;
Engine.log('up on');
break;
case 40: // Down
case 83:
Space.down = true;
Engine.log('down on');
break;
case 37: // Left
case 65:
Space.left = true;
Engine.log('left on');
break;
case 39: // Right
case 68:
Space.right = true;
Engine.log('right on');
break;
}
},
keyUp: function(event) {
switch(event.which) {
case 38: // Up
case 87:
Space.up = false;
Engine.log('up off');
break;
case 40: // Down
case 83:
Space.down = false;
Engine.log('down off');
break;
case 37: // Left
case 65:
Space.left = false;
Engine.log('left off');
break;
case 39: // Right
case 68:
Space.right = false;
Engine.log('right off');
break;
}
}
};