Metroidvania engine with bugs... help.. please

On and off through the years I have come and gone with Actionscript, often I ended up getting frustrated and not messing with it for months at a time… Somehow, I just got bit recently, and started going pretty hard…

Using Nathans tutorial on platformers (which I have studied through the years, and understand pretty well by now)… I am still no AS expert… however, as inefficient as my code is, it is through much trial, error, research and brain busting starting to do what I want it to do…

I will post the whole code down below, explaining what I did, (either intentionally or accidentally), and why… What I am here for is someone to give me suggestions how I could make this more efficient, smooth…etc… I am certain my code get’s very redundant and needless in place… But this is where I am.

For starters, I modified the attacking, walking and jumping, in minor ways… to make it closer to the classic castlevania engine… In the original tut, you could not jump and attack, nor could you jump up and move and attack… now you can…

How efficient it is… that’s another story.

Also, I added Y scrolling… which is pretty smooth, and could probably be done in less lines…

Finally, there is now a double jump… when the character get’s an item, he is able to perform a (really bad and glitchy) double jump…

I’ve been sitting on this project for way too long…So one way or another, it’s going to get finished… Finally, I know that I should probably be doing something like this in a more tile based setting, but at this point, I am more concerned with getting the hang of working with variables, conditions, and functions under control…

If anyone can help me out here, with any tips, insight, pointers, whatever…

Thanks.

