A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Super Simple Platform Game Engine ^_^

  1. #1
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173

    Super Simple Platform Game Engine ^_^

    Im in the works of making a super simple platform game engine...

    and wanted to see if anyone wants to help out/has some ideas/knows why im going to absolutely fail...

    anyways its only 154 lines of script or something like that right now, and its functional enough to see the idea...


    Im having a little trouble with the walls, and setting up a loop to hit test all the objects instead of a long or statement...

    anyways INPUT IS APPRECIATED GREATLY!

    and it would be nice if someone could point out how to do the hittests better...


    var xspeed = 0;
    var yspeed = 0;
    var accelleration = 2;
    var friction = 0.95;
    var maxspeed = 5;
    var gravity = 0.25;
    var jumpdelay = 0;
    var leftKeyDown:Boolean = false;
    var upKeyDown:Boolean = false;
    var rightKeyDown:Boolean = false;
    var downKeyDown:Boolean = false;
    var groundcontact:Boolean = false;
    var climbingstatus:Boolean = false;


    addEventListener(Event.ENTER_FRAME,enterframe);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
    function checkKeysDown(event:KeyboardEvent):void
    {
    //making the booleans true based on the keycode
    //WASD Keys or arrow keys
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = true;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = true;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = true;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = true;
    }
    }

    //this listener will listen for keys being released
    stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
    function checkKeysUp(event:KeyboardEvent):void
    {
    //making the booleans false based on the keycode
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = false;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = false;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = false;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = false;
    }
    }

    function enterframe(event:Event)
    {
    if (jumpdelay >= 120)
    {

    }
    else
    {
    jumpdelay += 1;
    }
    trace(jumpdelay);
    if (leftKeyDown == true)
    {
    xspeed += 0.25;
    }
    else if (rightKeyDown == true)
    {
    xspeed -= 0.25;
    }


    if (xspeed >= maxspeed || xspeed <= maxspeed * -1)
    {
    if (xspeed >= 0)
    {
    xspeed = maxspeed;
    }
    else
    {
    xspeed = maxspeed * -1;
    }
    }
    var i = 1;
    if (groundcontact == false)
    {
    yspeed -= gravity;


    if (player_mc.hitTestObject(stage_mc.block_mc1) || player_mc.hitTestObject(stage_mc.block_mc2) || player_mc.hitTestObject(stage_mc.block_mc3) || player_mc.hitTestObject(stage_mc.block_mc4))
    {
    yspeed = 0;
    groundcontact = true;
    }
    }
    else if (groundcontact == true)
    {
    if (player_mc.hitTestObject(stage_mc.block_mc1) || player_mc.hitTestObject(stage_mc.block_mc2) || player_mc.hitTestObject(stage_mc.block_mc3) || player_mc.hitTestObject(stage_mc.block_mc4))
    {
    stage_mc.y += 1;
    }
    if (upKeyDown == true)
    {
    if (jumpdelay <= 119)
    {

    }
    else
    {
    yspeed += 6;
    jumpdelay = 0;
    groundcontact = false;
    }
    }
    }

    if (player_mc.hitTestObject(stage_mc.skyblock_mc1) || player_mc.hitTestObject(stage_mc.skyblock_mc2) || player_mc.hitTestObject(stage_mc.skyblock_mc3) || player_mc.hitTestObject(stage_mc.skyblock_mc4) || player_mc.hitTestObject(stage_mc.skyblock_mc5))
    {
    groundcontact = false;
    }
    if (player_mc.hitTestObject(stage_mc.ladder_mc1) || player_mc.hitTestObject(stage_mc.ladder_mc2))
    {
    yspeed = 2;
    groundcontact = false;
    climbingstatus = true;

    }
    else
    {
    climbingstatus = false;
    }
    if (player_mc.hitTestObject(stage_mc.wall_mc1) || player_mc.hitTestObject(stage_mc.wall_mc2))
    {
    if (climbingstatus = true)
    {
    xspeed *= -1;
    }
    else
    {
    xspeed *= -1;
    yspeed *= -1;
    }
    }



    xspeed *= friction;
    if (xspeed <= 0.1 && xspeed >= 0)
    {
    xspeed = 0;
    }
    if (xspeed >= -0.1 && xspeed <= 0)
    {
    xspeed = 0;
    }
    stage_mc.y += yspeed;
    stage_mc.x += xspeed;

    }





    EDIT **** DO NOT VIEW THIS FLA! its SUPER OLD
    Attached Files Attached Files
    Last edited by YBAB; 04-15-2011 at 10:46 PM.

  2. #2
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    ok this Original programing was not going to do the trick...

    so I am revamping the system and it is working a lot better...

    Umm, still having slight trouble with the way the character reacts when it hits a wall going side to side, Im about to add the tracking for the head also...

    afterwards the goal now it to make it so that I can keep track of registered points of a movieclip inside a movie clip for things like the feet, which will allow rotation of the character and slanted surfaces with rotation of the main character to stand on these surfaces...



    var xspeed = 0;
    var yspeed = 0;
    var accelleration = 2;
    var friction = 0.95;
    var maxspeed = 5;
    var gravity = 0.25;
    var jumpdelay = 0;
    var leftKeyDown:Boolean = false;
    var upKeyDown:Boolean = false;
    var rightKeyDown:Boolean = false;
    var downKeyDown:Boolean = false;

    var centerGC:Boolean = false;
    var leftlegGC:Boolean = false;
    var rightlegGC:Boolean = false;
    var leftarmC:Boolean = false;
    var rightarmC:Boolean = false;

    var climbingstatus:Boolean = false;

    addEventListener(Event.ENTER_FRAME,enterframe);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
    function checkKeysDown(event:KeyboardEvent):void
    {
    //making the booleans true based on the keycode
    //WASD Keys or arrow keys
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = true;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = true;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = true;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = true;
    }
    }

    //this listener will listen for keys being released
    stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);

    function checkKeysUp(event:KeyboardEvent):void
    {
    //making the booleans false based on the keycode
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = false;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = false;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = false;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = false;
    }
    }

    function enterframe(event:Event)
    {
    var leftLegx:int = player_mc.x - 14;
    var leftLegy:int = player_mc.y + 20;
    var rightLegx:int = player_mc.x + 14;
    var rightLegy:int = player_mc.y + 20;
    var centerx:int = player_mc.x;
    var centery:int = player_mc.y + 19;
    var leftarmx:int = player_mc.x - 20;
    var leftarmy:int = player_mc.y - 5;
    var rightarmx:int = player_mc.x + 20;
    var rightarmy:int = player_mc.y - 5;


    //jump delay

    if (jumpdelay >= 60)
    {

    }
    else
    {
    jumpdelay += 1;
    }
    trace(jumpdelay);

    function jumpgo()
    {

    if (jumpdelay <= 59)
    {

    }
    else
    {
    yspeed += 6;
    jumpdelay = 0;


    }
    }




    //left right motion
    if (leftKeyDown == true)
    {
    xspeed += 0.25;
    }
    else if (rightKeyDown == true)
    {
    xspeed -= 0.25;
    }
    if (xspeed >= maxspeed || xspeed <= maxspeed * -1)
    {
    if (xspeed >= 0)
    {
    xspeed = maxspeed;
    }
    else
    {
    xspeed = maxspeed * -1;
    }
    }

    //No Contact to the ground
    if (leftlegGC == false && rightlegGC == false && centerGC == false)
    {
    yspeed -= gravity;
    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy, true))
    {
    xspeed *= -0.5;
    }
    else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarm y,true))
    {
    xspeed *= -0.5;
    }
    }
    else if (leftlegGC == false && rightlegGC == true && centerGC == false)
    {

    }
    else if (leftlegGC == true && rightlegGC == false && centerGC == false)
    {

    }
    else if (leftlegGC == true && rightlegGC == true && centerGC == false)
    {

    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy, true))
    {
    xspeed *= -0.5;
    }
    else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarm y,true))
    {
    xspeed *= -0.5;
    }
    }

    //Left Leg Contact
    if (stage_mc.block_mc.hitTestPoint(leftLegx,leftLegy, true))
    {
    if (upKeyDown == true)
    {
    jumpgo();
    }
    else
    {
    yspeed = 0;
    leftlegGC = true;
    }

    }
    else
    {
    leftlegGC = false;
    }
    //right leg contact;
    if (stage_mc.block_mc.hitTestPoint(rightLegx,rightLeg y,true))
    {
    if (upKeyDown == true)
    {
    jumpgo();
    }
    else
    {
    yspeed = 0;
    rightlegGC = true;
    }
    }
    else
    {
    rightlegGC = false;
    }
    //middlebody contact
    if (stage_mc.block_mc.hitTestPoint(centerx,centery,tr ue))
    {
    yspeed = 0;
    centerGC = true;
    stage_mc.y += 1;
    }
    else
    {
    centerGC = false;
    }

    //friction
    xspeed *= friction;
    if (xspeed <= 0.1 && xspeed >= 0)
    {
    xspeed = 0;
    }
    if (xspeed >= -0.1 && xspeed <= 0)
    {
    xspeed = 0;
    }

    //exicute movement
    stage_mc.y += yspeed;
    stage_mc.x += xspeed;


    }
    Attached Files Attached Files

  3. #3
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    I found that a simple change of :
    Actionscript Code:
    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy,true))
            {
                xspeed -=  1;
            }
            else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarmy,true))
            {
                xspeed +=  1;
            }
    from the original

    Actionscript Code:
    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy, true))
    {
    xspeed *= -0.5;
    }
    else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarm y,true))
    {
    xspeed *= -0.5;
    }

    makes a huge difference in the reaction of the impact on vertical surfaces.



    my assignment to you guys is to make these things react better and look for ways to improve the script and the reaction to "walls"


    *****EDIT

    yea I looked at it and actually thought about it and came up with the replacement function, that takes away the repetitive script of the arm check... also it is much more efficient!

    function wallhit(){
    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy, true))
    {
    if (xspeed >= 1.5)
    {
    xspeed *= -0.5;
    }
    else if (xspeed<=0.5)
    {
    xspeed -= 1;
    }
    else
    {
    xspeed -= 0.5;
    }
    }
    else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarm y,true))
    {
    if (xspeed >= 1.5)
    {
    xspeed *= -0.5;
    }
    else if (xspeed<=0.5)
    {
    xspeed += 1;
    }
    else
    {
    xspeed += 0.5;
    }
    }
    }
    Last edited by YBAB; 04-15-2011 at 01:07 AM.

  4. #4
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173

    Update!

    ok i have introduced water, and ladders again...

    let me know if yall can help me out with the error im getting when the character is in contact with the ground while in the water.



    var xspeed = 0;
    var yspeed = 0;
    var accelleration = 2;
    var friction = 0.95;
    var maxspeed = 5;
    var gravity = 0.25;
    var jumpdelay = 0;
    var leftKeyDown:Boolean = false;
    var upKeyDown:Boolean = false;
    var rightKeyDown:Boolean = false;
    var downKeyDown:Boolean = false;

    //charicter States
    var centerGC:Boolean = false;
    var leftlegGC:Boolean = false;
    var rightlegGC:Boolean = false;
    var bodyinwater:Boolean = false;
    var headinwater:Boolean = false;
    var climbingstatus:Boolean = false;

    addEventListener(Event.ENTER_FRAME,enterframe);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
    function checkKeysDown(event:KeyboardEvent):void
    {
    //making the booleans true based on the keycode
    //WASD Keys or arrow keys
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = true;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = true;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = true;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = true;
    }
    }

    //this listener will listen for keys being released
    stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);

    function checkKeysUp(event:KeyboardEvent):void
    {
    //making the booleans false based on the keycode
    if (event.keyCode == 37 || event.keyCode == 65)
    {
    leftKeyDown = false;
    }
    if (event.keyCode == 38 || event.keyCode == 87)
    {
    upKeyDown = false;
    }
    if (event.keyCode == 39 || event.keyCode == 68)
    {
    rightKeyDown = false;
    }
    if (event.keyCode == 40 || event.keyCode == 83)
    {
    downKeyDown = false;
    }
    }

    //main Engine
    function enterframe(event:Event)
    {
    //Charicter Hit test definitions
    var leftLegx:int = player_mc.x - 14;
    var leftLegy:int = player_mc.y + 20;
    var rightLegx:int = player_mc.x + 14;
    var rightLegy:int = player_mc.y + 20;
    var centerx:int = player_mc.x;
    var centery:int = player_mc.y + 19;
    var leftarmx:int = player_mc.x - 20;
    var leftarmy:int = player_mc.y - 5;
    var rightarmx:int = player_mc.x + 20;
    var rightarmy:int = player_mc.y - 5;
    var headx:int = player_mc.x;
    var heady:int = player_mc.y - 20;


    //jump delay
    if (bodyinwater == true && headinwater == true)
    {
    if (upKeyDown == true)
    {
    yspeed += 0.25;
    if (yspeed >= 1.75)
    {
    yspeed = 1.75;
    }
    }
    }
    else
    {
    if (jumpdelay >= 60)
    {

    }
    else
    {
    jumpdelay += 1;
    }
    trace(jumpdelay);

    function jumpgo()
    {

    if (jumpdelay <= 59)
    {

    }
    else
    {
    yspeed += 6;
    jumpdelay = 0;


    }
    }
    }



    //left right motion
    if (leftKeyDown == true)
    {
    xspeed += 0.25;
    }
    else if (rightKeyDown == true)
    {
    xspeed -= 0.25;
    }
    if (xspeed >= maxspeed || xspeed <= maxspeed * -1)
    {
    if (xspeed >= 0)
    {
    xspeed = maxspeed;
    }
    else
    {
    xspeed = maxspeed * -1;
    }
    }

    // arm hittest
    function wallhit()
    {
    if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy, true))
    {
    if (xspeed >= 1.5)
    {
    xspeed *= -0.5;
    }
    else if (xspeed<=0.5)
    {
    xspeed -= 1;
    }
    else
    {
    xspeed -= 0.5;
    }
    }
    else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarm y,true))
    {
    if (xspeed >= 1.5)
    {
    xspeed *= -0.5;
    }
    else if (xspeed<=0.5)
    {
    xspeed += 1;
    }
    else
    {
    xspeed += 0.5;
    }
    }
    else if (stage_mc.block_mc.hitTestPoint(headx,heady,true))
    {
    yspeed = 0;
    stage_mc.y -= 1;
    }
    }

    //No Contact to the ground
    if (leftlegGC == false && rightlegGC == false && centerGC == false)
    {
    yspeed -= gravity;
    wallhit();

    }
    else if (leftlegGC == false && rightlegGC == true && centerGC == false)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == false && centerGC == false)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == true && centerGC == false)
    {
    wallhit();
    }
    else if (leftlegGC == false && rightlegGC == false && centerGC == false && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == false && centerGC == false && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == false && rightlegGC == true && centerGC == false && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == true && centerGC == false && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == false && centerGC == true && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == false && rightlegGC == true && centerGC == true && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }
    else if (leftlegGC == true && rightlegGC == true && centerGC == true && bodyinwater == true && headinwater == true)
    {
    wallhit();
    }





    //Left Leg Contact
    if (stage_mc.block_mc.hitTestPoint(leftLegx,leftLegy, true))
    {
    if (upKeyDown == true)
    {
    jumpgo();
    }
    else
    {
    yspeed = 0;
    leftlegGC = true;
    }

    }
    else
    {
    leftlegGC = false;
    }
    //right leg contact;
    if (stage_mc.block_mc.hitTestPoint(rightLegx,rightLeg y,true))
    {
    if (upKeyDown == true)
    {
    jumpgo();
    }
    else
    {
    yspeed = 0;
    rightlegGC = true;
    }
    }
    else
    {
    rightlegGC = false;
    }
    //middlebody contact
    if (stage_mc.block_mc.hitTestPoint(centerx,centery,tr ue))
    {
    yspeed = 0;
    centerGC = true;
    stage_mc.y += 1;
    }
    else
    {
    centerGC = false;
    }
    //LADDER HIT TEST
    if (stage_mc.ladder_mc.hitTestPoint(centerx,centery,t rue))
    {
    yspeed += 0.5;
    if (yspeed >= 2)
    {
    yspeed = 2;
    }
    }

    if (stage_mc.water_mc.hitTestPoint(centerx,centery,tr ue))
    {
    bodyinwater = true;
    gravity = 0.1;
    if (stage_mc.water_mc.hitTestPoint(headx,heady,true))
    {
    headinwater = true;
    }
    else
    {
    headinwater = false;
    if (upKeyDown == true)
    {
    jumpgo();
    }
    }
    }
    else
    {
    bodyinwater = true;
    gravity = 0.25;
    }


    //friction
    xspeed *= friction;
    if (xspeed <= 0.1 && xspeed >= 0)
    {
    xspeed = 0;
    }
    if (xspeed >= -0.1 && xspeed <= 0)
    {
    xspeed = 0;
    }

    //exicute movement
    stage_mc.y += yspeed;
    stage_mc.x += xspeed;

    }
    Attached Files Attached Files
    Last edited by YBAB; 04-15-2011 at 04:19 PM.

  5. #5
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173

    Update!

    ok i have introduced water, and ladders again...

    let me know if yall can help me out with the error im getting when the character is in contact with the ground while in the water.


    Actionscript Code:
    var xspeed = 0;
    var yspeed = 0;
    var accelleration = 2;
    var friction = 0.95;
    var maxspeed = 5;
    var gravity = 0.25;
    var jumpdelay = 0;
    var leftKeyDown:Boolean = false;
    var upKeyDown:Boolean = false;
    var rightKeyDown:Boolean = false;
    var downKeyDown:Boolean = false;

    //charicter States
    var centerGC:Boolean = false;
    var leftlegGC:Boolean = false;
    var rightlegGC:Boolean = false;
    var bodyinwater:Boolean = false;
    var headinwater:Boolean = false;
    var climbingstatus:Boolean = false;

    addEventListener(Event.ENTER_FRAME,enterframe);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
    function checkKeysDown(event:KeyboardEvent):void
    {
        //making the booleans true based on the keycode
        //WASD Keys or arrow keys
        if (event.keyCode == 37 || event.keyCode == 65)
        {
            leftKeyDown = true;
        }
        if (event.keyCode == 38 || event.keyCode == 87)
        {
            upKeyDown = true;
        }
        if (event.keyCode == 39 || event.keyCode == 68)
        {
            rightKeyDown = true;
        }
        if (event.keyCode == 40 || event.keyCode == 83)
        {
            downKeyDown = true;
        }
    }

    //this listener will listen for keys being released
    stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);

    function checkKeysUp(event:KeyboardEvent):void
    {
        //making the booleans false based on the keycode
        if (event.keyCode == 37 || event.keyCode == 65)
        {
            leftKeyDown = false;
        }
        if (event.keyCode == 38 || event.keyCode == 87)
        {
            upKeyDown = false;
        }
        if (event.keyCode == 39 || event.keyCode == 68)
        {
            rightKeyDown = false;
        }
        if (event.keyCode == 40 || event.keyCode == 83)
        {
            downKeyDown = false;
        }
    }

    //main Engine
    function enterframe(event:Event)
    {
        //Charicter Hit test definitions
        var leftLegx:int = player_mc.x - 14;
        var leftLegy:int = player_mc.y + 20;
        var rightLegx:int = player_mc.x + 14;
        var rightLegy:int = player_mc.y + 20;
        var centerx:int = player_mc.x;
        var centery:int = player_mc.y + 19;
        var leftarmx:int = player_mc.x - 20;
        var leftarmy:int = player_mc.y - 5;
        var rightarmx:int = player_mc.x + 20;
        var rightarmy:int = player_mc.y - 5;
        var headx:int = player_mc.x;
        var heady:int = player_mc.y - 20;


        //jump delay
        if (bodyinwater == true && headinwater == true)
        {
            if (upKeyDown == true)
            {
                yspeed +=  0.25;
                if (yspeed >= 1.75)
                {
                    yspeed = 1.75;
                }
            }
        }
        else
        {
            if (jumpdelay >= 60)
            {

            }
            else
            {
                jumpdelay +=  1;
            }
            trace(jumpdelay);

            function jumpgo()
            {

                if (jumpdelay <= 59)
                {

                }
                else
                {
                    yspeed +=  6;
                    jumpdelay = 0;


                }
            }
        }



        //left right motion
        if (leftKeyDown == true)
        {
            xspeed +=  0.25;
        }
        else if (rightKeyDown == true)
        {
            xspeed -=  0.25;
        }
        if (xspeed >= maxspeed || xspeed <= maxspeed * -1)
        {
            if (xspeed >= 0)
            {
                xspeed = maxspeed;
            }
            else
            {
                xspeed = maxspeed * -1;
            }
        }

        // arm hittest
        function wallhit()
        {
            if (stage_mc.block_mc.hitTestPoint(leftarmx,leftarmy,true))
            {
                if (xspeed >= 1.5)
                {
                    xspeed *=  -0.5;
                }
                else if (xspeed<=0.5)
                {
                    xspeed -=  1;
                }
                else
                {
                    xspeed -=  0.5;
                }
            }
            else if (stage_mc.block_mc.hitTestPoint(rightarmx,rightarmy,true))
            {
                if (xspeed >= 1.5)
                {
                    xspeed *=  -0.5;
                }
                else if (xspeed<=0.5)
                {
                    xspeed +=  1;
                }
                else
                {
                    xspeed +=  0.5;
                }
            }
            else if (stage_mc.block_mc.hitTestPoint(headx,heady,true))
            {
                yspeed = 0;
                stage_mc.y -=  1;
            }
        }

        //No Contact to the ground
        if (leftlegGC == false && rightlegGC == false && centerGC == false)
        {
            yspeed -=  gravity;
            wallhit();

        }
        else if (leftlegGC == false && rightlegGC == true && centerGC == false)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == false && centerGC == false)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == true && centerGC == false)
        {
            wallhit();
        }
        else if (leftlegGC == false && rightlegGC == false && centerGC == false && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == false && centerGC == false && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == false && rightlegGC == true && centerGC == false && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == true && centerGC == false && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == false && centerGC == true && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == false && rightlegGC == true && centerGC == true && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }
        else if (leftlegGC == true && rightlegGC == true && centerGC == true && bodyinwater == true && headinwater == true)
        {
            wallhit();
        }





        //Left Leg Contact
        if (stage_mc.block_mc.hitTestPoint(leftLegx,leftLegy,true))
        {
            if (upKeyDown == true)
            {
                jumpgo();
            }
            else
            {
                yspeed = 0;
                leftlegGC = true;
            }

        }
        else
        {
            leftlegGC = false;
        }
        //right leg contact;
        if (stage_mc.block_mc.hitTestPoint(rightLegx,rightLegy,true))
        {
            if (upKeyDown == true)
            {
                jumpgo();
            }
            else
            {
                yspeed = 0;
                rightlegGC = true;
            }
        }
        else
        {
            rightlegGC = false;
        }
        //middlebody contact
        if (stage_mc.block_mc.hitTestPoint(centerx,centery,true))
        {
            yspeed = 0;
            centerGC = true;
            stage_mc.y +=  1;
        }
        else
        {
            centerGC = false;
        }
        //LADDER HIT TEST
        if (stage_mc.ladder_mc.hitTestPoint(centerx,centery,true))
        {
            yspeed +=  0.5;
            if (yspeed >= 2)
            {
                yspeed = 2;
            }
        }

        if (stage_mc.water_mc.hitTestPoint(centerx,centery,true))
        {
            bodyinwater = true;
            gravity = 0.1;
            if (stage_mc.water_mc.hitTestPoint(headx,heady,true))
            {
                headinwater = true;
            }
            else
            {
                headinwater = false;
                if (upKeyDown == true)
                {
                    jumpgo();
                }
            }
        }
        else
        {
            bodyinwater = true;
            gravity = 0.25;
        }


        //friction
        xspeed *=  friction;
        if (xspeed <= 0.1 && xspeed >= 0)
        {
            xspeed = 0;
        }
        if (xspeed >= -0.1 && xspeed <= 0)
        {
            xspeed = 0;
        }

        //exicute movement
        stage_mc.y +=  yspeed;
        stage_mc.x +=  xspeed;

    }

    EDIT***

    I fixed the way you act in the water...

    umm moving on to program hang able tiles...

  6. #6
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    http://ybab.webs.com/gameengine2.swf

    for those who dont wanna download the FLA and still see whats going on.


    EDIT********

    Updated... fixed gravity fields and water...
    Last edited by YBAB; 04-15-2011 at 11:36 PM.

  7. #7
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    709
    Haha, it seems to be a one man topic, but actually the engine is pretty cool. You could make a cool game with it.

  8. #8
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    yea Ive just been posting updates to it on here...

    I'm working on a modified version of the engine to show its versatility, by making a top down marble game also...

    So I have this engine in development with two different titles being worked on in parallel, If you have any suggestions let me know!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center