TGC Codebase Backup



Point and Click Box Objects by Anonymous Coder

5th Mar 2005 9:54
Summary

Creates point and click box objects.



Description

Project folder attachement is included.
Thank you.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: Point and Click Box Objects
Rem Created: 2/25/2005 9:59:27 PM

Rem ***** Main Source File *****

type pointer
hold_object$
free_handler$
endtype

type object
width
height
Left
Top
Right
Bottom
centre_x
centre_y
text$
enclaved_bypointer$
mouseclick_andlock_boxobject$
setbox$
entity_object
endtype

dim boxobject$(10) as object
communication_device$ as pointer

global i,max_objects_on_screen,lastobjectxpoint,maxboxes,Filename$,BitmapNumber
i=1
max_objects_on_screen=10

Filename$="bitmaps\image.bmp"
BitmapNumber=0
`LOAD BITMAP Filename$,BitmapNumber
`set current bitmap 0
`can't color a box with "image.bmp"

ini_controller()
create_boxobject(40,40,0,0)
create_boxobject(40,40,50,0)
create_boxobject(40,40,100,0)
create_boxobject(40,40,150,0)
create_boxobject(40,40,200,0)
i=i-1
maxboxes=i
do
   cls
   view_object_box_settings()
   pointer_reading()
   draw_boxobjects()
loop
end

function ini_controller()
communication_device$.hold_object$="no"
communication_device$.free_handler$="yes"
endfunction


function view_object_box_settings()
local i
for i=1 to maxboxes step 1
   set cursor i*80,85
   print "box:",boxobject$(i).entity_object
   text i*80,100,boxobject$(i).enclaved_bypointer$
   text i*80,115,boxobject$(i).mouseclick_andlock_boxobject$
   text 0,100,"Point:"
   text 0,115,"Click:"
next
endfunction

function draw_boxobjects()
local i
for i=1 to maxboxes step 1
   BOX boxobject$(i).Left,boxobject$(i).Top,boxobject$(i).Right,boxobject$(i).Bottom
next
endfunction

function pointer_reading()
local i
if (communication_device$.free_handler$="yes")
   for i=1 to maxboxes step 1
   if (mousex()>=boxobject$(i).Left)
      if (mousex()<=boxobject$(i).Right)
         if (mousey()>=boxobject$(i).Top)
            if (mousey()<=boxobject$(i).Bottom)
               boxobject$(i).enclaved_bypointer$="yes"
               if (mouseclick()=1)
                  boxobject$(i).setbox$="follow"
                  boxobject$(i).mouseclick_andlock_boxobject$="yes"
                  communication_device$.hold_object$="yes"
               else
                  boxobject$(i).setbox$="set no motion"
                  boxobject$(i).mouseclick_andlock_boxobject$="no"
                  communication_device$.hold_object$="no"
               endif
            else
               boxobject$(i).enclaved_bypointer$="no"
            endif
         else
            boxobject$(i).enclaved_bypointer$="no"
         endif
      else
         boxobject$(i).enclaved_bypointer$="no"
      endif
   else
      boxobject$(i).enclaved_bypointer$="no"
   endif

   if (boxobject$(i).setbox$="follow")
      boxobject$(i).Left=mousex()-boxobject$(i).centre_x
      boxobject$(i).Top=mousey()-boxobject$(i).centre_y
      boxobject$(i).Right=mousex()+boxobject$(i).centre_x
      boxobject$(i).Bottom=mousey()+boxobject$(i).centre_y
   endif
next
endif

endfunction


function create_boxobject(widthfactor,heightfactor,x,y)
boxobject$(i).width=widthfactor
boxobject$(i).height=heightfactor
boxobject$(i).Left=x
boxobject$(i).Top=y
boxobject$(i).Right=x+widthfactor
boxobject$(i).Bottom=y+heightfactor
boxobject$(i).centre_x=(boxobject$(i).Right-boxobject$(i).Left)/2
boxobject$(i).centre_y=(boxobject$(i).Bottom-boxobject$(i).Top)/2
boxobject$(i).text$="Entity:"
boxobject$(i).enclaved_bypointer$="no"
boxobject$(i).mouseclick_andlock_boxobject$="no"
boxobject$(i).entity_object=i
BOX boxobject$(i).Left,boxobject$(i).Top,boxobject$(i).Right,boxobject$(i).Bottom
i=i+1
endfunction