-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel-designer.html
99 lines (89 loc) · 3.38 KB
/
level-designer.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/canvas.js"></script>
<script type="text/javascript" src="js/keys.js"></script>
<script type="text/javascript" src="js/astar-min.js"></script>
<script type="text/javascript">
var canvas, demo, _key,
map = [], graph = [], closed = [];
function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function init(){
_key = new Key();
canvas = document.getElementById("demo");
demo = new Canvas(canvas);
// Строим сетку
var cellSize = 32,
mapSize = [30, 20];
for( var h = mapSize[1]; h--; ){ // Перебор по вертикали
map[h] = [];
graph[h] = [];
for( var w = mapSize[0]; w--; ){ // Перебор по горизонтали
map[h][w] = {
v: (new demo.draw.Rectangle(
w*cellSize, h*cellSize, // Position
cellSize, cellSize, // Size
"#CCC" // Fill
)).bind('click', function(e){
if( this.free ){
this.free = false;
this.fill = (e.ctrlKey) ? "#FF0" : (e.altKey) ? "#F00" : "#00F";
graph[this.cy][this.cx] = (e.ctrlKey) ? 2 : (e.altKey) ? 3 : 1;
}else{
this.free = true;
this.fill = "#CCC";
graph[this.cy][this.cx] = 0;
}
levelJSON();
})
}
map[h][w].v.free = true;
map[h][w].v.cx = w;
map[h][w].v.cy = h;
graph[h][w] = 0;
}
}
var draw = function(delta){
};
demo.animate.addDraw(draw);
demo.animate.play();
}
function levelJSON(){
var textarea = document.getElementById('json'),
json = JSON.stringify(graph);
textarea.value = json;
}
</script>
<style type="text/css">
html, body{min-height: 100%; height: 100%; margin: 5px; padding: 0;}
canvas{border: 1px solid #CCC;}
.legend div{
float: left;
width: 32px;
height: 32px;
margin: 10px;
text-align: center;
line-height: 32px;
}
.start{ background-color: #0F0; }
.end{ background-color: #F00; color: #FFF; }
.wall{ background-color: #00F; color: #FFF; }
#json{width: 800px; height: 500px; clear: both; display: block;}
</style>
</head>
<body onload="init();">
<canvas id="demo" width="960" height="640">
Update your browser.
</canvas>
<div class="legend">
<div class="start">start</div>
<div class="end">end</div>
<div class="wall">wall</div>
</div>
<textarea name="" id="json" cols="30" rows="10"></textarea>
</body>
</html>