-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aaron.js
71 lines (64 loc) · 1.71 KB
/
Aaron.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const aaron = document.getElementById('aaron');
const characterSize = 45;
var mapX = //x coodrinate of map
var mapY = //Y coordinate of map
//SETS COORDINATES
var aaronY= //y coordinate of aaron's spawn point
var aaronX= //x coord
//MOVES DOWN
function moveDown() {
if (aaronY < (mapY - characterSize) && aaronY >= 0) {
aaronY += characterSize;
aaron.style.top = aaronY+"px";
}
}
//MOVES UP
function moveUp() {
if (aaronY < mapY && aaronY >= characterSize) {
aaronY -= characterSize;
aaron.style.top = aaronY+"px";
}
}
//MOVES RIGHT
function moveRight() {
if (aaronX < (mapX - characterSize) && aaronX >= 0) {
aaronX += characterSize;
aaron.style.left = aaronX+"px";
}
}
//MOVES LEFT
function moveLeft() {
if (aaronX >= characterSize && aaronX <mapX) {
aaronX -= characterSize;
aaron.style.left = aaronX+"px";
}
}
//CONTROLS KEYBOARD MOVEMENT
document.addEventListener("keydown", function(e) {
setTimeout(function() {
if (aaronX < liebreX + characterSize &&
aaronX + characterSize > liebreX &&
aaronY < liebreY + characterSize &&
characterSize + aaronY > liebreY)
{console.log("collision!");} //win condition
else {
switch (e.key) {
case "ArrowDown":
case "s":
moveDown();
break;
case "ArrowUp":
case "w":
moveUp();
break;
case "ArrowLeft":
case "a":
moveLeft();
break;
case "ArrowRight":
case "d":
moveRight();
break;}
}
}, speed);
});