-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdarkscrolls.js
70 lines (58 loc) · 1.24 KB
/
darkscrolls.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
$(document).ready(function() {
var world = [
[2,2,2,2,2,2,2,2,2,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,2],
[2,2,2,2,2,2,2,2,2,2]
];
var mainChar = {
x: 60,
y: 60
}
function displayWorld(){
var output = '';
for(var i=0; i<world.length; i++){
output += "<div class='row'>";
for(var j=0; j<world[i].length; j++){
if(world[i][j] == 2){
output += "<div class='brick'></div>";
}
else if(world[i][j] == 1){
output += "<div class='coin'></div>";
}
if(world[i][j] == 0){
output += "<div class='empty'></div>";
}
}
output += "</div>";
}
document.getElementById('world').innerHTML = output;
}
displayWorld();
function drawMainChar(){
document.getElementById("mainChar").style.top = mainChar.y * 1 + "px";
document.getElementById("mainChar").style.left = mainChar.x * 1 + "px";
}
displayWorld();
document.onkeydown = function(e){
if(e.keyCode==37)
{
// if(world[x][y] !== 2)
mainChar.x = mainChar.x - 60;
}
if(e.keyCode==39)
{
// if(world[x][y] !== 2)
mainChar.x = mainChar.x + 60;
}
drawMainChar();
console.log(e.keyCode);
}
});