-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (34 loc) · 958 Bytes
/
script.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
const start = document.querySelector(".start");
const character = document.querySelector(".character");
var startG = start.getBoundingClientRect();
var characterG = character.getBoundingClientRect();
$(document).keydown(function(e) {
if (e.which == '39') { //Right arrow key
$(".character").finish().animate({
left: "+=50"
});
}
if (e.which == '37') { //left arrow key
$(".character").finish().animate({
left: "-=50"
});
}
if (e.which == '40') { //down arrow key
$(".character").finish().animate({
top: "+=50"
});
}
if (e.which == '38') { //up arrow key
$(".character").finish().animate({
top: "-=50"
});
}
startGame();
});
function startGame(){
console.log(character.x);
console.log(start.x);
if(character.x >= start.x && character.y <= start.y){
window.location = "game.html";
}
}