Levels
#include <macawlevel.h>These calls come from #include <macawlevel.h>. They let a C program open, draw, walk round and even build the levels you make in Brushwork, the level editor. A level is a number: openlevel, loadlevel and newlevel each give you one, and 0 means it didn't work. They work the same way as Lua's level calls, which Levels explains in more detail, and C tells you about C on Macaw OS.
A few things to know
- A level has two halves. Its table is what's in the
.lvlfile: its brushes, entities and settings. Its built level is that table made into something that draws and that you can bump into.openlevelgives you both;loadlevelandnewlevelgive you only the table until you callbuildlevel. - A brush is a solid convex shape, like a box or a wedge, that the level is made of. An entity is a thing at a place in the level, such as a lamp, the player start or a pickup.
- Everything counts from 0: the first brush, the first water, the first face.
- A path that doesn't start with
/is taken from your program's folder. - Calls that give text copy it into a buffer you pass, cut to fit with a 0 on the end, and return the length of the whole text, so you can tell when your buffer was too small.
- Asking a level that isn't built yet to draw or collide is an error, and your program stops with a message. So is using a brush, entity, water or probe that isn't there, except in the calls whose entries say they return 0 for one that isn't there.
The structs
levelcam is a camera, for water and reflection probes:
x,y,z: where the camera is, in the level's units.yaw: which way it turns, in degrees (0 looks along +z, 90 along +x).pitch: how far it looks up, in degrees (negative looks down).fov: how wide it sees, in degrees (0 or less means 90).
levelviewfn is the type of a function you write for water and probes to call. They call it when they need the view from a camera drawn: a mirrored camera under the water for a reflection, or one of the six views round a probe. Your function sets camera3d to the camera and draws the level above the height it's given (with leveldrawabove(level, above)), plus anything else that should show. It returns nothing. Where a call takes one, you can pass NULL, and then it draws just the level. Its arguments are:
c: the camera to draw from, alevelcam. It's only there during the call, so don't keep the pointer.above: the height of the water, so you can leave out what's under it; for a probe it's -1e30, which means draw everything.user: whatever pointer you gave the call that takes your function, passed back unchanged.
levellightinfo is a lamp or an area light, as levellight gives them and levelbake takes them. An area light is a glowing rectangle that lights one way.
x,y,z: where it is (for an area light, its middle).bright: how bright it is (a lamp is 1.2 and an area light 1.5 if the level doesn't say).radius: how far its light reaches (12 if the level doesn't say).r,g,b: its colour, each from 0 to 1.soft: a lamp's size, so how soft its shadows are (0 is hard; -1 means use the bake's softness).area: 1 for an area light, 0 for a lamp.w,h: an area light's size across.facing: which way an area light faces:LIGHT_DOWN(0),LIGHT_UP(1),LIGHT_PX(+x, 2),LIGHT_NX(-x, 3),LIGHT_PZ(+z, 4) orLIGHT_NZ(-z, 5).
Modules
- Opening, saving and building
openlevel,loadlevel,newlevel,savelevel,buildlevel,freeleveland more- Drawing
- These draw a built level with
camera3d's camera, unless they say otherwise. - Bumping into it
- These work on a built level.
- Water
- In Brushwork you can make brushes into water.
- Reflection probes
- A shiny surface reflects the nearest reflection probe: a point in the level whose view all round is baked into a cube map (six square pictures, one each way).
- What's in a level
- These read the level's table, so they work before it's built too.
- Entities
- Each entity has a class, its kind, such as
"pickup"or"start", and fields with values. - Kinds of entity
- These tell you about the classes a level can have: Macaw OS's own (light, arealight, start, probe), the generic ones (marker, pickup, enemy, trigger, sound, sign) and a game's own, from an
entities.luain the level's folder or a folder above it. - Building from code: brushes
- These change a level's table.
- Building from code: entities and settings
leveladdentity,levelremoveentity,levelmoveentity,levelentitysetnum,levelentitysettext,levelentitysetbooland more- Skies and textures
levelskies,levelsky,leveltexture,leveltexturename- Baking light and the built level
- Baking light works out how the level's lamps, glowing faces and sky light every surface, bounces and shadows included, and keeps the result.