-
Notifications
You must be signed in to change notification settings - Fork 13
/
05-infinite-forest.html
70 lines (61 loc) · 2.29 KB
/
05-infinite-forest.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Infinite Forest</title>
<link href="../unicodetiles/unicodetiles.css" rel="stylesheet" type="text/css" />
<link href="../docs/style.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="../unicodetiles/unicodetiles.js"></script>
<script src="../unicodetiles/ut.WebGLRenderer.js"></script>
<script src="../unicodetiles/ut.CanvasRenderer.js"></script>
<script src="../unicodetiles/ut.DOMRenderer.js"></script>
<script src="../unicodetiles/input.js"></script>
<script src="renderer-switcher.js"></script>
<!-- We are extending the simple-dungeon example -->
<script src="simple-dungeon.js"></script>
<!-- We are extending the fov-dungeon example -->
<script src="fov.js"></script>
<script>
// Poor pseudo random number generator
var A = 2971215073, B = 479001599, M = 1048573;
function rand(x, y) {
var num = ((A*x)^(B*y)) % M;
return num / M;
}
var GRASS = new ut.Tile(".", 80, 150, 80);
var GRASS2 = new ut.Tile(".", 90, 250, 90);
var TREE = new ut.Tile("☘", 20, 100, 20);
var ROCK = new ut.Tile("☁", 100, 100, 100);
// Uses deterministic randomness to return a tile based on the coordinates
function getForestTile(x, y) {
var r = rand(Math.round(x), Math.round(y));
if (r > 0.80) return TREE;
if (r > 0.75) return ROCK;
if (r > 0.50) return GRASS2;
return GRASS;
}
// Initializes the forest
function initForest() {
// Eng is already constructed by initSimpleDungeon(),
// so we swap the tile function to the new one here
eng.setTileFunc(getForestTile);
// Enable tile cache for possibly improved performance
eng.setCacheEnabled(true);
// We want infinite world so we set the size to undefined
eng.w = undefined;
eng.h = undefined;
}
</script>
</head>
<body onload="initSimpleDungeon(); createRendererSwitcher(); initFOV(); initForest();">
<p class="centerer">Move around with arrow keys.</p>
<div class="centerer">
<div id="game">Enable JavaScript and reload the page.</div>
</div>
<div class="centerer" id="renderer-switcher">
<!-- Populated by renderer-switcher.js -->
</div>
<a class="backlink" href="index.html"><-- Back to index</a>
</body>
</html>