Tuesday, 10 April 2012

Object List - Dropping Objects

So finally we come to the last part of the object handling functions.  Dropping the dragged Object.

The following code goes in the getPointerReleased() > 0 portion of the main loop

if thisObjectPicked > 0
   thisX# = PointWX() - thisPickOffsetX#
   thisY# = PointWY() - thisPickOffsetY#
   HideHighLight()
   if WorldToScreenY( thisY#) >= getTextY( panelText() )
      DelWorkObject( thisObjectPicked )
   else
      setSpritePositionByOffset( thisSpritePicked , thisX# , thisY# )
      setSpriteDepth( thisSpritePicked , DEPTH_WORK - 1 )
      thisObjectUnder = WorkObjectIsOver( thisObjectPicked )
      if thisObjectUnder > 0
         // This is where the merge objects code goes
      endif
   endif
endif
thisSpritePicked = 0
thisObjectPicked = 0
thisPickOffsetX# = 0.0
thisPickOffsetY# = 0.0

It is mainly a reworking of the code used in the getPointerState() > 0 portion, but in a slightly different order.
Instead of the call to HighlightSprite(), when the object is over the panel, it has a call to DelWorkObject(), which destroys the object and it's sprite.

The commands to set the sprite position and depth have been moved to after the else command as there is no point moving the sprite and then deleting it straight after.

The HideHighLight() command has been moved out from the else portion to where the move commands were, so is always called when the object is dropped.

If there is an object under the drop location, a comment line has been added indicating where the merge object function goes.  We can't do this until we have some recipes to tell us what happens to merged objects.

Whether or not an object was picked up, the variables used are reset at the end of the outer loop.

And that's about it. Compile it, run it, have a play.

Notice one thing, we created the objects and stored their references in testObject1 and testObject2, but we have never accessed these variables beyond that.

And we probably never will.  The work object functions are pretty self contained and any access to the array has used the various lookups within the functions.

No comments:

Post a Comment