GMS and S-GMS Functions for Dark Basic Pro
Move objects with the mouse, in two different ways!
Created by RUCCUS
GMS (Grid Movement System)
This function will move an object around the map with the mouse using a 2 line formula!
GMS Code:
``````````````````````````````````````````````````````````````````
`Grid Movement System (GMS)
`Programmed by RUCCUS
``````````````````````````````````````````````````````````````````
`GMS is a function created for Dark Basic Pro that allows the
`user to move any selected object with the mouse. The object will
`follow wherever the mouse goes aslong as the mouse button is
`heald down. Dont move too fast or the object will be dropped.
``````````````````````````````````````````````````````````````````
`Standard Program Setup
SYNC ON:SYNC RATE 0:SET TEXT FONT "ARIAL":POSITION MOUSE 319.5,237
`Create a few objects for us to move
MAKE OBJECT BOX 1,30,30,30
POSITION OBJECT 1,0,0,0
MAKE OBJECT CONE 2,40
POSITION OBJECT 2,-100,0,0
MAKE OBJECT SPHERE 3,50
POSITION OBJECT 1,100,0,0
`IMPORTANT: The height at which you position the camera is vital.
`I find 435 to be about right for the GMS, any higher or lower
`can affect how the movement of the objects work. Experiment with
`it if you wish.
POSITION CAMERA 0,435,0
POINT CAMERA 0,0,0
`Start our main loop
DO
`Display some nifteh' text on the screen...
SET TEXT TO BOLD
CENTER TEXT 319.5,0,"Grid Movement System"
SET TEXT TO NORMAL
CENTER TEXT 319.5,15,"Programmed by RUCCUS"
`Call the Move Object With Mouse function
GMS()
`Refresh the screen and end the loop
SYNC
LOOP
`Move Object With Mouse Function
`Breakdown
`The function checks if the mouse position is at the object
`in question's position. If it is, it checks if the mouse is
`above or below the halfway point of the screen.
`If its above, position the object accordingly. And vise versa
`for below.
FUNCTION GMS()
FOR i = 1 TO 3 STEP 1
IF MOUSECLICK()=1 AND MOUSEX()>=OBJECT SCREEN X(i)-(OBJECT SIZE X(i)/2)-5 AND MOUSEX()<=OBJECT SCREEN X(i)+(OBJECT SIZE X(i)/2)+5 AND MOUSEY() >=OBJECT SCREEN Y(i)-(OBJECT SIZE Y(i)/2) AND MOUSEY()<=OBJECT SCREEN Y(i)+(OBJECT SIZE Y(i)/2)
IF MOUSEY()<237 THEN POSITION OBJECT i,MOUSEX()-(SCREEN WIDTH()/2),0,ABS(MOUSEY()-(SCREEN HEIGHT()/2))
IF MOUSEY()>237 THEN POSITION OBJECT i,MOUSEX()-(SCREEN WIDTH()/2),0,-(MOUSEY()-(SCREEN HEIGHT()/2))
ENDIF
NEXT i
ENDFUNCTION
`````````````````````````````````````````````````````````````````
`Contact me at [email protected] or on the db irc channel for
`more information and help on this or any of my other code
`snippets and tutorials.
`````````````````````````````````````````````````````````````````
`Thanks
` - RUCCUS
`````````````````````````````````````````````````````````````````
S-GMS (Snap-To-Grid Movement System)
This function get's the object you click and moves it on a grid, snapping the object to different grid sections as you move your mouse.
S-GMS Code (With Media):
``````````````````````````````````````````````````````````````````
`Snap-To-Grid Movement System (S-GMS)
`Programmed by RUCCUS
``````````````````````````````````````````````````````````````````
`S-GMS is a function created for Dark Basic Pro that allows the
`user to move any selected object with the mouse in a "snapping"
`way, much like proffesional map maker programs.
`The bones of the program uses part of my GMS function to move
`the object with the mouse in combination with some new code I
`created to move the object in sections.
`Use the code in any way you wish, no royalties are required but
`as always with all my code a simple mention of my name would be
`nice, and possibly a link to my site, www.ruccus.net. Goodluck,
`and if you have any questions feel free to email me at
`[email protected].
``````````````````````````````````````````````````````````````````
`Standard Program Setup
SYNC ON:SYNC RATE 0:SET TEXT FONT "ARIAL":POSITION MOUSE 319.5,237
`Create a few objects for us to move
MAKE OBJECT BOX 1,30,30,30
`Load the image we will texture our grid with
LOAD IMAGE "GRID.bmp",1
`Create a plain and edit it to be our background grid object,
`ONLY for cismetic purposes.
MAKE OBJECT PLAIN 10, 700,530
POSITION OBJECT 10,0,0,0
XROTATE OBJECT 10,-90
TEXTURE OBJECT 10,1
`IMPORTANT: The height at which you position the camera is vital.
`I find 435 to be about right for the GMS, any higher or lower
`can affect how the movement of the objects work. Experiment with
`it if you wish.
POSITION CAMERA 0,435,0
POINT CAMERA 0,0,0
`Start our main loop
DO
`Display some nifteh' text on the screen...
SET TEXT TO BOLD
CENTER TEXT 319.5,0,"Snap-To-Grid Movement System"
SET TEXT TO NORMAL
CENTER TEXT 319.5,15,"Programmed by RUCCUS"
SET TEXT TO BOLD
CENTER TEXT 319.5,450,"Special thanks to APEXnow, [Jimmy] and TheSturgeon for programming help!"
SET TEXT TO NORMAL
`Call the Move Object With Mouse function
SGMS()
`Refresh the screen and end the loop
SYNC
LOOP
`Move Object With Mouse Function
`Breakdown:
`The function stores the object's position for later use. Then
`checks if the mouse is being clicked. If it is, and the mouse is
`at the same coordinates as the object in question, then check
`where the mouse is next. If it's to the left of the object,
`move the object left, if it's to the right, move the object
`right, if it's infront of it, move the object forward. And
`finally if it's behind it, move it backward.
`If the object is off of the screen, reposition it at it's old
`coordinates to disallow moving it off of the screen.
`What to change for different purposes:
`Change what the for checks for for more objects. I.E If you want
`to check for object's between 1 and 10, use
`for i = 1 to 10 Step 1.
`Change the amount at which the object's move to a greater or
`lesser number for larger or lesser movement. Depending on the
`size of your grid and objects, you may want to change this.
`If all your objects are the same width and length, you could
`change the 30 to the object's width and length.
`As a rule of thumb, keep object sizes divisible by the amount
`you're moving the object.
FUNCTION SGMS()
FOR i = 1 TO 1 STEP 1
OLDX#=OBJECT POSITION X(i)
OLDY#=OBJECT POSITION Y(i)
OLDZ#=OBJECT POSITION Z(i)
IF MOUSECLICK()=1
IF MOUSEX()>=(OBJECT SCREEN X(i)-(OBJECT SIZE X(i)/2)-5) AND MOUSEX()<=OBJECT SCREEN X(i)+(OBJECT SIZE X(i)/2)+5 AND MOUSEY() >=(OBJECT SCREEN Y(i)-(OBJECT SIZE Y(i)/2))-10 AND MOUSEY()<=(OBJECT SCREEN Y(i)+(OBJECT SIZE Y(i)/2))+10
IF MOUSEY()< (OBJECT SCREEN Y(i)-(OBJECT SIZE Y(i)/2)+5) THEN MOVE OBJECT i,32
IF MOUSEY()> (OBJECT SCREEN Y(i)+(OBJECT SIZE Y(i)/2)-5) THEN MOVE OBJECT i,-32
IF MOUSEX()<= (OBJECT SCREEN X(i)-(OBJECT SIZE X(i)/2)+5) THEN MOVE OBJECT LEFT i,32
IF MOUSEX()> (OBJECT SCREEN X(i)+(OBJECT SIZE X(i)/2)-5) THEN MOVE OBJECT RIGHT i,32
IF OBJECT IN SCREEN (i)=0 THEN POSITION OBJECT i,OLDX#,OLDY#,OLDZ#
ENDIF
ENDIF
NEXT i
ENDFUNCTION
`````````````````````````````````````````````````````````````````
`Special Thanks
`````````````````````````````````````````````````````````````````
`APEXnow : For helping me overcome my problem with moving the
` object up and down.
`[Jimmy] : For helping me understand the basics of implementing
` background pictures, i.e the grid.
`TheSturgeon : For trying to help me :P
`````````````````````````````````````````````````````````````````
`Contact me at [email protected] or on the db irc channel for
`more information and help on this or any of my other code
`snippets and tutorials.
`````````````````````````````````````````````````````````````````
`Thanks
` - RUCCUS
`````````````````````````````````````````````````````````````````
S-GMS Code (Without Media):
``````````````````````````````````````````````````````````````````
`Snap-To-Grid Movement System (S-GMS)
`Programmed by RUCCUS
``````````````````````````````````````````````````````````````````
`S-GMS is a function created for Dark Basic Pro that allows the
`user to move any selected object with the mouse in a "snapping"
`way, much like proffesional map maker programs.
`The bones of the program uses part of my GMS function to move
`the object with the mouse in combination with some new code I
`created to move the object in sections.
`Use the code in any way you wish, no royalties are required but
`as always with all my code a simple mention of my name would be
`nice, and possibly a link to my site, www.ruccus.net. Goodluck,
`and if you have any questions feel free to email me at
`[email protected].
``````````````````````````````````````````````````````````````````
`Standard Program Setup
SYNC ON:SYNC RATE 0:SET TEXT FONT "ARIAL":POSITION MOUSE 319.5,237
`Create a few objects for us to move
MAKE OBJECT BOX 1,30,30,30
POSITION OBJECT 1,-90,0,0
MAKE OBJECT BOX 2,30,30,30
POSITION OBJECT 2,90,0,0
MAKE OBJECT BOX 3,30,30,30
POSITION OBJECT 3,0,0,0
`IMPORTANT: The height at which you position the camera is vital.
`I find 435 to be about right for the GMS, any higher or lower
`can affect how the movement of the objects work. Experiment with
`it if you wish.
POSITION CAMERA 0,435,0
POINT CAMERA 0,0,0
`Start our main loop
DO
`Display some nifteh' text on the screen...
SET TEXT TO BOLD
CENTER TEXT 319.5,0,"Snap-To-Grid Movement System"
SET TEXT TO NORMAL
CENTER TEXT 319.5,15,"Programmed by RUCCUS"
SET TEXT TO BOLD
CENTER TEXT 319.5,450,"Special thanks to APEXnow, [Jimmy] and TheSturgeon for programming help!"
SET TEXT TO NORMAL
`Call the Move Object With Mouse function
MOVE_OBJECT_WITH_MOUSE()
`Refresh the screen and end the loop
SYNC
LOOP
`Move Object With Mouse Function
`Breakdown:
`The function stores the object's position for later use. Then
`checks if the mouse is being clicked. If it is, and the mouse is
`at the same coordinates as the object in question, then check
`where the mouse is next. If it's to the left of the object,
`move the object left, if it's to the right, move the object
`right, if it's infront of it, move the object forward. And
`finally if it's behind it, move it backward.
`If the object is off of the screen, reposition it at it's old
`coordinates to disallow moving it off of the screen.
`What to change for different purposes:
`Change what the for checks for for more objects. I.E If you want
`to check for object's between 1 and 10, use
`for i = 1 to 10 Step 1.
`Change the amount at which the object's move to a greater or
`lesser number for larger or lesser movement. Depending on the
`size of your grid and objects, you may want to change this.
`If all your objects are the same width and length, you could
`change the 30 to the object's width and length.
`As a rule of thumb, keep object sizes divisible by the amount
`you're moving the object.
FUNCTION MOVE_OBJECT_WITH_MOUSE()
FOR i = 1 TO 3 STEP 1
OLDX#=OBJECT POSITION X(i)
OLDY#=OBJECT POSITION Y(i)
OLDZ#=OBJECT POSITION Z(i)
IF MOUSECLICK()=1
IF MOUSEX()>=(OBJECT SCREEN X(i)-(OBJECT SIZE X(i)/2)-5) AND MOUSEX()<=OBJECT SCREEN X(i)+(OBJECT SIZE X(i)/2)+5 AND MOUSEY() >=(OBJECT SCREEN Y(i)-(OBJECT SIZE Y(i)/2))-10 AND MOUSEY()<=(OBJECT SCREEN Y(i)+(OBJECT SIZE Y(i)/2))+10
IF MOUSEY()< (OBJECT SCREEN Y(i)-(OBJECT SIZE Y(i)/2)+5) THEN MOVE OBJECT i,32
IF MOUSEY()> (OBJECT SCREEN Y(i)+(OBJECT SIZE Y(i)/2)-5) THEN MOVE OBJECT i,-32
IF MOUSEX()<= (OBJECT SCREEN X(i)-(OBJECT SIZE X(i)/2)+5) THEN MOVE OBJECT LEFT i,32
IF MOUSEX()> (OBJECT SCREEN X(i)+(OBJECT SIZE X(i)/2)-5) THEN MOVE OBJECT RIGHT i,32
IF OBJECT IN SCREEN (i)=0 THEN POSITION OBJECT i,OLDX#,OLDY#,OLDZ#
ENDIF
ENDIF
NEXT i
ENDFUNCTION
`````````````````````````````````````````````````````````````````
`Special Thanks
`````````````````````````````````````````````````````````````````
`APEXnow : For helping me overcome my problem with moving the
` object up and down.
`[Jimmy] : For helping me understand the basics of implementing
` background pictures, i.e the grid.
`TheSturgeon : For trying to help me :P
`````````````````````````````````````````````````````````````````
`Contact me at [email protected] or on the db irc channel for
`more information and help on this or any of my other code
`snippets and tutorials.
`````````````````````````````````````````````````````````````````
`Thanks
` - RUCCUS
`````````````````````````````````````````````````````````````````
Im not sure if the functions work in Dark Basic, I dont have it so I cant test it but it should work. If someone could test it in Dark Basic and get back to me on the forums with an answer I'd greatly appretiate it.
Comments, Critisism and Questions are encouraged. If I see some good questions Ill make a small FAQ in this post for quick reference. Ill try and answer them all as soon as possible.
Goodluck with the code, no credit is required but as always a mention of my name and a link to my site; www.RUCCUS.net, is always appretiated.
<Edit> As usual the damn attachment button isn't working, so here's the pic:

Picture here:
http://i3.photobucket.com/albums/y84/RUCCUS/GRID.bmp
-
The Forum Ninja, RUCCUS.