Issue #21 resolved
Chris Logsdon
created an issue

I'll take this one. I think the double tapping of the key could be useful in several other scenarios. One thing that I do want to ask you about is smoke. If I wanted there to be a small smoke screen at the point the blink begins and/or ends, how do you think that could be done?

Comments (16)

  1. Jake Albano repo owner
    • changed status to open

    Make an animated decal, and tell it to remove itself from the stage when its animation finishes. Like so:

    addDecal(Library.IMG("smoke", blink_start_x, blink_start_y, smokeFunc, /* animation stuff here */);
    private function smokeFunc(i:IfritObject):void
        // i is a reference to the decal calling the function.
        if (i.animation.playing != "smoking") Game.stage.removeChild(i);
  2. Jake Albano repo owner

    I updated the Decal class to support non-looping animations. The last parameter is an optional boolean. It defaults to true, so existing code works without any changes.

  3. Chris Logsdon reporter

    In Game class, on direction key press:

    if (canBlink)
         for (var i:int = World.Platforms.length - 1; i <= 0; i--)
              if (Point.distance(man, platform) >= 75)
                   man.x += Point.distance(man, platform);
                   canBlink = false;
                   HUD.buyAction(200, HUD.SPECIAL);
                   man.x -= 75;
                   canBlink = false;
                   HUD.buyAction(200, HUD.SPECIAL);
  4. Jake Albano repo owner

    A few notes with just a quick look:

    Your loop will never run, since it tests for <= 0 instead of >= 0.

    You should probably be testing only against vertical platforms.

    Finally (and most likely the problem), the first time in the loop that a platform is more than 75 pixels away, the teleportation will trigger, even if the platform being tested is on the other side of the map.

    The best way I can think to do this:

    Create a new point containing the man's position.

    In a while loop, increase or decrease the x value by 5, depending on direction.

    Each time, loop through the platforms and do a hitTestPoint() on the vertical ones. If it returns true, stop the loop and set the man's position to the point's position.

    If the platform check is false, check if the point is farther than the maximum allowed blink distance. If true, stop the loop and set the man's position to the point's position.

    This could potentially be expensive in terms of time. We'll see how it works -- if necessary I can create some kind of space partitioning structure to only check platforms nearby.

  5. Chris Logsdon reporter

    I made a few mistakes when I typed that up. I did have a >=, I was checking only verticals, and the -= should be += to be consistent with the block above it.

    Hmm. That makes sense. There are two things I don't fully understand though. What is the while condition? What is the purpose of increasing the x value? Is it to determine where to move the man? If so, is it assuming that x will be >= 75 if all the platform checks are false?

  6. Jake Albano repo owner

    I thought that might be the case. Just wanted to mention it anyway. :)

    Basically, inside the while loop, x is increased, and then checked to see if it would be a legal place for the man to end up. Since it checks every 5 pixels, it's impossible for him to skip a platform. Once the destination is 75 pixels away or a wall is reached (the end of the loop), teleport the man there.

  7. Chris Logsdon reporter

    Ohhhh, got it!

    Correct me if I'm wrong:

    var to:Point = new Point(man.x, man.y); // Obviously this isn't how I would actually do these variables
    var stop:Boolean = false;
    while (Point.distance(new Point(man.x, man.y), to) <= 75 || !stop)
         to.x +=  5
         for (platform stuffs)
              if (vertical)
                   if (platform.hitTestPoint(to))  stop = true;
                   else  stop = false;
    man.x += to.x;
  8. Log in to comment