I've posted a bunch of functions here. Even if you find them useless, they're here. They have been tested in DBPro, not DBC. But some may work in DBC.
EDIT: Okay I've added a DBA file which includes all of the functions listed in this post. That way you don't have to clutter your workspace with all of these function declarations; you can just include the DBA file. Here is how (DBPro)
1.Go into Project View Mode for your project.
2.Select the little red tab in the bottom-right corner of your screen marked "Files"
3.Click it and then click "Browse..."
4.Go to where you saved the DBA file and click OPEN.
5.There you go. Your project may look like it was replaced with the function code, but it's not. At the top of this "Files" menu it says "Main Source File". Click on that once, maybe twice and your code should pop up again.
Or you could just use the #Include command
All of the globals and types are already declared in the DBA file, so you don't have to declare them yourself!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
MY FUNCTIONS
See My Function List for details in the comments.
Control Object Using Arrowkeys
SYNTAX: Move_Object_Using_Arrowkeys(Obj,MS,TS)
-----Will move an object at a specified speed and with a specified turn rate. Similar to DBPro's Control Camera Using Arrowkeys command.
Third Person Camera
SYNTAX: Third_Person_Camera(Obj,Cam,Dist#,Height#,Smooth,FLAG)
-----Will make the specified camera follow an object.
Box Clear
SYNTAX: Box_Clear(Left,Top,Right,Bottom,Thick)
-----Just like the 2d box command, but the box made is clear with the line thickness that you specify.
Circle Fill
SYNTAX: Circle_Fill(x,y,Radius)
Not the fastest command. lower logic has a faster one (posted later)
-----Just like the 2d circle command, but the circle is pretty much filled in (pretty much...)
Triangle
SYNTAX: Triangle(X1,Y1,X2,Y2,X3,Y3)
-----Creates a 2d triangle using 3 points that you specify.
LBL Text (Letter-by-letter Text)
SYNTAX: LBL_Text(X,Y,Text$,Delay#,Sound)
-----Will print text to the screen letter by letter using a REPEAT and UNTIL loop.
FPS Camera (First Person Shooter Camera)
SYNTAX: FPS_Camera(Cam,Speed,FLAG)
-----Will make the specified camera act like a First Person Shooter Camera.
Merge Object
SYNTAX: Merge_Object(SObj,EObj,TOBj,X#,Y#,Z#)
-----Will merge all of the objects within an object range (SObj to EOBj) into one object. Each of the merged objects will now be a limb on the one object (TObj) and the new object will appear white. The limbs keep their original position and rotation. All of the positions and angles use world coordinates (where they are in te ACTUAL 3d space) Use the LIMB commands to modify individual parts of the new object. The center of the object (what the position is based on, I'm not sure what the word is) is at the point that you specify.
Pos To Tile (Position to Tile)
Semi-Advanced- Uses types and globals. This function is not the best one here, as it may bring up questions.
SYNTAX: Pos_To_Tile(Matrix,Size,Tiles,x#,z#)
-----Will convert a 3d coordinate into a tile coordinate on a matrix. The tile coordinate must be on the matrix. This function uses one type and a global. The type is where the tile coordinates are put. To access this type, use FTile.X or FTile.Z. There is a little code that you need to put at the start of your program. Everything you need is included in a REM in the function. If you have a question about this one, just ask me.
Detect Movement
SYNTAX: Detect_Movement()
-----Will return a 1 if the user does anything (move the mouse, press a key, etc.), otherwise a 0 is returned.
Tile To Pos (Tile to Position)
Semi-Advanced- Uses types and globals. This function is not the best one here, as it may bring up questions.
SYNTAX: Tile_To_Pos(Matrix,Size,Tiles,x,z)
-----Does the exact opposite of Pos To Tile (Position To Tile). This will convert a tile coordinate to a world coordinate in 3D space. The coordinate is the one at the exact CENTER of the tile positions specified. This function, like Pos_To_Tile, uses types and globals. The type is the same as the one for Pos_To_Tile. The global however is FPos instead of FTile. You can access the results generated from this function by typing in "FPos.x" or "FPos.z". As you may have guessed, "FPos.x" returns the X coordinate generated, and "FPos.z" returns the Z Coordinate. Everything you need is stored inside a REM within the function. Read the REM inside the function for details.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
<<<<<MY FUNCTION LIST>>>>>
REM ****************************************************************
REM * <<===FUNCTIONS===>> *
REM ****************************************************************
function Control_Object_Using_Arrowkeys(Obj,MS,TS)
`Works just like move camera using arrowkeys!
`MS=Move Speed
`TS=Turn speed
`OBJ=Object Number
`USe arrowkeys to move object
if upkey() then move object Obj,MS
if downkey() then move object OBJ,-1*MS
if leftkey() then yrotate object OBJ,wrapvalue(Object angle y(OBj)-TS)
if rightkey() then yrotate object OBJ,wrapvalue(Object angle y(OBj)+TS)
endfunction
function Third_Person_Camera(Obj,Cam,Dist#,Height#,Smooth,FLAG)
`Obj=Object that you want to follow
`Cam=Camera number of camera used (Psst...0 is default camera...)
`Dist#=Distance from target
`Height#=Height of camera above object
`Smooth=Amount of steps it takes to reach the target
`1=No smoothing
`100=LOTS of smoothing
`Height Smoothing Flag. 0=No height smoothing and 1=Height smoothing
rem Store Camera Target Position
cx#=newxvalue(OBject position x(Obj),Object angle y(Obj),-1*Dist#)
cy#=Object Position y(Obj)+Height#
cz#=newzvalue(OBject position z(Obj),Object angle y(Obj),-1*Dist#)
`Store Camera Current Position
Camx#=curvevalue(cx#,Camera Position x(Cam),Smooth)
Camy#=curvevalue(cy#,Camera Position y(Cam),Smooth)
Camz#=curvevalue(cz#,Camera Position z(Cam),Smooth)
`Position Camera
if FLAG=1 then position camera Cam,Camx#,Camy#,camz#
if FLAG=0 then position camera Cam,Camx#,Object Position y(Obj)+Height#,camz#
point camera Cam,OBject position x(Obj),object position y(Obj),object position z(Obj)
endfunction
function Box_Clear(Left,Top,Right,Bottom,Thick)
`LEFT=how far left the box should start out
`TOP=At what height the top of the box is at.
`RIGHT=How far right the box should go
`BOTTOM=Where the bottom of the box is.
`Make Top line of the box, making more lines until the line is as thick as it should be.
For T = 0 to Thick
line Left,Top+T,Right,Top+T
next T
`Bottom line
for T = 0 to Thick
line Left,Bottom-T,Right,Bottom-T
next t
`Left side
for T = 0 to Thick
line Left+T,Top,Left+T,Bottom
next t
`Right side
for T = 0 to Thick
line right-T,Top,right-T,Bottom
next t
endfunction
function Circle_Fill(x,y,Radius)
`X= X Position of circle
`Y= Y position of circle
`Z= Z Position of circle
`Radius=Radius of circle
`Keep making curcles until the circle is as big as specified.
for b = 1 to radius
for a = 0 to 360
`Create many dots in a circe to form a filled in circle.
dot x+b*sin(a),y+b*cos(a)
next a
next b
endfunction
function Triangle(X1,Y1,X2,Y2,X3,Y3)
`X1=Point 1 X Position
`Y1=Point 1 Y Position
`X2=Point 2 X Position
`Y2=Point 2 Y Position
`X3=Point 3 X Position
`Y3=Point 3 Y Position
`Create the first line, gong from point 1 to point 2
line X1,Y1,X2,Y2
`Create the second line, gong from point 2 to point 3
line X2,Y2,X3,Y3
`Create the third line, gong from point 3 back to point 1, thus finishing the triangle.
line X3,Y3,X1,Y1
endfunction
function LBL_Text(X,Y,Text$,Delay#,Sound)
`X=Where the text begins on the X axis
`Y=Whee it begins on the Y axis
`Text$=The text that you want to print
`Delay#=the delay(in seconds) that you want between each printed letter
`Sound=The sound number of the sound that you want to be played with each letter printed (Does not include spaces).
` Specify a 0 for NO sound.
`Translate Delay into milliseconds for the function
Delay#=delay#*1000
`Get the length of the entire text
Length=LEN(Text$)
`If there's nothing there, then do nothing.
if LENGTH=0 then Exitfunction
`Set the String Character Number to 1 in order to start
Char=1
repeat
`Store the Timer
Time#=Timer()
`If the Timer becomes greater than what it used to be plus the delay...
if LALA=0 `If the function has no delay or doesn't work, ERASE THIS "IF LALA=0" thing. My comp is kinda weird, so I put that there or else it wouldn't compile lol
if Time#>OldTime#+Delay#
`Make OldTimer what the timer is now so we can do it again
OldTime#=Time#
`Store the text on the screen right now
OldPRint$=Print$
for b = 1 to Char
`Add the next character in the entered string to the string being printed on screen
Print$=OldPrint$+Mid$(Text$,b)
next b
`IF you enabled sound, play it.
if Mid$(Text$,Char)<>" " and sound>0 then Play Sound Sound
`Move on to the next Character
Char=Char+1
endif
`Print what we have so far to the screen
text X,Y,Print$
`Do it again until we are done.
sync
until Char>Length
endfunction
function FPS_Camera(Cam,Speed,FLAG)
`Cam=Camera Number (Psst...0 is default camera...)
`Speed=Camera Speed
`FLAG=A flag value for the controls.
` 0=Arrowkeys Only
` 1=WASD keys only
` 2=Arrowkeys and WASD keys.
`Place the mouse at the center of the screen like a target
position mouse screen width()/2,screen height()/2
`store the angles that the camera should be at by using the mouse's movements
Cax#=Camera Angle x(Cam)+Mousemovey()/8
Cay#=Camera Angle y(Cam)+Mousemovex()/8
`Restrict certain camera movements (no upside-down stuff)
if Cax#>=80 then Cax#=80
if Cax#<-80 then Cax#=-80
`rotate camera on the correct angle
rotate camera Cam,Cax#,Cay#,0
`Store camera positions
x#=Camera position x(Cam)
y#=Camera position y(Cam)
z#=Camera position z(Cam)
`Allow different coontrols
`Move camera using arrowkeys
if FLAG=0
if upkey() then position camera Cam,newxvalue(x#,Cay#,Speed),Camera Position y(Cam),newzvalue(z#,Cay#,Speed)
if downkey() then position camera Cam,newxvalue(x#,Cay#,-1*Speed),Camera Position y(Cam),newzvalue(z#,Cay#,-1*Speed)
if leftkey() then position camera Cam,newxvalue(x#,Cay#-90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#-90,Speed)
if rightkey() then position camera Cam,newxvalue(x#,Cay#+90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#+90,Speed)
endif
`Move camera using WASD
if FLAG=1
if Keystate(17) then position camera Cam,newxvalue(x#,Cay#,Speed),Camera Position y(Cam),newzvalue(z#,Cay#,Speed)
if Keystate(31) then position camera Cam,newxvalue(x#,Cay#,-1*Speed),Camera Position y(Cam),newzvalue(z#,Cay#,-1*Speed)
if Keystate(30) then position camera Cam,newxvalue(x#,Cay#-90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#-90,Speed)
if Keystate(32) then position camera Cam,newxvalue(x#,Cay#+90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#+90,Speed)
endif
`Move camera using WASD and arrowkeys
if FLAG=2
if upkey() then position camera Cam,newxvalue(x#,Cay#,Speed),Camera Position y(Cam),newzvalue(z#,Cay#,Speed)
if downkey() then position camera Cam,newxvalue(x#,Cay#,-1*Speed),Camera Position y(Cam),newzvalue(z#,Cay#,-1*Speed)
if leftkey() then position camera Cam,newxvalue(x#,Cay#-90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#-90,Speed)
if rightkey() then position camera Cam,newxvalue(x#,Cay#+90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#+90,Speed)
if Keystate(17) then position camera Cam,newxvalue(x#,Cay#,Speed),Camera Position y(Cam),newzvalue(z#,Cay#,Speed)
if Keystate(31) then position camera Cam,newxvalue(x#,Cay#,-1*Speed),Camera Position y(Cam),newzvalue(z#,Cay#,-1*Speed)
if Keystate(30) then position camera Cam,newxvalue(x#,Cay#-90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#-90,Speed)
if Keystate(32) then position camera Cam,newxvalue(x#,Cay#+90,Speed),Camera Position y(Cam),newzvalue(z#,Cay#+90,Speed)
endif
endfunction
function Merge_Object(SObj,EObj,TOBj,X#,Y#,Z#)
remstart
SOBJ=Start Merge OBject
EOBJ=End MErge Object
TOBj=The final object number
X# Y# and Z# = The center point in the object (not sure what the word for this is). It's what the object's position is based on.
NOTE: The limbs are stated in this way: Limb 1=SObj.
The limb number goes up by 1 with each limb added. So, the second object would be limb 2.
remend
`Set Start Limb Number to 1
Limb=1
`Make a TINY almost invisible sphere to mark the center of the object
make object sphere TObj,0
`Begin to select all of the objects from the SOBj to the EObj
for M = SOBj to EObj
`Make a mesh from the selected object
make mesh from object m,m
`Add the object to the final object as a limb
add limb TObj,Limb,m
`Position the limb where the object was, but in a local way instead.
offset Limb TObj,Limb,Object Position x(m)-x#,Object Position y(m)-y#,Object Position z(m)-z#
`Rotate the limb to the old object's position.
rotate limb TObj,Limb,Object angle x(m),Object angle y(m),Object angle z(m)
`Increasethe limb number.
inc Limb
`Delete the original object
delete object m
`Delete the Mesh
delete mesh m
`Keep going until you're done!
next m
Endfunction
function Pos_To_Tile(Matrix,Size,Tiles,x#,z#)
remstart
NOTE: ONLY WORKS ON A SQUARE MATRIX WITH SAME AMOUNT OF TILES ON BOTH AXIS!!!
MAtrix=Matrix Number
Size=MAtrix Size (In the make matrix command this would be the Width or Height value)
Tiles=Number of tiles that the matrix has (in the Make MAtrix command, it's be the XSegment or ZSegment value. These should both be the same, because it's a square.)
x#=X Coordinate to convert
z#=Z Coordinate to convert
Palce the following code at the start of your program. Make sure none of these names have been used, for the function uses them.
type _TileR_
X as integer
Z as integer
endtype
global FTile as _TileR_
The variable FTile is a global type. To retrieve the X tile generated, use FTile.X. To retrieve the Z tile, use FTile.Z.
IF you are unsure about how to use types, type in the command "type" in the editor and press F1. Scroll down to the section about types.
remend
`Store the size of each tile
MTS#=Size/Tiles
`Store the matrix positions
MX#=MAtrix position x(MAtrix)
MZ#=MAtrix Position z(Matrix)
`Check every tile on the matrix for a match
for y = 0 to Tiles
for x = 0 to Tiles
`IF the coordinates specified are within the range of the selected tile, then set the FTile type variable to the tile's coordinates.
if x#>MTS#*(x)+MX# and x#<MTS#*(x+1)+MX# and z#>MTS#*(y)+Mz# and z#<MTS#*(y+1)+Mz#
FTile.X=x : FTile.Z=y
endif
next x
next y
endfunction
function Detect_Movement()
if Scancode()=0 and mousemovex()=0 and mousemovey()=0 and mouseclick()=0 then Result=0 else Result=1
endfunction Result
function Tile_To_Pos(Matrix,Size,Tiles,x,z)
remstart
NOTE: ONLY WORKS ON A SQUARE MATRIX WITH SAME AMOUNT OF TILES ON BOTH AXIS!!!
MAtrix=Matrix Number
Size=MAtrix Size (In the make matrix command this would be the Width or Height value)
Tiles=Number of tiles that the matrix has (in the Make MAtrix command, it's be the XSegment or ZSegment value. These should both be the same, because it's a square.)
x=X Tile Coordinate to convert
z=Z Tile Coordinate to convert
Palce the following code at the start of your program. Make sure none of these names have been used, for the function uses them.
type _TileR_
X as integer
Z as integer
endtype
global FPos as _TileR_
The variable FPos is a global type. To retrieve the X position generated, use FPos.X. To retrieve the Z position, use FPos.Z.
IF you are unsure about how to use types, type in the command "type" in the editor and press F1. Scroll down to the section about types.
remend
`Store the size of each tile
MTS#=Size/Tiles
`Store the matrix positions
MX#=MAtrix position x(MAtrix)
MZ#=MAtrix Position z(Matrix)
`Generate the 3D cordinate position based on the tile positions specified. Then offset this by the Matrix position.
FPos.x=MX#+MTS#*x+MTS#/2
FPos.z=MZ#+MTS#*z+MTS#/2
endfunction
Other Function Links
Xenocythe's Functions
Function Collection Thread(Started by Benji)