').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) {
Engine.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);
clearInterval(Space._volumeTimer);
clearTimeout(Space._panelTimeout);
var body_color;
if (Engine.isLightsOff())
body_color = '#272823';
else
body_color = '#FFFFFF';
// Craaaaash!
$('body').removeClass('noMask').stop().animate({
backgroundColor: body_color
}, {
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();
$('body').attr('style', '');
$('#notifyGradient').attr('style', '');
$('#spacePanel').attr('style', '');
}
});
$('.menu, select.menuBtn').animate({color: '#666'}, 300, 'linear');
$('#outerSlider').animate({top: '0px'}, 300, 'linear');
Engine.activeModule = Ship;
Ship.onArrival();
Button.cooldown($('#liftoffButton'));
Engine.event('progress', 'crash');
AudioEngine.playSound(AudioLibrary.CRASH);
},
endGame: function() {
if(Space.done) return;
Engine.event('progress', 'win');
Space.done = true;
clearInterval(Space._timer);
clearInterval(Space._shipTimer);
clearInterval(Space._volumeTimer);
clearTimeout(Engine._saveTimer);
clearTimeout(Outside._popTimeout);
clearTimeout(Engine._incomeTimeout);
clearTimeout(Events._eventTimeout);
clearTimeout(Room._fireTimer);
clearTimeout(Room._tempTimer);
for(var j in Room.Craftables) {
Room.Craftables[j].button = null;
}
for(var k in Room.TradeGoods) {
Room.TradeGoods[k].button = null;
}
delete Outside._popTimeout;
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_ENDING);
$('#hullRemaining', Space.panel).animate({opacity: 0}, 500, 'linear');
Space.ship.animate({
top: '350px',
left: '240px'
}, 3000, 'linear', function() {
Engine.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();
Engine.setTimeout(function() {
$('body').stop();
var container_color;
if (Engine.isLightsOff())
container_color = '#EEE';
else
container_color = '#000';
$('#starsContainer').animate({
opacity: 0,
'background-color': container_color
}, {
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() {
Engine.GAME_OVER = true;
Score.save();
Prestige.save();
$('
')
.addClass('centerCont')
.appendTo('body');
$('')
.addClass('endGame')
.text(_('score for this game: {0}', Score.calculateScore()))
.appendTo('.centerCont')
.animate({opacity:1},1500);
$('
')
.appendTo('.centerCont');
$('')
.addClass('endGame')
.text(_('total score: {0}', Prestige.get().score))
.appendTo('.centerCont')
.animate({opacity:1},1500);
$('
')
.appendTo('.centerCont');
$('
')
.appendTo('.centerCont');
$('#starsContainer').remove();
$('#content, #notifications').remove();
$('')
.addClass('endGame endGameOption')
.text(_('restart.'))
.click(Engine.confirmDelete)
.appendTo('.centerCont')
.animate({opacity:1},1500);
$('
')
.appendTo('.centerCont');
$('
')
.appendTo('.centerCont');
$('')
.addClass('endGame')
.text(_('expanded story. alternate ending. behind the scenes commentary. get the app.'))
.appendTo('.centerCont')
.animate({opacity:1}, 1500);
$('
')
.appendTo('.centerCont');
$('
')
.appendTo('.centerCont');
$('')
.addClass('endGame endGameOption')
.text(_('iOS.'))
.click(function() { window.open('https://itunes.apple.com/app/apple-store/id736683061?pt=2073437&ct=gameover&mt=8'); })
.appendTo('.centerCont')
.animate({opacity:1},1500);
$('
')
.appendTo('.centerCont');
$('')
.addClass('endGame endGameOption')
.text(_('android.'))
.click(function() { window.open('https://play.google.com/store/apps/details?id=com.yourcompany.adarkroom'); })
.appendTo('.centerCont')
.animate({opacity:1},1500);
Engine.options = {};
Engine.deleteSave(true);
}
});
}, 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;
}
},
handleStateUpdates: function(e){
},
lowerVolume: function () {
if (Space.done) return;
// lower audio as ship gets further into space
var progress = Space.altitude / 60;
var newVolume = 1.0 - progress;
AudioEngine.setBackgroundMusicVolume(newVolume, 0.3);
}
};