Code:
onClipEvent (load) {
speed = 0;
Fall = 6;
_this._x = 0;
_root._x = 0;
_root._y = 0;
healthX = _root.health._x;
healthY = +root.health._y;
scoreX = _root.score._x;
Xpos = this._x;
Ypos = this._y;
maxmove = 15;
//////////////////////
////Ammendment 1//
//////////////////
healthX = _root.health._x;
//sets healthX to the starting X postition of the “health” MC
scoreX = _root.score._x;
//sets scoreX to the starting X postition of the “score” MC
Xpos = this._x;
//sets Xpos to the starting X postition of this MC
Ypos = this._y;
//sets Ypos to the starting Y postition of this MC
////////////////
///////
maxmove = 15;
// maxmove is fifteen(max run seed)
_root.maxshoottime = 100;
// _root.maxshoottime is set to 100
// this is how far you want the bullets to travel before deleting
}
onClipEvent (enterFrame) {
if (!gamepaused){
//////////////////////
////Ammendment 2//
//////////////////
_x = Xpos-_root._x;
//sets the X pos to the starting X postition of this MC
_root.score._x = scoreX-_root._x;
//sets the scire MCs X pos to its starting point on the screen
_root.health._x = healthX-_root._x;
//sets the health MCs X pos to its starting point on the screen
if (!_root.ground.hitTest(this._x, this._y, true) && !jumping && !jumpinga) {
// if NOT hitting X and Y postion with the ground and NOT jumping
this._y = this._y+6;
falling = true;
_root._y = _root._y-fall;
_root.health._y = _root.health._y+fall;
_root.cash._y = _root.cash._y+fall;

}

}
////////////////
///////
if (!_root.shooting) {
// if _root.shooting is false
_root.timer = 0;
// _root.timer is set to 0
_root.mvsp = _xscale/20;
// _root.mvsp is set to the chars xscale divided by 20
// the answer to this is the speed of the bullets
}
if (_root.dead) {
// if dead is true
this.gotoAndStop(“dead”);
// goto and stop on the “dead” frame
} else {
// otherwise (if they are not dead)
speed *= .85;
// speed is multiplied by .85
// the lower the faster is slows
if (dir == “right” && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
_root.health._x += speed;
// moves the health, the opposite way to the _root
_root.score._x += speed;
// moves the score, the opposite way to the _root
this._x += speed;
// moves the char, the opposite way to the _root
_root._x -= speed;
// moves the _root
}
//////////////////////
////Ammendment 3//
//////////////////
if (speed>0) {
//if speed is smaller than 0
dir = “right”;
// the variable dir is set to right
} else if (speed<0) {
//if speed is greater than 0
dir = “left”;
// the var dir is set to left
}
if (dir == “left” && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
_root.health._x += speed;
// moves the health, the opposite way to the _root
_root.score._x += speed;
// moves the score, the opposite way to the _root
this._x += speed;
// moves the char, the opposite way to the _root
_root._x -= speed;
// moves the _root
}
if (Key.isDown(Key.LEFT) && !attacking) {
// if left is pressed
speed–;
walking = true;
// speed goes lower
// goto and stop the run frame
this._xscale = -100;
// scale is set to neg. 100
// this is what rotates ur char
///////////////////
///////////////
} else if (Key.isDown(Key.RIGHT) && !attacking) {
// otherwise if right is pressed
speed++;
walking = true;
// speed goes up
this._xscale = 100;
// scale is set to 100
// this is what rotates ur char
// goto and stop the run frame
} else if (Key.isDown(Key.RIGHT) && attacking && jumping) {
// otherwise if right is pressed
speed++;
attacking == true;
// speed goes up
this._xscale = 100;
// scale is set to 100
// this is what rotates ur char
// goto and stop the run frame
} else if (Key.isDown(Key.LEFT) && attacking && jumping) {
// if left is pressed
speed–;
attacking = true;
// speed goes lower
// goto and stop the run frame
this._xscale = -100;
// scale is set to neg. 100
// this is what rotates ur char
///////////////////
///////////////
}
if (walking && !falling) {
this.gotoAndStop(“run”);
///////////////
}
if (Key.isDown(Key.CONTROL)) {
// otherwise if control is pressed
attacking = true;
walking = false;
}
if (attacking) {
this.gotoAndStop(“attack”);
// goto and stop the attack frame
}
if (falling && !jumping) {
this.gotoAndStop(“jump”);
walking = false;
speed = 0;

    } else if (falling && attacking ||fallinga|| attacking && walking) {
        falling == false;
        attacking == true;
    } else if (speed&lt;1 && speed&gt;-1 && !attacking) {
        // if speed is smaller than one and greater than neg. 1
        speed = 0;
        // speed is set to 0
        this.gotoAndStop("idle");
        // gotoAndStop the idle frame
    }
}
    if (Key.isDown(Key.SHIFT) && !jumping && !jumpinga) {
        // if up is pressed and NOT jumping
        jumping = true;
         
        // jumping is set true
     
    }
    // jumping is set true 
    if (jumping && !attacking) {
        // if jumping is true
        this.gotoAndStop("jump");
        this._y = this._y-jump;
        _root._y = _root._y+jump;
        _root.health._y = _root.health._y-jump;
        _root.cash._y = _root.cash._y-jump;
        // Y position is set down jump
        jump -= .5;
        // jump is set down .5
        if (jump&lt;0) {
            // if jump is smaller than 0
            falling = true;
            // falling is true
        }
        if (jump&lt;-5) {
            // if jump is smaller than neg. 5
            jump = -5;
            // jump is set to neg 5
            // capping fall speeds prevents falling through grounds
        }
        if (Key.isDown(Key.SHIFT) && !jumping) {
            // if up is pressed and NOT jumping
            jumping = true;
            // jumping is set true
        } 
     
    }
    if (jumping && attacking) {
        walking = false;
        this.gotoAndStop("attack");
        this._y = this._y-jump;
        _root._y = _root._y+jump;
        _root.health._y = _root.health._y-jump;
        _root.cash._y = _root.cash._y-jump;
        // Y position is set down jump
        jump -= .5;
        // jump is set down .5
        if (jump&lt;0  && !jumpinga) {
            // if jump is smaller than 0
            falling = true;
            // falling is true
        }
        if (jump&lt;-15) {
            // if jump is smaller than neg. 5
            jump = -5;
            // jump is set to neg 5
            // capping fall speeds prevents falling through grounds
        }
    }
    if (_root.ground.hitTest(this._x, this._y, true) && falling) {
        // if hitting X an Y postions with the ground and falling
        jump = 7;
        // jump is set to 9
        jumping = false;
        // jumping is false
        falling = false;
        // falling is false

}
if (_root.gotBoots == true && !_root.jumpinga) {

    if (Key.isDown(Key.UP) && jump&lt;7.0) {
        // if up is pressed and NOT jumping
         jumpinga=true
        // jumping is set true
    }
    // jumping is set true 
    if (jumpinga && !attacking) {
        // if jumping is true
        this.gotoAndStop("jump");
        this._y = this._y-jumpa;
        _root._y = _root._y+jumpa;
        _root.health._y = _root.health._y-jumpa;
        _root.cash._y = _root.cash._y-jumpa;
        // Y position is set down jump
        jumpa -= .5;
        // jump is set down .5
        if (jumpa&lt;0) {
            // if jump is smaller than 0
            fallinga = true;
            // falling is true
        }
        if (jump &lt;-15) {
            // if jump is smaller than neg. 5
            jump = -5;
            // jump is set to neg 5
            // capping fall speeds prevents falling through grounds
        } 
        if (Key.isDown(Key.UP)  && (Key.isDown(Key.SHIFT))) {
            // if up is pressed and NOT jumping
            jumpinga = true;
            jumping =false;
            // jumping is set true
         
        }
     
    }

    if (_root.ground.hitTest(this._x, this._y, true) && fallinga) {
        // if hitting X an Y postions with the ground and falling
        jumpa = 9;
        // jump is set to 9
        jumpinga = false;
        // jumping is false
        fallinga = false;
        // falling is false
    }

}
}
onClipEvent (keyUp) {
// on Key Up
if (Key.getCode() == Key.CONTROL) {
// if the release is control
attacking = false;
// attacking is false
}

}