javascript - Game over on Snake Game -


i'm doing snake game , want display game over when spaceship crashes. want game on image appears , floating on center of boardgame.

i think have place here don't know how it.

var makeastep = function() { if (snake.detectcollision(snake.velocity) === true) {     var explosion = $('<div id="explosion"><img src="images/explosion.gif"></div>');     var newcss = {         top: parseint($("#head").css("top").substring(0, $("#head").css("top").length - 2)) - 90 + 'px',         left: parseint($("#head").css("left").substring(0, $("#head").css("left").length - 2)) - 61 + 'px',         position: 'absolute'     };     explosion.css(newcss);     $('#box').append(explosion);     var alertinterval = setinterval(function() {         clearinterval(alertinterval);         $('#explosion').remove();     }, 800);      clearinterval(intervalhandler);     intervalhandler == null;     return; }  var lastitemposition = snake.body[snake.body.length - 1].position.copy();  snake.move();  var ijustatesomefood = snake.gethead().isonposition(food.position);  if (ijustatesomefood == true) {     food.updatescore();     generatefood();     snake.body.push(new snakeitem(lastitemposition)); }  snake.screenupdate({updatefireballs: ijustatesomefood}); 

};

the complete code

since using jquery, can call modal dialog

if (snake.detectcollision(snake.velocity) === true) {   $("#dialog").dialog("open"); // here   ... } 

after create <div id="dialog">...</div>, see link example.

note: nice game. should disable 180° rotation, i.e. spaceship moving left should not react right arrow.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -