A library for creating Wolfenstein style games.
File: |
Raycaster.lib |
Version: |
1.4 |
Author: |
Marcus Johansson and John Master |
Details
Constants
Sub routines
With the raycasting library and the RC Editor program you can create 3D games in the style of Wolfenstein (the first one). If you want more control it is possible to create games without using the editor. You could have a look at the 'Raycaster maze generation' example if you're interested. If you are using RC Editor, you don't need to care much about most of the subroutines presented below, because 'RC_LoadMap' takes care of the setup for you.
A NaaLaa raycasting "world" should be seen as a grid of cubes, where the side of every cube is 1. The world is represented by a 2D map/array with a couple of "layers":
Array indexing |
||
Name |
Description | |
RC_X |
X coordinate. |
|
RC_Z |
Z coordinate. |
|
RC_ANGLE |
Angle. |
|
RC_FLAG |
Flag. |
|
Array indexes for collision info |
||
Name |
Description | |
RC_NORTH |
North. |
|
RC_SOUTH |
South. |
|
RC_WEST |
West. |
|
RC_EAST |
East. |
General |
|||
Name |
Parameters |
Brief description |
|
procedure |
fov#, renderW, renderH |
Init view. |
|
function |
filename$ |
Load map. |
|
function |
Get map width. |
||
function |
Get map height. |
||
procedure |
r, g, b, zMin#, zMax# |
Set fog. |
|
procedure |
w, h |
Init map. |
|
procedure |
xpos#, zpos#, angle#, bobEffect# |
Render view. |
|
procedure |
speed# |
Update raycaster. |
|
function |
index |
Get image from index. |
|
Collision handling |
|||
Name |
Parameters |
Brief description |
|
function |
dist#, xpos#, zpos#, dx#, dz# |
Move with collision handling. |
|
function |
Get collision information. |
||
function |
x, z |
Return true if position has an obstacle/wall. |
|
function |
x#, z#, angle# |
Return wall in front of position with respect to viewing angle. |
|
function |
x#, z#, angle# |
Return position in front of specified position with respect to viewing angle. |
|
function |
xpos#, zpos#, dstx#, dstz# |
Return true if there's no obstacle between two positions. |
|
Walls |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Get wall. |
|
function |
x, z |
Get wall image. |
|
procedure |
x, z, img |
Set wall image. |
|
Floor |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Get floor. |
|
function |
x, z |
Get floor image. |
|
procedure |
x, z, img |
Set floor image. |
|
Ceiling |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Get ceiling. |
|
function |
x, z |
Get ceiling image. |
|
procedure |
x, z, img |
Set ceiling image. |
|
Flags |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Get flag. |
|
function |
flag |
Get flag position. |
|
procedure |
x, z, flag |
Set flag value. |
|
Items |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Return item. |
|
procedure |
x, z, item, obstacle |
Set item value. |
|
procedure |
x, z |
Remove item. |
|
Objects |
|||
Name |
Parameters |
Brief description |
|
procedure |
id, img, x#, z#, y#, s#, ix, iz |
Add visual object. |
|
procedure |
id, img, x#, z#, y# |
Modify object. |
|
procedure |
id, img |
Set object image. |
|
procedure |
id, value |
Set additive property. |
|
procedure |
id, x#, z#, y# |
Set object position. |
|
procedure |
id |
Remove object. |
|
procedure |
Clear objects. |
||
function |
id |
Returns true if object exists. |
|
procedure |
currentImg, newImg |
Change image for multiple objects. |
|
Doors |
|||
Name |
Parameters |
Brief description |
|
function |
x, z |
Return door. |
|
function |
x, z |
Return true if door at position is closed. |
|
function |
x, z |
Return true if door at position is open. |
|
procedure |
x, z |
Open door at position. |
|
procedure |
x, z |
Close door at position. |
|
procedure |
x, z, type, img, alongZ |
Set door. |
|
procedure |
Clear doors. |
||
procedure |
speed# |
Set door speed. |
procedure RC_InitView ( fov#, renderW, renderH )Must be called once before 'RC_Render'.
[ Back ] |
function RC_LoadMap[][] ( filename$ )Load map created with RC_Editor. The returned array contains the starting position and angle set in the editor together with all set loader flags. The starting position is found at index 0 as [0][RC_X] and [0][RC_Z], and the angle at [0][RC_ANGLE]. The loader flags are stored as [n][RC_X], [n][RC_Z] and [n][RC_FLAG]. If the array is empty, the map could not be loaded.
Return value [ Back ] |
function RC_GetMapWidth ( )Get map width.
Return value [ Back ] |
function RC_GetMapHeight ( )Get map height.
Return value [ Back ] |
procedure RC_SetFog ( r, g, b, zMin#, zMax# )Sets fog properties and far clip plane.
[ Back ] |
procedure RC_InitMap ( w, h )Create a new map, only relevant if you're not using RC Editor.
[ Back ] |
procedure RC_Render ( xpos#, zpos#, angle#, bobEffect# )Renders world as if seen some the specified position and angle. @parap bobEffect Always set to zero.
[ Back ] |
procedure RC_Update ( speed# )This currently only has effect on door animations.
[ Back ] |
function RC_GetImage ( index )Return the image identifier for image at index from RC Editor.
Return value [ Back ] |
function RC_Move#[] ( dist#, xpos#, zpos#, dx#, dz# )Try move "something" from specified position. If no collision occured, the [RC_X] and [RC_Z] fields of the returned arry will be 'xpos + dx' and 'zpos + dz'.
Return value [ Back ] |
function RC_GetCollisionInfo[] ( )The fields [RC_EAST], [RC_WEST], [RC_NORTH] and [RC_SOUTH] in the returned array will be set to either true or false, indicating if collisions occured or not.
Return value [ Back ] |
function RC_ObstacleAt ( x, z )Return true if position has an obstacle/wall.
Return value [ Back ] |
function RC_FacingWall ( x#, z#, angle# )Return wall in front of position with respect to viewing angle.
Return value [ Back ] |
function RC_FacingPos[] ( x#, z#, angle# )Return position in front of specified position with respect to viewing angle.
Return value [ Back ] |
function RC_Visible ( xpos#, zpos#, dstx#, dstz# )Return true if there's no obstacle between two positions.
Return value [ Back ] |
function RC_GetWall ( x, z )Returns the wall at x, y. The returned value only makes sense if you're using the RC_Editor. It's the index of an image loaded in the editor, rather than the image identifier itself. You can use 'RC_GetImage' to convert the index to an image identifier.
Return value [ Back ] |
function RC_GetWallImage ( x, z )Get wall image.
Return value [ Back ] |
procedure RC_SetWall ( x, z, img )Set wall image.
[ Back ] |
function RC_GetFloor ( x, z )Returns the floor at x, y. The returned value only makes sense if you're using the RC_Editor. It's the index of an image loaded in the editor, rather than the image identifier itself. You can use 'RC_GetImage' to convert the index to an image identifier.
Return value [ Back ] |
function RC_GetFloorImage ( x, z )Get floor image.
Return value [ Back ] |
procedure RC_SetFloor ( x, z, img )Set floor image.
[ Back ] |
function RC_GetCeiling ( x, z )Returns the ceiling at x, y. The returned value only makes sense if you're using the RC_Editor. It's the index of an image loaded in the editor, rather than the image identifier itself. You can use 'RC_GetImage' to convert the index to an image identifier.
Return value [ Back ] |
function RC_GetCeilingImage ( x, z )Get ceiling image.
Return value [ Back ] |
procedure RC_SetCeiling ( x, z, img )Set ceiling image.
[ Back ] |
function RC_GetFlag ( x, z )Get flag.
Return value [ Back ] |
function RC_GetFlagPos[] ( flag )Returns position of the first founc occurance of a flag.
Return value [ Back ] |
procedure RC_SetFlag ( x, z, flag )Set flag value.
[ Back ] |
function RC_GetItem ( x, z )Return item.
Return value [ Back ] |
procedure RC_SetItem ( x, z, item, obstacle )When loading a map from RC Editor, visual objects are automaticly connected to items. This procedure does no such thing.
[ Back ] |
procedure RC_RemoveItem ( x, z )Removes item at specified position. Also remove any connected visual object.
[ Back ] |
procedure RC_AddObject ( id, img, x#, z#, y#, s#, ix, iz )Add a visual object to the world. An object is just an image with a position and size. If an object with the same id already exists, it will be replaced. Worth noting is the objects y position. If set to 0, the object will stand on the floor. If set to 1.0 - "the objects height", the object will hang from the ceiling. The object can be automaticly removed when an item at the specified position is removed. Set 'ix' and 'iz' to -1 if you're uninterested in this behaviour.
[ Back ] |
procedure RC_ModifyObject ( id, img, x#, z#, y# )Modify object.
[ Back ] |
procedure RC_SetObjectImage ( id, img )Set object image.
[ Back ] |
procedure RC_SetObjectAdditive ( id, value )Set additive property.
[ Back ] |
procedure RC_SetObjectPos ( id, x#, z#, y# )Set object position.
[ Back ] |
procedure RC_RemoveObject ( id )Remove object.
[ Back ] |
procedure RC_ClearObjects ( )Remove all added visual objects. [ Back ] |
function RC_HasObject ( id )Returns true if object exists.
Return value [ Back ] |
procedure RC_ObjChangeImages ( currentImg, newImg )Changes image from 'currentImg' to 'newImg' for all objects that use it.
[ Back ] |
function RC_GetDoor ( x, z )Return the door at specified position. The returned value only makes sense if you're using RC Editor. It's the index of an image loaded in the editor. You can use 'RC_GetImage' to convert the index to an image id.
Return value [ Back ] |
function RC_DoorClosed ( x, z )Return true if door at position is closed.
Return value [ Back ] |
function RC_DoorOpen ( x, z )Return true if door at position is open.
Return value [ Back ] |
procedure RC_OpenDoor ( x, z )Open door at position.
[ Back ] |
procedure RC_CloseDoor ( x, z )Close door at position.
[ Back ] |
procedure RC_SetDoor ( x, z, type, img, alongZ )
[ Back ] |
procedure RC_ClearDoors ( )Clear doors. [ Back ] |
procedure RC_SetDoorSpeed ( speed# )Set movement speed of doors opening/closing. A door's movement parameter is in the range [0..1], and it's updated once every time you call 'RC_Update'.
[ Back ] |
Generated with NLDoc 20160611.