TGC Codebase Backup



GMS Grid Movement System by RUCCUS

22nd Apr 2005 19:34
Summary

Move objects around the map with the mouse.



Description

The source has plenty of comments in it to describe the code. Basically you select the object you wish to move, hold the mouse down and move the mouse to move the object.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ``````````````````````````````````````````````````````````````````
`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 ruccus@ruccus.net or on the db irc channel for
`more information and help on this or any of my other code
`snippets and tutorials.
`````````````````````````````````````````````````````````````````
`Thanks
` - RUCCUS
`````````````````````````````````````````````````````````````````