fenomas / noa

Experimental voxel game engine.
MIT License
608 stars 86 forks source link

Limit world size? #165

Closed itzTheMeow closed 2 years ago

itzTheMeow commented 2 years ago

Is there a way to limit the world size to like 64x64x64 or 128x64x128?

fenomas commented 2 years ago

Hi, at the data level the world is (sorta) infinite, but you can define the world data to be empty beyond a certain size, or solid blocks beyond some boundary, in order to limit the player to a given area. Is that what you mean?

itzTheMeow commented 2 years ago

yes that's what i mean, i could make it transparent blocks outside so you can not move out, but wouldn't the blocks still show up as selected when you look at them?

itzTheMeow commented 2 years ago

that also wouldn't limit building outside of the area

recon-cyber commented 2 years ago

check this https://github.com/moddio/box .

We are limiting the size of the map in world.js

fenomas commented 2 years ago

yes that's what i mean, i could make it transparent blocks outside so you can not move out, but wouldn't the blocks still show up as selected when you look at them?

There's no built-in setting for area limits, but the engine should have all the tools you need to set whatever rules you want to happen.

For blocking player movement, the easiest thing will be solid transparent blocks, as I imagine you've already tried. To make those blocks not selectable, check the engine's default block-target highlight function. By default it just draws a highlight whenever the target block is solid, but if you set the skipDefaultHighlighting option then the engine won't do any highlighting, and you can add your own targetBlockChanged listener that draws highlights as you like (e.g. skipping the highlight if the target is your invisible barrier block).

As for building, the engine has no built-in behaviors for this. It has APIs for creating/destroying blocks, and it fires events when the player clicks the mouse, but how your game links those together is up to you. Here is the handler from the hello-world example where it creates blocks on mouse events, so you could use code like that but with added logic to disallow building outside certain regions, etc.

itzTheMeow commented 2 years ago

alright, thanks