SCI 1.1 Compass Rose Navigation

Let's say you are making a first-person game (no traditional 'ego' that walks around the screen) and you want to be able to change screens by clicking on a compass rose.  I chose to create a single view, rather than create a view for each direction that could be clicked - and now that I've done it, it may have been easier doing it that way as it would avoid the coordinate checking code.


Basically we check for the 'do' verb on the view, then check the coordinates that were clicked to determine whether the user clicked 'north', 'south' etc.  Then we determine whether the direction clicked is a valid direction as defined in the room properties and if so we switch to that room.  If not we let the user know that it's not a valid direction to travel.

Here's the code:

Code: [Select]
(instance compassRose of Prop
   (properties
   view 1
   x 270
   y 190
   ;signal ignAct
   loop 0
   cel 0
   priority 0
   )
   (method (doVerb theVerb param2)
       (switch theVerb
         (V_DO

            (if ( and (> ((gUser curEvent?) x?)  263)
                  (> ((gUser curEvent?) y?)  95)
                    (< ((gUser curEvent?) x?)  275)
                  (< ((gUser curEvent?) y?)  128)
)
  (if (== (rm304 north?) 0)
     (Prints "You cannot go that way")
   else
     (gRoom newRoom: (rm304 north?))
  )
)

            (if ( and (> ((gUser curEvent?) x?)  263)
                  (> ((gUser curEvent?) y?)  158)
                    (< ((gUser curEvent?) x?)  275)
                  (< ((gUser curEvent?) y?)  186)
)
  (if (== (rm304 south?) 0)
     (Prints "You cannot go that way")
   else
     (gRoom newRoom: (rm304 south?))
  )
)

            (if ( and (> ((gUser curEvent?) x?)  284)
                  (> ((gUser curEvent?) y?)  137)
                    (< ((gUser curEvent?) x?)  319)
                  (< ((gUser curEvent?) y?)  149)
)
  (if (== (rm304 east?) 0)
     (Prints "You cannot go that way")
   else
     (gRoom newRoom: (rm304 east?))
  )
)

            (if ( and (> ((gUser curEvent?) x?)  222)
                  (> ((gUser curEvent?) y?)  137)
                    (< ((gUser curEvent?) x?)  256)
                  (< ((gUser curEvent?) y?)  146)
)
  (if (== (rm304 west?) 0)
     (Prints "You cannot go that way")
   else
     (gRoom newRoom: (rm304 west?))
  )
)
         )
       )
   )

)

A future improvement would be add 'hover over' highlighting which would light up when the direction is valid and we could remove those print statements.