Looking with the right mouse button

From SCI Wiki
Revision as of 18:37, 5 August 2013 by Andrew Branscom (talk | contribs) (1 revision)
Jump to navigationJump to search

To accomplish this we will use the priority colors - you can use the control colors as well.

Step 1: Trace & fill all the objects in your room with a priority color. For immediately adjacent objects, use a different color.

Step 2: Determine the bounding rectangle around each object. This will allow you to re-use a priority color more than once per room. Note that you can have overlapping bounding rectangles for objects - just make sure that the objects have different priority colors. To aid with determining the coordinates of the rectangles, temporarily include the following code in your handleEvent method to give you the cursor hotspot location on a right-click:

Code:
        (if(== (send pEvent:type) evMOUSEBUTTON and == (send pEvent:modifiers) 515)
            FormatPrint("x:%d, y:%d" (send pEvent:x) (send pEvent:y) )	 
	)

Step 3: Modify your 'look' logic

Code:
        (if(Said('look/box')
        	or
                   (    == (send pEvent:type) evMOUSEBUTTON  // mouse click
        	    and == (send pEvent:modifiers) 515   // specifically a right mouse click
        	    and == $0002 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y))  // on NAVY priority color

                    // check that the mouse is in the bounding rectangle for this object
        	    and > (send pEvent:x) 93
        	    and < (send pEvent:x) 132
        	    and > (send pEvent:y) 78
        	    and < (send pEvent:y) 110
                   )
           )
           Print("The box is closed")
	)

Or for much cleaner implementation, create a class and then create instances of the class for each right-clickable area:

Code:
(class MouseLookObj
   (properties
      priorityColor $0000
      xMin 0
      xMax 0
      yMin 0
      yMax 0
   )
   (method (rightClicked pEvent)
   	  MouseLook(pEvent)
   )   
)

(procedure (MouseLook pEvent) of MouseLookObj
       (if (== (send pEvent:type) evMOUSEBUTTON
    	    and == (send pEvent:modifiers) 515
    	    and == priorityColor OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y))
    		and > (send pEvent:x) xMin
    		and < (send pEvent:x) xMax
    		and > (send pEvent:y) yMin
    		and < (send pEvent:y) yMax)
	      return(TRUE)
	)
        return(FALSE)
)

In your room script:

Code:
(instance public BoxLook of MouseLookObj
    (properties 
        priorityColor $0002 
        xMin  93 
        xMax 132 
        yMin  78
        yMax 110
    )
)

....

(if(Said('look/box') or BoxLook:rightClicked(pEvent))
    Print("The box is closed")
)