Skip to content

Commit fed72e7

Browse files
committed
Adds infinite tile generation to demo
Adds stub for game `mode` in demo Updates ReadMe
1 parent a005022 commit fed72e7

File tree

3 files changed

+96
-22
lines changed

3 files changed

+96
-22
lines changed

ReadMe.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ import labyrinthos from 'labyrinthos';
168168
// Main map - 8x8 = 64 tiles
169169
const mainMap = new labyrinthos.TileMap({ width: 8, height: 8 });
170170

171-
// Submaps - 4x4 = 16 tiles each
171+
// Sub maps - 4x4 = 16 tiles each
172172
const subMap1 = new labyrinthos.TileMap({ width: 4, height: 4 });
173173
const subMap2 = new labyrinthos.TileMap({ width: 4, height: 4 });
174174
const subMap3 = new labyrinthos.TileMap({ width: 4, height: 4 });

examples/browser/demo.js

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
let previousSeed = null;
22
let urlSeed = null;
33
let map;
4+
let infinite = false;
5+
let mode = 'topdown';
46
$(document).ready(function () {
57

68

@@ -63,6 +65,13 @@ $(document).ready(function () {
6365
generateMap(map.mersenneTwister.currentSeed); // Adjust if generateMap needs specific arguments
6466
});
6567

68+
$('#generateChunks').change(function () {
69+
generateMap(map.mersenneTwister.currentSeed);
70+
});
71+
72+
$('input[name="mapModePhysics"]').change(function () {
73+
generateMap(map.mersenneTwister.currentSeed);
74+
});
6675

6776
/*
6877
// when clicking on mapContainer, generate a new map
@@ -84,6 +93,17 @@ $(document).ready(function () {
8493
let height = searchParams.get('height');
8594
let depth = searchParams.get('depth');
8695
let algo = searchParams.get('algo');
96+
97+
let _infinite = searchParams.get('infinite'); // chunks or no chunks
98+
let _mode = searchParams.get('mode'); // topdown or platformer
99+
100+
if (_infinite == 'true') {
101+
infinite = true;
102+
}
103+
if (_mode == 'platformer') {
104+
mode = 'platformer';
105+
}
106+
87107
if (width) {
88108
$('#mapWidth').val(width);
89109
}
@@ -157,13 +177,17 @@ $(document).ready(function () {
157177
generateMap(previousSeed);
158178
});
159179

180+
$('.gameSettings').click(function () {
181+
$('.gameSettingsMessage').show();
182+
});
183+
160184
$('.mantraTiled').click(function () {
161185
let id = $(this).attr('id');
162186
// takes the current tileMap.data and opens a link to
163187
// the mantra Tiled world with tiledata?=tileMap.data
164188
let host = 'https://yantra.gg/mantra/tiled';
165189
// for dev mode
166-
// host = 'http://192.168.1.80:7777/tiled.html'
190+
host = 'http://192.168.1.80:7777/tiled.html'
167191

168192

169193
// instead of sending entire TiledMap format, we will instead send metadata about `TileMap` with seed
@@ -179,6 +203,11 @@ $(document).ready(function () {
179203
};
180204

181205

206+
207+
tileMapData.infinite = infinite;
208+
tileMapData.mode = mode;
209+
210+
182211
let queryString = '?s=labyrinthos';
183212

184213
// convert tileMapData to query string
@@ -371,7 +400,6 @@ $(document).ready(function () {
371400
}, map, {});
372401
*/
373402
$('#stackingModeSelection').toggle(false);
374-
375403
generators[generatorType](map, {});
376404
if (LABY.terrains[generatorType]) {
377405
map.scaleToTileRange(4);
@@ -403,6 +431,23 @@ $(document).ready(function () {
403431
searchParams.set(prop, map[prop]);
404432
}
405433

434+
let _infinite = $('#generateChunks').is(':checked');
435+
if (_infinite === true || _infinite === 'true') {
436+
infinite = true;
437+
searchParams.set('infinite', 'true');
438+
} else {
439+
infinite = false;
440+
searchParams.set('infinite', 'false');
441+
}
442+
443+
let _mode = $('input[name="mapModePhysics"]:checked').val();
444+
if (_mode === 'topdown' || _mode === 'platformer') {
445+
mode = _mode;
446+
searchParams.set('mode', mode);
447+
} else {
448+
searchParams.set('mode', 'topdown');
449+
}
450+
406451
searchParams.set('algo', algo);
407452

408453
//searchParams.set('map', map.toJSON());

examples/index.html

+48-19
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88
<script src="https://yantra.gg/labyrinthos/browser/vendor/jquery.min.js"></script>
99
<script src="https://yantra.gg/labyrinthos/browser/vendor/jszip.min.js"></script>
10-
<meta name="description"
11-
content="A JavaScript procedural generator for Mazes, Terrains, and Biomes">
10+
<meta name="description" content="A JavaScript procedural generator for Mazes, Terrains, and Biomes">
1211
<script src="./browser/labyrinthos.js"></script>
1312
<script src="./browser/demo.js"></script>
1413

@@ -118,6 +117,7 @@
118117
padding-bottom: 0px;
119118
padding-top: 0px;
120119
}
120+
121121
label {
122122
color: #3652AD;
123123
font-size: 24px;
@@ -201,6 +201,11 @@
201201
min-width: 280px;
202202
}
203203

204+
.gameSettingsMessage {
205+
display: none;
206+
padding: 10px;
207+
font-size: 18px;
208+
}
204209

205210
button {
206211
padding: 12px 30px;
@@ -345,11 +350,8 @@
345350
/* Reset order to ensure natural HTML flow */
346351
}
347352

348-
select,
349-
button,
350-
.mapSettings {
351-
/* Adjust font size for readability */
352-
}
353+
354+
353355

354356
#mapContainer {
355357
font-size: 24px;
@@ -387,8 +389,10 @@ <h2>A JavaScript procedural generator for Mazes, Terrains, and Biomes</h2>
387389
<button id="nextAlgo" title="Next algorithm">&gt;</button>
388390

389391
<button id="generateMap" title="Generate new map and random seed">Generate Map</button>
390-
<button class="mantraTiled" id="mantra2DTiled" title="View Map using Mantra.js CSSGraphics">Explore in 2D</button>
391-
<button class="mantraTiled" id="mantra3DTiled" title="View Map using Mantra.js 3D Graphics">Explore in 3D</button>
392+
<button class="mantraTiled" id="mantra2DTiled" title="View Map using Mantra.js CSSGraphics">Explore in
393+
2D</button>
394+
<button class="mantraTiled" id="mantra3DTiled" title="View Map using Mantra.js 3D Graphics">Explore in
395+
3D</button>
392396

393397
<div id="mapContainer"></div>
394398

@@ -405,7 +409,7 @@ <h2>A JavaScript procedural generator for Mazes, Terrains, and Biomes</h2>
405409
</label>
406410
</div>
407411
</div>
408-
412+
409413
<br />
410414

411415
<div class="boxer">
@@ -416,7 +420,7 @@ <h2>A JavaScript procedural generator for Mazes, Terrains, and Biomes</h2>
416420
<label for="mapHeight">Map Height
417421
<input class="mapSettings" id="mapHeight" type="number" value="16" />
418422
</label>
419-
<br/>
423+
<br />
420424
<!-- Depth Input for 3D Mode (Initially Hidden) -->
421425
<label for="mapDepth" style="display:none;">Map Depth
422426
<input class="mapSettings" id="mapDepth" type="number" value="1" />
@@ -438,20 +442,44 @@ <h2>A JavaScript procedural generator for Mazes, Terrains, and Biomes</h2>
438442
<label for="mapSizeLarge">Large
439443
<input type="radio" id="mapSizeLarge" name="mapSize" value="large">
440444
</label>
445+
<br />
446+
<label for="mapMode2d">2D
447+
<input type="radio" id="mapMode2d" name="mapMode" value="2d" checked>
448+
</label>
449+
<label for="mapMode3d">3D
450+
<input type="radio" id="mapMode3d" name="mapMode" value="3d">
451+
</label>
441452
</div>
442453
<br />
443454
<!-- Map Size select -->
444455
<div class="boxer">
445456

446457
<!-- Map Mode Selection -->
447458
<div>
448-
<label for="mapMode2d">2D
449-
<input type="radio" id="mapMode2d" name="mapMode" value="2d" checked>
459+
460+
<!--
461+
462+
<br />
463+
<label class="gameSettings" for="mapModePhysicsTop" title="Top-Down Physics with zero gravity">Top-Down
464+
<input type="radio" id="mapModePhysicsTop" name="mapModePhysics" value="top-down" checked>
450465
</label>
451-
<label for="mapMode3d">3D
452-
<input type="radio" id="mapMode3d" name="mapMode" value="3d">
466+
<label class="gameSettings" for="mapModePhysicsPlatform" title="Platformer style physics with gravity">Platformer
467+
<input type="radio" id="mapModePhysicsPlatform" name="mapModePhysics" value="platformer">
468+
</label>
469+
-->
470+
471+
<br />
472+
<br />
473+
474+
<label class="gameSettings" for="generateChunks"
475+
title="When enabled the TileMap will extend to infinity using coordinate chunks as random seed values to your algorithm.">Procedurally
476+
Generate Chunks
477+
<input type="checkbox" id="generateChunks" name="generateChunks" value="false">
453478
</label>
454479

480+
<div class="gameSettingsMessage">You must explore map to see these changes.</div>
481+
482+
455483
<!-- Stacking Mode Selection for 3D Maps -->
456484
<div id="stackingModeSelection" style="display:none;"> <!-- Initially hidden -->
457485
<label for="stackingModeUnique" title="Each layer of the 3D will be unique instance of 2D algo.">Unique
@@ -484,13 +512,14 @@ <h2>A JavaScript procedural generator for Mazes, Terrains, and Biomes</h2>
484512
<br />
485513

486514
<div class="boxer">
487-
<a href="https://discord.gg/hw9VvWPJqN" target="_blank" id="discordLink"><img width="60" src="./browser/img/discord-voice.png"/></a>
515+
<a href="https://discord.gg/hw9VvWPJqN" target="_blank" id="discordLink"><img width="60"
516+
src="./browser/img/discord-voice.png" /></a>
517+
<br />
518+
<a class="chatLink link" target="_blank" href="https://discord.gg/hw9VvWPJqN"> Chat</a>
488519
<br />
489-
<a class="chatLink link" target="_blank" href="https://discord.gg/hw9VvWPJqN"> Chat</a>
490-
<br/>
491520

492521
</div>
493-
522+
494523
</div>
495524
<!-- TODO:
496525
<div>

0 commit comments

Comments
 (0)