-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_mario.js
50 lines (49 loc) · 1.74 KB
/
basic_mario.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
case 37:
$('#mario').animate({left: "-=30px"}, 'fast');
break;
case 38:
$('#mario').animate({top:'-=30px'},'fast');
break;
case 39:
$('#mario').animate({left:'+=30px'},'fast');
break;
case 40:
$('#mario').animate({top:'+=30px'},'fast');
break;
}
var end = $("#mario").collision( "#coin" );
var win = end.remove();
if(win.length != 0)
{
alert("U WON THE GAME!!");
$('#mario').after('<a href="basic game.html">PLAY AGAIN</a>');
$('#mario').remove();
$('.rock').remove();
}
var explosion = $('.rock').collision("#mario");
var loss = explosion.effect('explode');
if(loss.length !=0)
{
alert("GAME OVER!!");
$('#mario').after('<a href="basic game.html">PLAY AGAIN</a>');
$('.rock').remove();
}
});
scroll();
function scroll() {
$("#rock1").css("left", "10%");
$('#rock1').delay(2000).animate({left : '90%'},3000);
$("#rock2").css("top", "10%");
$('#rock2').delay(2000).animate({top : '90%'},3000);
$("#rock3").css("left", "90%");
$('#rock3').delay(2000).animate({left : '20%'},3000);
$("#rock4").css("top","90%");
$('#rock4').delay(2000).animate({top : '20%'},3000);
$("#rock5").css({"top":"15%","left" : "35%"});
$('#rock5').delay(2000).animate({left : '80%',top: '80%'},3000);
$("#rock6").css({"left":"90%","top": "90%"});
$('#rock6').delay(2000).animate({left : '10%', top: '10%'},3000,scroll);}
});