Author Topic: 'Looking' with the right mouse button  (Read 5033 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

'Looking' with the right mouse button
« on: September 29, 2012, 09:56:30 AM »
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: [Select]
       (if(== (send pEvent:type) evMOUSEBUTTON and == (send pEvent:modifiers) 515)
            FormatPrint("x:%d, y:%d" (send pEvent:x) (send pEvent:y) )
)
EDIT:  Even easier, in the picture editor (either Studio or Companion) use the x/y coordinate indicator to get the current location of the mouse.

Step 3: Modify your 'look' logic
Code: [Select]
       (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")
)
« Last Edit: December 26, 2012, 01:36:20 PM by gumby »


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline gumby

Re: 'Looking' with the right mouse button
« Reply #1 on: September 29, 2012, 11:39:40 AM »
Or for much cleaner implementation, create a class and then create instances of the class for each right-clickable area:

Code: [Select]
(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: [Select]
(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")
)
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: 'Looking' with the right mouse button
« Reply #2 on: September 30, 2012, 11:55:42 PM »
Nice! Thanks for this!
Brass Lantern Prop Competition

Offline Doan Sephim

Re: 'Looking' with the right mouse button
« Reply #3 on: October 22, 2013, 04:01:05 PM »
Hmm... I just looked this over. I wish I had seen this a long time ago as it looks like it would save on some heap space. The method I've been using is much less streamlined...

Maybe I will have time to come over my code and replace, but that sounds like a horrible time...  :-[


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.04 seconds with 23 queries.