Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: A little problem with the walk.  (Read 1018 times)

0 Members and 1 Guest are viewing this topic.
A little problem with the walk.
« on: February 12, 2007, 03:57:27 pm »
  • Metal Up Your Ass.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 56
Hi, I'm using the Movement, Pickup and Push engine done by Goodnight, but I have a little problem with the walking. When I stop moving my char, it stays in the walking animation, and the standing animation doesn't show. What's the problem?

Here's is the code that use, I believe that is the Step event where is the problem.

Step Event:
Code1
Code: [Select]
// LINK MOVEMENT ENGINE by GOODNIGHT
var fholdd, fholdu, fholdl, fholdr, cc;

// Check keys
holdd=keyboard_check(vk_down)
holdu=keyboard_check(vk_up)
holdl=keyboard_check(vk_left)
holdr=keyboard_check(vk_right)
// Cancel opposing keys
if holdu && holdd {
    holdu=0
    holdd=0
}
if holdl && holdr {
    holdl=0
    holdr=0
}


// This is where you may want to add other conditionals which keep you from moving,
// such as if you are using an item, or you are in a menu.
// Just add the conditions to the end of this next "if" line.
// example:
// if (holdd ||holdu || holdl || holdr) && !usingshield {

if (holdd ||holdu || holdl || holdr)
        && (sprite_index!=sprLinkLiftD and sprite_index!=sprLinkLiftU and sprite_index!=sprLinkLiftL and sprite_index!=sprLinkLiftR) 
        && (sprite_index!=sprLinkThrowD and sprite_index!=sprLinkThrowU and sprite_index!=sprLinkThrowL and sprite_index!=sprLinkThrowR)
        {

if holdd ||holdu || holdl || holdr {
    // If you are holding any key, start moving.
    // Change Link's direction if you weren't already moving.
    if !moving {
        if holdd { global.facing="D" }
        else if holdu { global.facing="U" }
        if holdl { global.facing="L" }
        else if holdr { global.facing="R" }
    }
    moving=1
    // Direction correction:
    // Get the correct sprite when you walk diagonally then release one arrow.
    if (holdd && !holdl && !holdr) { global.facing="D" }
    else if (holdu && !holdl && !holdr) { global.facing="U" }
    else if (holdl && !holdd && !holdu) { global.facing="L" }
    else if (holdr && !holdd && !holdu) { global.facing="R" }
    // Prevent direction glitches caused by inhuman keypress timing.
    if (holdd && holdl && global.facing!="D" && global.facing!="L") { global.facing="L" }
    else if (holdd && holdr && global.facing!="D" && global.facing!="R") { global.facing="R" }
    else if (holdu && holdl && global.facing!="U" && global.facing!="L") { global.facing="L" }
    else if (holdu && holdr && global.facing!="U" && global.facing!="R") { global.facing="R" }
// Stop moving if no key is held.
} else { moving=0 }

// If Link is attempting to move now,
if moving {
    // "charge up" the number of pixels to move during this step,
    movestep+=movespeed
    // prepare movement variables,
    xstep=0
    ystep=0
    // and start doing the movement.

    while movestep>=1 {

        // Corner-cutting loop. This for-loop determines if Link is blocked by a solid,
        // but is close enough to its edge to cut around it.
        // If so, a "fake hold" variable is set, and the engine acts as if that arrow key is held.
        // Feel free to change the initial "cc" variable for corner sensitivity.
        // Between 4 and 8 is recommended - even less if your solids have curved masks. Use 0 for none.

        fholdd=0; fholdu=0; fholdl=0; fholdr=0;
        for (cc=6; cc>0; cc-=1) {
            if holdu {
                // If you're walking upwards and blocked by a solid...
                if !place_free(x,y-1) {
                    // ...but pressing left or right, release the "up" key.
                    if holdl || holdr { holdu=0 }
                    // ...but close to the left edge, and NOT holding left or right, and not fake-holding either, perform a fake left hold.
                    // And if you are only 1 pixel from the edge, also perform a fake up hold, to move diagonally through the corner.
                    else if place_free(x-cc,y-1) && !(fholdl || fholdr) { fholdl=1; fholdu=place_free(x-1,y-1) }
                    // Same as above, for the right edge.
                    else if place_free(x+cc,y-1) && !(fholdl || fholdr) { fholdr=1; fholdu=place_free(x+1,y-1) }
                }
            // Same thing transposed for the other three directions:
            } else if holdd {
                if !place_free(x,y+1) {
                    if holdl || holdr { holdd=0 }
                    else if place_free(x-cc,y+1) && !(fholdl || fholdr) { fholdl=1; fholdd=place_free(x-1,y+1) }
                    else if place_free(x+cc,y+1) && !(fholdl || fholdr) { fholdr=1; fholdd=place_free(x-1,y+1) }
                }
            }
            if holdl {
                if !place_free(x-1,y) {
                    if holdu || holdd { holdl=0 }
                    else if place_free(x-1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdl=place_free(x-1,y-1) }
                    else if place_free(x-1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdl=place_free(x-1,y+1) }
                }
            } else if holdr {
                if !place_free(x+1,y) {
                    if holdu || holdd { holdr=0 }
                    else if place_free(x+1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdr=place_free(x+1,y-1) }
                    else if place_free(x+1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdr=place_free(x+1,y+1) }
                }
            }
        }
        // End corner-cutting loop.

        // Determine the number of pixels to move horizontally and vertically (-1, 0, or 1).
        xstep=(holdr || fholdr)-(holdl || fholdl)
        ystep=(holdd || fholdd)-(holdu || fholdu)
        // If you can move hor. and vert. at the same time, do so.
        if place_free(x+xstep,y+ystep) {
            x+=xstep
            y+=ystep
        } else {
            // Otherwise, just move in the direction that you can.
            if place_free(x+xstep,y) { x+=xstep }
            else if place_free(x,y+ystep) { y+=ystep }
        }
        // If you only moved up, down, left, or right, take 1 (pixel) off your movement steps.
        // If you moved diagonally, take the square root of 2 (about 1.41) off your movement steps.
        // Allowing less diagonal movements per step gives the proper 'slowdown' effect.
        if ((holdd || holdu) && (holdl || holdr)) || ((fholdd || fholdu) && (fholdl || fholdr)) { movestep-=sqrt(2) }
        else { movestep-=1 }
    }
   
    // Wall-pushing detection code.
    // Just to clarify, Link's pushcount activates his pushing animation,
    // while the block's pushcount activates its movement.

    // If you weren't moving diagonally, and weren't able to move, check for a solid for Link to push.
    var pushblock;
    pushblock=0
    // Determine the id of the solid block in front of Link (if there is one).
    if !(holdd || holdu || fholdd || fholdu || place_free(x+xstep,y)) {
        pushblock=collision_point(x+xstep*8+(xstep>0)*16,y+8,parSolid,0,0)
    } else if !(holdl || holdr || fholdl || fholdr || place_free(x,y+ystep)) {
        pushblock=collision_point(x+8,y+ystep*8+(ystep>0)*16,parSolid,0,0)
    }
    // If there is a solid, increase Link's pushcount (to a maximum of 16).
    if pushblock>0 {
        pushcount=min(pushcount+1,16)
        // Set the alarm to reset the pushcount to 0 when Link stops moving.
        alarm[7]=2
        // If the solid is pushable, and Link is fairly in-line with it,
        if object_get_parent(pushblock.object_index)=parPushable && ((ystep=0 && abs(pushblock.y-y)<=4) || (xstep=0 && abs(pushblock.x-x)<=4)) {
            with pushblock {
                // and it's not already moving,
                if !moving {
                    // and it can be pushed in the direction Link is facing,
                    movedir=global.facing
                    if movesa>0 || (movedir="D" && movesd>0) || (movedir="U" && movesu>0) || (movedir="L" && movesl>0) || (movedir="R" && movesr>0) {
                        // then increase its pushcount.
                        pushcount=min(pushcount+1,16)
                        alarm[7]=2
                    }
                }
            }
        }
    }

    // Set the right sprite when you are moving.
    // If Link has been pushing for at least 15 steps, use the pushing animation.
    if pushcount>=15 {
        switch global.facing {
            case "D": sprite_index=sprLinkPushD; break;
            case "U": sprite_index=sprLinkPushU; break;
            case "L": sprite_index=sprLinkPushL; break;
            case "R": sprite_index=sprLinkPushR; break;
        }
        // (Which is slightly slower than the running animation.)
        image_speed=animspeed*0.7
    // Otherwise, use the running animation.
    } else {
        switch global.facing {
            case "D": sprite_index=sprLinkRunD; break;
            case "U": sprite_index=sprLinkRunU; break;
            case "L": sprite_index=sprLinkRunL; break;
            case "R": sprite_index=sprLinkRunR; break;
        }
        image_speed=animspeed
    }
// If Link is not moving this step,
} else {
    // Set the right standing sprite.
    switch global.facing {
        case "D": sprite_index=sprLinkStandD; break;
        case "U": sprite_index=sprLinkStandU; break;
        case "L": sprite_index=sprLinkStandL; break;
        case "R": sprite_index=sprLinkStandR; break;
    }
    movestep=0
}

// Almighty depth leverage technique
depth=-y
// end of Link Movement


Code2
Code: [Select]

// Are we meant to be holding something?
if instance_exists(holding_pot) {

with (holding_pot) {
    solid=0 // It no longer will get in our way
    if (objLink.sprite_index=sprLinkLiftD or objLink.sprite_index=sprLinkLiftU or objLink.sprite_index=sprLinkLiftL or objLink.sprite_index=sprLinkLiftR)
    move_towards_point(objLink.x,objLink.y-15,point_distance(x,y,objLink.x,objLink.y-15)/2) // Move to above his head
    else
    {x=objLink.x;y=objLink.y-15}
}


}

Where is the mistake?

Thanks and I know that my english sucks. :)

