-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_test.html
283 lines (253 loc) · 9.44 KB
/
map_test.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!doctype html>
<html>
<head>
<title>Infinite Dungeon: Map Test</title>
<link rel="icon" type="image/vnd.microsoft.icon" href="/code/loc/favicon.ico"/>
<link rel='stylesheet' href='/code/loc/Canvassa/loc.css'/>
<script data-dojo-config="parseOnLoad: false, isDebug: false, modulePaths:{ 'loc': '/code/loc/Canvassa' }"
src="http://o.aolcdn.com/dojo/1.6/dojo/dojo.js"></script>
<!--src="/js/dojo-release-1.6.1-src/dojo/dojo.js"></script-->
<link rel="stylesheet" href="/fonts/silkscreen/stylesheet.css" type="text/css" charset="utf-8">
<style type="text/css">
h1 {
font: 60px/68px 'SilkscreenNormal', Arial, sans-serif;
letter-spacing: 0;
margin: 0; padding: 0;
//text-align: center;
}
canvas {
border: 6px double black;
}
#mapCanvas {
top: 80px;
left: 20px;
}
#messages {
font: 8pt 'SilkscreenNormal', Arial, sans-serif;
border: 6px double black;
background-color: black;
color: white;
position: absolute;
top: 260px; left: 20px;
height: 136px; width: 252px;
}
#message_fader {
border: none;
position: absolute;
top: 260px; left: 20px;
height: 148px; width: 264px;
background-color: transparent;
background-image: -moz-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,1));
background-image: -o-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,1));
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgba(0,0,0,0)),color-stop(1, rgba(0,0,0,1)));
background-image: -webkit-linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
background-image: linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,0));
}
#textMap {
display: block;
font-family: monospace;
}
#floorCanvas, #spriteCanvas {
top: 80px;
left: 296px;
}
#infoPane {
position: absolute;
top: 80px;
left: 820px;
}
</style>
</head>
<body>
<h1>Infinite Dungeon!</h1>
<div class="map">
<canvas id="mapCanvas" width="256" height="160">
Browser! Y U NO Canvas?
</canvas>
<div id="throbber"><img src="res/wait.gif" /><br/>Loading resources...</div>
<div id="messages"></div>
<!--div id="message_fader"></div-->
<canvas id="floorCanvas" width="480" height="320"></canvas>
<canvas id="spriteCanvas" width="480" height="320"></canvas>
</div>
<div id="infoPane">
<button id="btnNewMap">Generate New Map</button><br/>
<a href="#" id="lnkShowMap">↓ Show map ↓</a>
<textarea id="textMap" rows='10' cols='20' style="display:none;"></textarea>
<a href="#" id="lnkHideMap" style="display:none;">↑ Hide map ↑ </a>
<p>Inspired by the Ruby work done by <a href="http://weblog.jamisbuck.org/2011/2/7/maze-generation-algorithm-recap">Jamis</a></p>
<audio id="sndBGM" preload loop>
<source src="res/bgm.mp3" type="audio/mpeg" />
<source src="res/bgm.ogg" type="audio/ogg" />
</audio>
<audio id="sndItem" preload>
<source src="res/item.mp3" type="audio/mpeg" />
<source src="res/item.ogg" type="audio/ogg" />
</audio>
<audio id="sndStairs" preload>
<source src="res/stairs.mp3" type="audio/mpeg" />
<source src="res/stairs.ogg" type="audio/ogg" />
</audio>
<audio id="sndWin" preload>
<source src="res/win.mp3" type="audio/mpeg" />
<source src="res/win.ogg" type="audio/ogg" />
</audio>
<a href="javascript:nosound_onclick();">No music</a>
</div>
</body>
<script src="map.js"></script>
<script>
function showMap() {
//dojo.stopEvent(e);
dojo.byId('textMap').style.display = '';
dojo.byId('lnkHideMap').style.display = '';
dojo.byId('lnkShowMap').style.display = 'none';
}
function hideMap(e) {
//dojo.stopEvent(e);
dojo.byId('textMap').style.display = 'none';
dojo.byId('lnkHideMap').style.display = 'none';
dojo.byId('lnkShowMap').style.display = '';
}
dojo.addOnLoad(function init_loader(){
// hook up events
dojo.connect(dojo.byId("btnNewMap"), "onclick", newMap);
dojo.connect(dojo.byId("lnkShowMap"), "onclick", showMap);
dojo.connect(dojo.byId("lnkHideMap"), "onclick", hideMap);
window.noSound = false;
window.sounds = {
'bgm' : dojo.byId('sndBGM'),
'item' : dojo.byId('sndItem'),
'stairs' : dojo.byId('sndStairs'),
'win' : dojo.byId('sndWin')
}
if (typeof sounds.bgm.loop != 'boolean') {
sounds.bgm.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
}
sounds.item.addEventListener('ended', snd_ended);
sounds.stairs.addEventListener('ended', snd_ended);
// before ANYTHING else, see if we can get a canvas context
var big_canvas = dojo.byId('floorCanvas');
if (big_canvas.getContext){
dojo.require("loc.Preloader");
dojo.addOnLoad(preload);
} else {
// hide the "please wait" throbber
dojo.style("throbber","display","none")
}
}); // end of init_loader()
function preload() {
window.loader = new loc.Preloader({
images: {
map: "res/map.png",
tiles: "res/underworld_tiles.png",
floor: "res/floor.png",
items: "res/items.png"
},
modules: []
})
if (loader.ready()) {
init_map();
delete window.loader;
} else {
var listener = dojo.subscribe("loc.Preloader.onReady", function() {
dojo.unsubscribe(listener);
init_map();
delete window.loader;
});
}
} // end of preload()
function init_map() {
window.map = new Map();
map.init({
mapCanvasID: "mapCanvas",
mapImg: window.imageCache.getImage("map"),
floorCanvasID: "floorCanvas",
floorImg: window.imageCache.getImage("floor"),
spriteCanvasID: "spriteCanvas",
tileImg: window.imageCache.getImage("tiles"),
itemsImg: window.imageCache.getImage("items")
});
dojo.connect(map, "message", map_message);
dojo.connect(map, "getItem", map_gotItem);
dojo.connect(map, "gameover", map_youWin);
// hide the "please wait" throbber
dojo.style("throbber","display","none")
// hook up the keyboard event handlers for player input
dojo.connect(window, "onkeydown", handle_keydown);
dojo.connect(window, "onkeyup", handle_keyup);
newMap();
}
function newMap() {
dojo.byId('messages').value = "";
map.generate();
dojo.byId('textMap').value = map.dump(map);
sounds.bgm.play();
}
function nosound_onclick() {
sounds.bgm.pause();
window.noSound = true;
}
function map_message(msg) {
dojo.byId('messages').innerHTML = msg.replace(/\n/g,"<p/>");
}
function map_gotItem(itm) {
if (!(noSound)) {
sounds.bgm.pause();
if (itm)
sounds.item.play();
}
}
function snd_ended() {
if (!(noSound)) {
sounds.bgm.play();
}
}
function play_stairs_sound() {
if (!(noSound)) {
sounds.bgm.pause();
sounds.stairs.play();
}
}
function map_youWin() {
if (!(noSound)) {
sounds.bgm.pause();
sounds.win.play();
}
}
/* handle user input/controls */
var isIE = navigator.appName.toLowerCase().indexOf("explorer") > -1;
handle_keydown = function(e){
var ev = isIE?event:e;
switch(ev.keyCode){
case 39: // right
map.east();
break;
case 37: // left
map.west();
break;
case 38: // up
map.north();
break;
case 40: // down
map.south();
break;
case 188: // < (up)
if (map.up()) { play_stairs_sound(); }
break;
case 190: // > (down)
if (map.down()) { play_stairs_sound(); }
break;
default:
//console.log(ev.keyCode);
}
}
handle_keyup = function(e){
var ev = isIE?event:e;
//mapper.keyUp(ev.keyCode);
}
</script>
</html>