p5.raycaster
Version:
a simple p5js library for semi 3d rendering with ray casting
2,294 lines (586 loc) • 28.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: World</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: World</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>World<span class="signature">(width<span class="signature-attributes">opt</span>, height<span class="signature-attributes">opt</span>, data<span class="signature-attributes">opt</span>, textureMap<span class="signature-attributes">opt</span>, skyBox<span class="signature-attributes">opt</span>, typeTable<span class="signature-attributes">opt</span>, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="World"><span class="type-signature"></span>new World<span class="signature">(width<span class="signature-attributes">opt</span>, height<span class="signature-attributes">opt</span>, data<span class="signature-attributes">opt</span>, textureMap<span class="signature-attributes">opt</span>, skyBox<span class="signature-attributes">opt</span>, typeTable<span class="signature-attributes">opt</span>, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>width</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
24
</td>
<td class="description last">integer indicating the width of the world (number of block)</td>
</tr>
<tr>
<td class="name"><code>height</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
24
</td>
<td class="description last">integer indicating the height of the world (number of block)</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">block data for the world, e.g. "0,1,0,0,0,0,1,2,0,0,0,0...", can be an array of integer instead]</td>
</tr>
<tr>
<td class="name"><code>textureMap</code></td>
<td class="type">
<span class="param-type">Map</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">[[0, texture], [1, texture], ...]</td>
</tr>
<tr>
<td class="name"><code>skyBox</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
World.defaultSkyBox
</td>
<td class="description last">sky box
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sky</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">a string notation of color or a p5.Image object</td>
</tr>
<tr>
<td class="name"><code>ground</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">a string notation of color or a p5.Image object</td>
</tr>
<tr>
<td class="name"><code>front</code></td>
<td class="type">
<span class="param-type">p5.Image</span>
</td>
<td class="description last">can be a p5.Graphics object</td>
</tr>
<tr>
<td class="name"><code>middle</code></td>
<td class="type">
<span class="param-type">p5.Image</span>
</td>
<td class="description last">can be a p5.Graphics object</td>
</tr>
<tr>
<td class="name"><code>back</code></td>
<td class="type">
<span class="param-type">p5.Image</span>
</td>
<td class="description last">can be a p5.Graphics object</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>typeTable</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
World.defaultTypeTable
</td>
<td class="description last">block type table to interpret the data, default to the default table</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>doorSpeed</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">how fast the door open and close, default to 0.01;</td>
</tr>
<tr>
<td class="name"><code>doorAutoClose</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="description last">will the door close by it self, default to false;</td>
</tr>
<tr>
<td class="name"><code>doorClosingTime</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">if doorAutoClose is true, define how long the door will be open</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line46">line 46</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addSprite"><span class="type-signature"></span>addSprite<span class="signature">(sprite)</span><span class="type-signature"></span></h4>
<div class="description">
add a sprite to the world
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sprite</code></td>
<td class="type">
<span class="param-type"><a href="Sprite.html">Sprite</a></span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line180">line 180</a>
</li></ul></dd>
</dl>
<h4 class="name" id="closeDoor"><span class="type-signature"></span>closeDoor<span class="signature">(x, y)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">x coordinate of the block</td>
</tr>
<tr>
<td class="name"><code>y</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">y coordinate of the block</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line265">line 265</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadCeiling"><span class="type-signature"></span>loadCeiling<span class="signature">(ceilingMapData)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>ceilingMapData</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">or a 1D/2D array, or a single number indicating the texture for all blocks</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line140">line 140</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadFloor"><span class="type-signature"></span>loadFloor<span class="signature">(floorMapData)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>floorMapData</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">or a 1D/2D array, or a single number indicating the texture for all blocks</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line108">line 108</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadMap"><span class="type-signature"></span>loadMap<span class="signature">(data, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">block data for the world separated by comma, can be an array of integer instead</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>doorSpeed</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">how fast the door open and close, default to 0.1;</td>
</tr>
<tr>
<td class="name"><code>doorAutoClose</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="description last">will the door close by it self, default to false;</td>
</tr>
<tr>
<td class="name"><code>doorClosingTime</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">if doorAutoClose is true, define how long the door will be open</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line66">line 66</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadTextureMap"><span class="type-signature"></span>loadTextureMap<span class="signature">(textureMap)</span><span class="type-signature"></span></h4>
<div class="description">
this function will not copy the Map
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>textureMap</code></td>
<td class="type">
<span class="param-type">Map</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line172">line 172</a>
</li></ul></dd>
</dl>
<h4 class="name" id="moveDoor"><span class="type-signature"></span>moveDoor<span class="signature">(x, y)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">x coordinate of the block</td>
</tr>
<tr>
<td class="name"><code>y</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">y coordinate of the block</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line279">line 279</a>
</li></ul></dd>
</dl>
<h4 class="name" id="openDoor"><span class="type-signature"></span>openDoor<span class="signature">(x, y)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">x coordinate of the block</td>
</tr>
<tr>
<td class="name"><code>y</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">y coordinate of the block</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line251">line 251</a>
</li></ul></dd>
</dl>
<h4 class="name" id="removeSprite"><span class="type-signature"></span>removeSprite<span class="signature">(spriteIdx)</span><span class="type-signature"></span></h4>
<div class="description">
remove a sprite
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>spriteIdx</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">index of the sprite in the sprites array or the sprite itself</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line192">line 192</a>
</li></ul></dd>
</dl>
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(frameRate<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
update the state of the doors and push walls
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>frameRate</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
30
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="World.js.html">World.js</a>, <a href="World.js.html#line213">line 213</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Camera.html">Camera</a></li><li><a href="KeyboardControl.html">KeyboardControl</a></li><li><a href="MouseControl.html">MouseControl</a></li><li><a href="PointerLockControl.html">PointerLockControl</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="TransparentWall.html">TransparentWall</a></li><li><a href="Util.html">Util</a></li><li><a href="World.html">World</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createCamera">createCamera</a></li><li><a href="global.html#createSkyBox">createSkyBox</a></li><li><a href="global.html#createSprite">createSprite</a></li><li><a href="global.html#createTextureMap">createTextureMap</a></li><li><a href="global.html#createWorld">createWorld</a></li><li><a href="global.html#initKeyboardControl">initKeyboardControl</a></li><li><a href="global.html#initMouseControl">initMouseControl</a></li><li><a href="global.html#initPointerLockControl">initPointerLockControl</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Feb 01 2024 12:26:09 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>