Logged

mit

Re: A little problem with the walk.
« Reply #1 on: February 12, 2007, 05:44:41 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Aha, I see what you're doing. You're using the pickup engine I made with the second version of Goodnight's code. Aha. Good idea.

Hmm... it's probably this: Notice where all the conditions for if you're lifting or throwing are - instead of replacing the condition in the new movement code, you've added it around it. This shouldn't really pose a problem except that now it doesn't see the "else" at the bottom that changes it to stopping sprites. So what you need to do is change
Code: [Select]
if (holdd ||holdu || holdl || holdr)
        && (sprite_index!=sprLinkLiftD and sprite_index!=sprLinkLiftU and sprite_index!=sprLinkLiftL and sprite_index!=sprLinkLiftR) 
        && (sprite_index!=sprLinkThrowD and sprite_index!=sprLinkThrowU and sprite_index!=sprLinkThrowL and sprite_index!=sprLinkThrowR)
        {

if holdd ||holdu || holdl || holdr {
to
Code: [Select]
if (holdd ||holdu || holdl || holdr)
        && (sprite_index!=sprLinkLiftD and sprite_index!=sprLinkLiftU and sprite_index!=sprLinkLiftL and sprite_index!=sprLinkLiftR) 
        && (sprite_index!=sprLinkThrowD and sprite_index!=sprLinkThrowU and sprite_index!=sprLinkThrowL and sprite_index!=sprLinkThrowR)
        {
and balance out the brackets at the other end.

That should fix the problem, not sure.

PS: Your english doesn't suck at all :P
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: A little problem with the walk.
« Reply #2 on: February 12, 2007, 08:33:30 pm »
  • Metal Up Your Ass.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 56
It worked. Yeah!, thanks you so much mit!

Edit:
It works in the walk engine, but when I pickup an object it doesn't show the Lift anim. What could be wrong?
« Last Edit: February 12, 2007, 08:37:10 pm by paito »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.024 seconds with 43 queries.

anything