fenomas / noa

Experimental voxel game engine.
MIT License
616 stars 91 forks source link

How do I change the options for the player? #80

Closed EliteAsian123 closed 5 years ago

EliteAsian123 commented 5 years ago

How do I change the options of the player like whether if it can double jump?

Pandawan commented 5 years ago

Hey, this is all done through noa's entity component system. You'll see that noa has a playerEntity property; this will give you the id of the player entity. From that, you can access the player's components and states through noa.entities.

For example, you can modify the number of jumps the player can do like so:

// Get the player's movement state
const movementState = noa.entities.getMovement(noa.playerEntity);

// Don't allow double jumps
movementState.airJumps = 0;

// Allow one air jump (double jump)
movementState.airJumps = 1;

// Allow two air jumps (triple jump)
movementState.airJumps = 2;

Hope that helps!

fenomas commented 5 years ago

I'll just add - many settings can be passed in as properties on the options object, but adding a setting for max air jumps is one I haven't gotten around to yet. But yeah, the runtime value for all entity settings lives in state objects in the ECS.

EliteAsian123 commented 5 years ago

Thanks for the answer! It work perfectly. Have a good day!