Direction while Jumping (tile based game)

Hey Everyone,

This seems like a simple question, but I can’t figure it out. I’ve been playing with Tonypa’s tile-based game system and can’t figure out how to make the character sprite face the direction he jumps or falls in face the right direction.

Here’s the game and source files.

And here’s the source:

ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]**function**[/COLOR] moveChar[COLOR=#000000]([/COLOR]ob, dirx, diry, jump[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]*// are we jumping?*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]abs[/COLOR][COLOR=#000000]([/COLOR]jump[COLOR=#000000])[/COLOR] == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    speed = ob.[COLOR=#000080]jumpspeed[/COLOR]*jump;
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
    speed = ob.[COLOR=#000080]speed[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// vertical movement*[/COLOR]
[COLOR=#808080]*// where are our edges?*[/COLOR]
[COLOR=#808080]*// first we look for y movement, so x is old*[/COLOR]
getMyCorners[COLOR=#000000]([/COLOR]ob.[COLOR=#000080]x[/COLOR], ob.[COLOR=#000080]y[/COLOR]+speed*diry, ob[COLOR=#000000])[/COLOR];
[COLOR=#808080]*// move got dammit... and check for collisions.*[/COLOR]
[COLOR=#808080]*// going up*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]diry == -[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]upleft[/COLOR] [COLOR=#0000FF]and[/COLOR] ob.[COLOR=#000080]upright[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#808080]*// no wall in the way, move on*[/COLOR]
        ob.[COLOR=#000080]y[/COLOR] += speed*diry;
    [COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#808080]*// hit the wall, place char near the wall*[/COLOR]
        ob.[COLOR=#000080]y[/COLOR] = ob.[COLOR=#000080]ytile[/COLOR]*game.[COLOR=#000080]tileH[/COLOR]+ob.[COLOR=#0000FF]height[/COLOR];
        [COLOR=#808080]*// are we jumping around and have hit the tile above?*[/COLOR]
        ob.[COLOR=#000080]jumpspeed[/COLOR] = [COLOR=#000080]0[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// if going down*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]diry == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]downleft[/COLOR] [COLOR=#0000FF]and[/COLOR] ob.[COLOR=#000080]downright[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]y[/COLOR] += speed*diry;
    [COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]y[/COLOR] = [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]ytile[/COLOR]+[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR]*game.[COLOR=#000080]tileH[/COLOR]-ob.[COLOR=#0000FF]height[/COLOR];
        ob.[COLOR=#000080]jump[/COLOR] = [COLOR=#000000]**false**[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// horisontal movement*[/COLOR]
[COLOR=#808080]*// changing x with speed and taking old y*[/COLOR]
getMyCorners[COLOR=#000000]([/COLOR]ob.[COLOR=#000080]x[/COLOR]+speed*dirx, ob.[COLOR=#000080]y[/COLOR], ob[COLOR=#000000])[/COLOR];
[COLOR=#808080]*// if going left*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]dirx == -[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]downleft[/COLOR] [COLOR=#0000FF]and[/COLOR] ob.[COLOR=#000080]upleft[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]x[/COLOR] += speed*dirx;
        [COLOR=#808080]*// check for tile below*[/COLOR]
        fall[COLOR=#000000]([/COLOR]ob[COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]x[/COLOR] = ob.[COLOR=#000080]xtile[/COLOR]*game.[COLOR=#000080]tileW[/COLOR]+ob.[COLOR=#0000FF]width[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// if going right*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]dirx == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]upright[/COLOR] [COLOR=#0000FF]and[/COLOR] ob.[COLOR=#000080]downright[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]x[/COLOR] += speed*dirx;
        [COLOR=#808080]*// check for tile below*[/COLOR]
        fall[COLOR=#000000]([/COLOR]ob[COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
        ob.[COLOR=#000080]x[/COLOR] = [COLOR=#000000]([/COLOR]ob.[COLOR=#000080]xtile[/COLOR]+[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR]*game.[COLOR=#000080]tileW[/COLOR]-ob.[COLOR=#0000FF]width[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// update char position*[/COLOR]
ob.[COLOR=#000080]clip[/COLOR].[COLOR=#0000FF]_x[/COLOR] = ob.[COLOR=#000080]x[/COLOR];
ob.[COLOR=#000080]clip[/COLOR].[COLOR=#0000FF]_y[/COLOR] = ob.[COLOR=#000080]y[/COLOR];
[COLOR=#808080]*// face the direction*[/COLOR]
ob.[COLOR=#000080]clip[/COLOR].[COLOR=#0000FF]gotoAndStop[/COLOR][COLOR=#000000]([/COLOR]dirx+diry*[COLOR=#000080]2[/COLOR]+[COLOR=#000080]3[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#808080]*// calculate the tile where chars center is*[/COLOR]
ob.[COLOR=#000080]xtile[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]floor[/COLOR][COLOR=#000000]([/COLOR]ob.[COLOR=#000080]clip[/COLOR].[COLOR=#0000FF]_x[/COLOR]/game.[COLOR=#000080]tileW[/COLOR][COLOR=#000000])[/COLOR];
ob.[COLOR=#000080]ytile[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]floor[/COLOR][COLOR=#000000]([/COLOR]ob.[COLOR=#000080]clip[/COLOR].[COLOR=#0000FF]_y[/COLOR]/game.[COLOR=#000080]tileH[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#808080]*// check for door*[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]game[COLOR=#000000][[/COLOR][COLOR=#FF0000]"t_"[/COLOR]+ob.[COLOR=#000080]ytile[/COLOR]+[COLOR=#FF0000]"_"[/COLOR]+ob.[COLOR=#000080]xtile[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000080]door[/COLOR] [COLOR=#0000FF]and[/COLOR] ob == [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]char[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#808080]*// make new map*[/COLOR]
    changeMap[COLOR=#000000]([/COLOR]ob[COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000FF]return[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#000000]}[/COLOR]
[COLOR=#000000]function[/COLOR] jumpCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]// gravity control[/COLOR]
ob.[COLOR=#000080]jumpspeed[/COLOR] = ob.[COLOR=#000080]jumpspeed[/COLOR]+ob.[COLOR=#000080]gravity[/COLOR];
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
ob.[COLOR=#000080]jumpspeed[/COLOR] = game.[COLOR=#000080]tileH[/COLOR]-char.[COLOR=#0000FF]height[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]// going up[/COLOR]
moveChar[COLOR=#000000]([/COLOR]ob, [COLOR=#000080]0[/COLOR], -[COLOR=#000080]1[/COLOR], -[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]// going down[/COLOR]
moveChar[COLOR=#000000]([/COLOR]ob, [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000FF]return[/COLOR] COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]

Thanks guys!