-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
254 lines (201 loc) · 10.5 KB
/
index.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Phaser-islandjs-plugin by luckylooke</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
<!-- highlight.js theme -->
<link rel="stylesheet" type="text/css" href="stylesheets/github.css" media="screen">
</head>
<body>
<section class="page-header">
<h1 class="project-name">Phaser-islandjs-plugin</h1>
<h2 class="project-tagline">Phaser.io plugin for procedural generation and rendering island maps<br/><small>based on island.js (<a href="https://github.com/lebesnec/island.js">https://github.com/lebesnec/island.js</a>)</small></h2>
<a href="https://github.com/luckylooke/phaser-islandjs-plugin" class="btn">View on GitHub</a>
<a href="https://github.com/luckylooke/phaser-islandjs-plugin/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/luckylooke/phaser-islandjs-plugin/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<p>Island map generator in JavaScript, using a Voronoi graph and perlin noise provided as <a href="phaser.io">Phaser.io</a> plugin.</p>
<ul>
<li>Inspired by <a href="http://www-cs-students.stanford.edu/%7Eamitp/game-programming/polygon-map-generation/">http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/</a>
</li>
<li>Use Raymond Hill Voronoi implementation : <a href="http://github.com/gorhill/Javascript-Voronoi">http://github.com/gorhill/Javascript-Voronoi</a>
</li>
<li>Use Sean McCullough perlin noise generator (modified!) : <a href="http://gist.github.com/banksean/304522#file-perlin-noise-simplex-js">http://gist.github.com/banksean/304522#file-perlin-noise-simplex-js</a>
</li>
</ul>
<h3><a id="dependencies" class="anchor" href="#dependencies" aria-hidden="true"><span class="octicon octicon-link"></span></a>Dependencies</h3>
<ul>
<li>Phaser game framework <a href="phaser.io">phaser.io</a>
</li>
<li>Raymond Hill Voronoi implementation : <a href="http://github.com/gorhill/Javascript-Voronoi">http://github.com/gorhill/Javascript-Voronoi</a>
</li>
<li>Modified Sean McCullough perlin noise generator : <a href="http://github.com/luckylooke/phaser-islandjs-plugin/blob/master/src/plugin/perlin.js">http://github.com/luckylooke/phaser-islandjs-plugin/blob/master/src/plugin/perlin.js</a>
</li>
</ul>
<h3><a id="demo" class="anchor" href="#demo" aria-hidden="true"><span class="octicon octicon-link"></span></a>DEMO</h3>
<p>Reload page to see another generated island.</p>
</section>
<div id="phaser-game"></div>
<canvas id="perlin" hidden="true"></canvas>
<section class="main-content">
<!-- ------------------------------------------------------------------------------------------------------------------------------------------------------------------ -->
<h3><a id="usage" class="anchor" href="#usage" aria-hidden="true"><span class="octicon octicon-link"></span></a>Usage</h3>
<p>Dependency files and plugin file need to be loaded before main game code</p>
<pre><code>
<script src="lib/phaser.js"></script>
<script src="lib/rhill-voronoi-core.min.js"></script>
<script src="plugin/perlin.js"></script>
<script src="plugin/PhaserIslandjsPlugin.js"></script>
<script src="game.js"></script>
</code></pre>
<p>You need hidden canvas in your page for creating perlin noise</p>
<pre><code>
<canvas id="perlin" hidden="true"></canvas>
</code></pre>
<p>In your game create function</p>
<pre><code>
var island = this.game.plugins.add(Phaser.Plugin.Island, {
// custom settings
width: 500,
height: 500,
perlinWidth: 256,
perlinHeight: 256,
allowDebug: false, // if set to true, you can click on the map to enter "debug" mode. Warning : debug mode is slow to initialize, set to false for faster rendering.
nbSites: 10000, // numbers of voronoi cell
sitesDistribution: 'hexagon', // distribution of the site of the voronoi graph : random, square or hexagon
sitesRandomisation: 80, // will move each site in a random way (in %), for the square or hexagon distribution to look more random
nbGraphRelaxation: 0, // nb of time we apply the relaxation algo to the voronoi graph (slow !), for the random distribution to look less random
cliffsThreshold: 0.15,
lakesThreshold: 0.005, // lake elevation will increase by this value (* the river size) when a new river end inside
nbRivers: (10000 / 200),
maxRiversSize: 4,
// seed: 168165168, // randomization can be seeded
shadeOcean: true
});
// You can change colors before rendering
island.DISPLAY_COLORS.OCEAN = '#4488ff';
// Start rendering
island.renderNow();
</code></pre>
<!-- ------------------------------------------------------------------------------------------------------------------------------------------------------------------ -->
<h3><a id="demo" class="anchor" href="#demo" aria-hidden="true"><span class="octicon octicon-link"></span></a>DEMO - debug=true</h3>
<p>Try to click on the map, you will get extra debug info from cell.</p>
</section>
<div id="phaser-game-debugger"></div>
<section class="main-content">
<p>Used code for debuged DEMO</p>
<pre><code>
function create(){
var island = this.game.plugins.add(Phaser.Plugin.Island, {
nbSites: 100,
perlinWidth: this.game.width/2,
perlinHeight: this.game.height/2,
allowDebug: true
});
island.renderNow();
this.game.input.onDown.add(function click(pointer) {
island.renderSite(island.cellIdFromPoint(pointer.x, pointer.y));
});
}
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'phaser-game-debugger', {create: create});
</code></pre>
<!-- ------------------------------------------------------------------------------------------------------------------------------------------------------------------ -->
<h3><a id="demo" class="anchor" href="#demo" aria-hidden="true"><span class="octicon octicon-link"></span></a>DEMO - cellular automata</h3>
<p>
Would you like to cellular automata on island map cells? Good news,
I have rewritten <a href="http://sanojian.github.io/cellauto/">cellauto.js lib</a> by <a href="http://github.com/sanojian">Jonas Olmstead</a>
to <a href="http://gist.github.com/luckylooke/85b0aa072ad8e95f2cef">cellautoVoronoi.js</a> version which can be used here.
You can click on cave icon in first demo above to see it in action. I have used cave example from <a href="http://sanojian.github.io/cellauto/">cellauto.js demo page</a>.
Every click is one step. If you want to restart example, just reload page.
</p>
<p>Used code for cave demo</p>
<pre><code>
function preload(){
this.load.image('cave', 'src/assets/cave.png');
}
function create(){
var island = this.game.plugins.add(Phaser.Plugin.Island, {
// custom settings
perlinWidth: this.game.width/2,
perlinHeight: this.game.height/2
});
// island.DISPLAY_COLORS.OCEAN = '#4444ff';
island.renderNow();
function example_caves() {
var cells = island.diagram.cells,
world = new CAVWorld(cells);
world.registerCellType('wall', {
process: function (cellVoronoi) {
var neighbors = cellVoronoi.neighborsCache || island.getNeighbors(cellVoronoi.site.voronoiId),
surrounding = this.countSurroundingCellsWithValue(neighbors, 'wasOpen');
this.open = (this.wasOpen && surrounding >= 3) || surrounding >= 5;
},
reset: function () {
this.wasOpen = this.open;
}
}, function () {
//init
this.open = Math.random() > 0.40;
});
world.initialize([
{ name: 'wall', distribution: 100 }
]);
return world;
}
var test = example_caves();
var testBtnFn = function() {
test.step();
console.log('testBtnFn');
for (var i = 0; i < test.voronoiCells.length; i++) {
var cell = test.voronoiCells[i],
ctx = island.debugLayer.ctx,
borders = cell.bordersCache || island.getBorders(cell.site.voronoiId),
bLength = borders.length, y;
ctx.fillStyle = cell.ca.open ? '#fff' : '#000';
ctx.beginPath();
ctx.moveTo(borders[0].x,borders[0].y);
for (y = 1; y < bLength; y++) {
ctx.lineTo(borders[y].x,borders[y].y);
}
ctx.closePath();
ctx.fill();
}
island.debugLayer.dirty = true;
};
var button = this.game.add.button(95, 400, 'cave', testBtnFn, this, 2, 1, 0);
button.fixedToCamera = true;
button.cameraOffset.setTo(10, 30);
}
new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'phaser-game', {create: create, preload:preload});
</code></pre>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/luckylooke/phaser-islandjs-plugin">Phaser-islandjs-plugin</a> is maintained by <a href="https://github.com/luckylooke">luckylooke</a>.</span>
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
</footer>
</section>
<script src="src/lib/phaser.js"></script>
<script src="src/lib/highlight.pack.js"></script>
<script src="src/lib/rhill-voronoi-core.min.js"></script>
<script src="src/lib/cellautoVoronoi.js"></script>
<script src="src/plugin/perlin.js"></script>
<script src="src/plugin/PhaserIslandjsPlugin.js"></script>
<script src="src/game.js"></script>
<script type="text/javascript">
/* global hljs */
hljs.initHighlightingOnLoad();
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
/* global _gat */
try {
var pageTracker = _gat._getTracker("UA-63917744-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>