Disable touch input until sprite reaches tapped target.

I have a 5 x 8 grid and I have figured out how to get a sprite to move, down, left and right while preventing diagonal movement by touching a neighboring grid square. I have even sorted out how to limit the travel to one grid square at a time. The problem I am having now is, if I tap (grid 1) and then immediately tap a neighbor of (grid 1) (above, below, or the opposite side from the sprite,) the sprite takes off in that direction along the same axis or diagonally which causes it to bypass (grid 1). What I would like to do is prevent any touch input until the sprite has reached the target and then enable touch input for movement to the next grid. I can get the touch input to stop by changing a game level attribute to CanTouch = 0, but I can't figure out a trigger to set it back to CanTouch = 1.

Here is a simplified version the logic:

Game Level Attributes:
CanTouch = 0 boolean
XPosition = 0 real
YPosition = 0 real
MoveToTarget = 0 boolean


(GRID SQUARE LOGIC)
WHEN ALL:
touch is: [inside]
if [game.CanTouch] is true
DO:
SET: [game.XPosition] TO: [self.position.x]
SET: [game.YPosition] TO: [self.position.y]
SET: [CanTouch] TO: [0] (Prevents grids from responding to screen touch.)
SET: [game.MoveToTarget] TO: [1] (Triggers sprite to move to X or Y position.)


(SPRITE LOGIC)
WHEN ALL:
if [game.MoveToTarget] is true
DO:
MOVE TO: [game.XPosition], [gameYPosition] relative: scene
@ [300] RTC

------------------------------------------------

After the sprite reaches the target grid square, I need to set game.CanTouch to 1, which will allow the grid squares to respond to input again.

Any assistance is greatly appreciated.

Comments

  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    Once the SPRITE_X/Y = game.XPosition/game.Yposition
    Change attribute: CanTouch to 1

    Is what I'm getting from this.
    Of course, move to might not be horribly exact, so instead of making the above rule equal to, you might want to set it to a range of a few pixels.
  • dalbelodalbelo Member Posts: 6
    I tried that but, I didn't have any luck. I didn't try it with a range because I assumed the sprite and the grid would have exactly the same positions. I'lll give that a try.

    Thanks
  • dalbelodalbelo Member Posts: 6
    Heh, I guess I need a bit of assistance with entering a range. I looked it under functions, but I didn't see an option for it in there.
  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    You would need to set up two more parameters for the rule.

    So in total you would have four:
    When attribute self.PositionX > game.Xposistion-1 AND When attribute self. PosistionX <game.xposistion +1

    Do the same for the Y value. You might want to change the 1 to give you more wiggle room.

    If that doesn't help, I'm not sure what will.
  • dalbelodalbelo Member Posts: 6
    I gave that a try, but I had no luck. I really appreciate your input.
  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    Well, assuming that the sprite moves at a fixed rate per square, you might be able to set it up on a timer, where After (number of steps) x (time it takes to complete one step) it will reset, but I feel like that might be pretty spotty code.
  • dalbelodalbelo Member Posts: 6
    Actually tried using a timer with ? second delay but strange things happened. Now I am playing with this:

    IF: self.motion.linear Velocity x/y = 0
    DO:
    SET: game.CanTouch TO: 1

    This seems to be working so far, but I am still testing.

    Once again, thanks for the suggestion.
  • ElfizmElfizm Member Posts: 489
    Go back to your Oriningal way and maybe change in the move to behavior and check run to completion. See if that works
Sign In or Register to comment.