Charactor is not hanging & jumping down properly?

Hi,

Guyes!

This is prafull, I am working on one platform type game where charactor will walk,jump in the air, hang on the ledge and again while pressing the up key he will climb up and stand on the ledge,he can walk on the ledge after ledge is finish he will jump down.

Please see the attach file and you will come to known what will be the problem.

Please guide me!

Please see the code:

stop();
Stage.showMenu = false;
Stage.scaleMode = “noBorder”;
//-----------------------------------------------------------------------------//
//Variables & Ojectes//
//-----------------------------------------------------------------------------//
fscommand(“fullscreen”, true);
fscommand(“showmenu”, false);
score = 0;
health.text = 100;
en_in = false;
en_out = false;
hang = false;
fast_speed = 30;
normal_speed = 15;
to_run_timeout = 4000;
prev_time = getTimer();
current_time = prev_time;
speed_countdown_timer = 0;
document.frameRate = normal_speed;
enemy_timeout = 12000;
vel_y = 0;
accel = 4;
jumping = false;
hero_bounds = new Object();
hero_bounds = hero.getBounds(this);
t_edge = hero_bounds.xMin;
b_edge = hero_bounds.yMin;
curStage = 1;
ground = 5;
hero.climbing = false;
enemy0._x = 1000;
waitCount = 0;
blinkCount = 0;
hp = 100;
Points = 0;
lastCheckpoint = [];
hanging1 = false;
hanging2 = false;
changeStage = false;
walk = false;
upFlage = false;
jumpFlage = false;
onTheLedge1 = false;
onTheLedge2 = false;
jumpDown = false;
jumpup = false;
//----------------------------------------------------------------------------//
this.onLoad = function() {
Direction = “Right”;
};
//----------------------------------------------------------------------------//
this.onEnterFrame = function() {
//trace(" Direction :"+Direction);
origYpos = hero._y;
//trace(“origYpos :”+origYpos);
speed = normal_speed;
hpBar._xscale = hp;
if (hp<0) {
hp = 0;
if (hp == 0) {
gotoAndStop(“End”);
}
}
//-----------------------------------------------------------------------------//
//Hero will Stand on the platform//
//-----------------------------------------------------------------------------//
if (platforms.hitTest(hero._x, hero._y+hero._height/2, true)) {
platform = “on”;
upFlage = false;
}
//-----------------------------------------------------------------------------//
//check if enemy is hit//
//-----------------------------------------------------------------------------//
if (hero.hitTest(enemy0)) {
Points = score;
//gotoAndStop(“End”);
}
//-----------------------------------------------------------------------------//
// If Hero hits the Ledge// //-----------------------------------------------------------------------------//
for (t=1; t<=6; t++) {
if (hero.hitTest(eval(“s_hit”+t))) {
trace("???..");
c_l = eval(“s_hit”+t);
trace(“Name of the hiting thing :”+c_l._name);
if (curStage == 3) {
hanging1 = false;
hanging2 = false;
jumpup = false;
//trace(“hero collides with s_hit from Right”);
}
}

}
if (hero.hitTest(ledge_wall1)) {
jumpup = true;
ledge_wall1_bounds = new Object();
ledge_wall1_bounds = ledge_wall1.getBounds(this);
if (Direction == “Right”) {
hanging1 = true;
hanging2 = false;
trace("hanging1 - “+hanging1);
}
if (Direction == “Left”) {
hanging1 = false;
}
}
if (hero.hitTest(ledge_wall2)) {
jumpup = true;
ledge_wall2_bounds = new Object();
ledge_wall2_bounds = ledge_wall2.getBounds(this);
trace(“hero hit the ledge_wall2”);
if (Direction == “Left”) {
//if (hero_bounds.xMin<=ledge_wall2_bounds.xMax) {
trace(” hit hanging2 will change - “+hanging2);
hanging2 = true;
hanging1 = false;
}
if (Direction == “Right”) {
hanging2 = false;
}
}
if (hero.hitTest(ledge_wall3)) {
jumpup = true;
trace(“hero hit the ledge_wall3”);
ledge_wall1_bounds = new Object();
ledge_wall1_bounds = ledge_wall1.getBounds(this);
if (Direction == “Right”) {
hanging1 = true;
hanging2 = false;
}
if (Direction == “Left”) {
hanging1 = false;
}
}
if (hero.hitTest(ledge_wall4)) {
jumpup = true;
trace(“hero hit the ledge_wall4”);
ledge_wall2_bounds = new Object();
ledge_wall2_bounds = ledge_wall2.getBounds(this);
if (Direction == “Left”) {
//if (hero_bounds.xMin<=ledge_wall2_bounds.xMax) {
trace(” hit hanging2 will change - "+hanging2);
hanging2 = true;
hanging1 = false;
trace("hanging2 - "+hanging2);
}
if (Direction == “Right”) {
hanging2 = false;
}
}
if (hero.hitTest(ledge_wall5)) {
jumpup = true;
trace(“hero hit the ledge_wall5”);
ledge_wall1_bounds = new Object();
ledge_wall1_bounds = ledge_wall1.getBounds(this);
if (Direction == “Right”) {
hanging1 = true;
hanging2 = false;
}
if (Direction == “Left”) {
hanging1 = false;
}
}
if (hero.hitTest(ledge_wall6)) {
jumpup = true;
trace(“hero hit the ledge_wall6”);
ledge_wall2_bounds = new Object();
ledge_wall2_bounds = ledge_wall2.getBounds(this);
if (Direction == “Left”) {
hanging2 = true;
hanging1 = false;
trace("hanging2 - "+hanging2);
}
if (Direction == “Right”) {
hanging2 = false;
}
}
for (i=1; i<=ground; i++) {
if (i == 1) {
hero.hits = 0;
}
if (hero.hitTest(eval(“l”+i)) && jumpup) {
hero.hits++;
walk = false;
Ledge = eval(“l”+i);
l_bounds = new Object();
l_bounds = Ledge.getBounds(this);
if (hanging1) {
if (Direction == “Right”) {
//hero._x = l_bounds.xMin-hero._width/2;
hero._y = Ledge._y+hero._height-30;
}
}
if (hanging2) {
if (Direction == “Left”) {
trace(“hero is hanging from the left side”);
//hero._x = l_bounds.xMax;
hero._y = Ledge._y+hero._height-30;
}
}
}
}
//------------------------------------------------------------------------//
//Moving Left & Right//
//-----------------------------------------------------------------------//
if (Key.isDown(Key.LEFT) && !upFlage && !jumpDown) {
walk = true;
hero._xscale = -100;
Direction = “Left”;
//jumping = true;
if (walk) {
if (bg._x == 0) {
curStage = 1;
hero._xscale = -100;
Direction = “Left”;
//trace(“Direction :”+Direction);
hero.gotoAndStop(curStage);
}
if (bg._x>=-1) {
speed = 0;
curStage = 1;
Direction = “Left”;
hero.gotoAndStop(curStage);
if (hero.anim._currentframe>=hero.anim._totalframes) {
curStage = 1;
hero.gotoAndStop(curStage);
}
wall._x += speed;
mb._x += speed;
l._x += speed;
for (i=1; i<=32; i++) {
eval(“f”+i)._x += speed;
eval(“l”+i)._x += speed;
eval(“ledge_wall”+i)._x += speed;
eval(“s_hit”+i)._x += speed;
eval(“ladder”+i)._x += speed;
}
} else {
if (onTheLedge1) {
speed = normal_speed;
}
curStage = 2;
Direction = “Left”;
hero.gotoAndStop(curStage);
prev_time = current_time;
current_time = getTimer();
dt = current_time-prev_time;
speed_countdown_timer = speed_countdown_timer+dt;
if (to_run_timeout>speed_countdown_timer) {
speed = normal_speed;
getDocumentDOM().frameRate = normal_speed;
} else {
speed = fast_speed;
getDocumentDOM().frameRate = fast_speed;
}
wall._x += speed;
mb._x += speed;
l._x += speed;
for (c=1; c<=32; c++) {
eval(“f”+c)._x += speed;
eval(“l”+c)._x += speed;
eval(“ledge_wall”+c)._x += speed;
eval(“s_hit”+c)._x += speed;
eval(“ladder”+c)._x += speed;
}
}
if (bg._x<=-1) {
bg._x += speed;
platforms._x += speed;
}
/if (CurStage == 2 && !Key.isDown(Key.LEFT)) {
trace(“Right key is releassed”);
curStage = 1;
hero.gotoAndStop(curStage);
}
/
}
} else if (Key.isDown(Key.RIGHT) && !upFlage && !jumpDown) {
//trace(upFlage);
Direction = “Right”;
walk = true;
//jumping = true;
hero._xscale = 100;
if (walk) {
if (onTheLedge) {
//speed = 0;
}
if (bg._x+bg._width<=670) {
speed = 0;
curStage = 1;
bg._x += speed;
platforms._x += speed;
Direction = “Right”;
hero.gotoAndStop(curStage);
if (curStage == 2 && hero.anim._currentframe>=hero.anim._totalframes) {
curStage = 1;
hero.gotoAndStop(curStage);
//trace(“curStage :”+curStage);
}
wall._x += speed;
mb._x += speed;
l._x += speed;
for (d=1; d<=32; d++) {
eval(“f”+d)._x += speed;
eval(“l”+d)._x += speed;
eval(“ledge_wall”+d)._x += speed;
eval(“s_hit”+d)._x += speed;
eval(“ladder”+d)._x += speed;
}
} else {
// normal walking on the level //
if (onTheLedge) {
//speed = normal_speed;
}
prev_time = current_time;
current_time = getTimer();
dt = current_time-prev_time;
speed_countdown_timer = speed_countdown_timer+dt;
if (to_run_timeout>speed_countdown_timer) {
speed = normal_speed;
document.frameRate = normal_speed;
} else {
speed = fast_speed;
document.frameRate = fast_speed;
}
Direction = “Right”;
curStage = 2;
hero.gotoAndStop(curStage);
if (curStage == 2 && hero.anim._currentframe>=hero.anim._totalframes) {
curStage = 1;
hero.gotoAndStop(curStage);
}
bg._x -= speed;
platforms._x -= speed;
wall._x -= speed;
mb._x -= speed;
l._x -= speed;
for (e=1; e<=32; e++) {
eval(“f”+e)._x -= speed;
eval(“l”+e)._x -= speed;
eval(“ledge_wall”+e)._x -= speed;
eval(“s_hit”+e)._x -= speed;
eval(“ladder”+e)._x -= speed;
}
if ((bg._x+bg._width) == 660) {
curStage = 1;
hero.gotoAndStop(curStage);
}
}
/if (CurStage == 2 && !Key.isDown(Key.RIGHT)) {
trace(“Right key is releassed”);
curStage = 1;
hero.gotoAndStop(curStage);
}
/
}
} else if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !upFlage && curStage == 2) {
walk = false;
if (!walk) {
curStage = 1;
hero.gotoAndStop(curStage);
}
}
//-----------------------------------------------------------------------------//
//Falling down//
//-----------------------------------------------------------------------------//
if (gravity == “on” && platform == “off” && !jumping) {
hero._y = hero._y+12;
hero._y = origYpos;
jumping = true;
//trace(“Ypos of the hero :”+hero._y);
}
//----------------------------------------------------------------------------//
//Jumping//
//---------------------------------------------------------------------------//
if (hero.hits<=0) {
//trace(hero.hits);
if (Key.isDown(Key.UP) && !jumping && !walk) {
upFlage = true;
//trace(“hero Direction while juming :”+Direction);
if (upFlage) {
curStage = 3;
platform = “no”;
vel_y = 22;
jumping = true;
walk = false;
//trace(Direction);
if (Direction == “Left”) {
if (bg._x>=-1) {
//speed = 0;
bg._x += speed;
for (g=1; g<=32; g++) {
eval(“f”+g)._x += speed;
eval(“l”+g)._x += speed;
eval(“ledge_wall”+g)._x += speed;
eval(“s_hit”+g)._x += speed;
eval(“ladder”+g)._x += speed;
}
wall._x += speed;
l._x += speed;
mb._x += speed;
} else {
bg._x += speed;
platforms._x += speed;
for (g=1; g<=32; g++) {
eval(“f”+g)._x += speed;
eval(“l”+g)._x += speed;
eval(“ledge_wall”+g)._x += speed;
eval(“s_hit”+g)._x += speed;
eval(“ladder”+g)._x += speed;
}
wall._x += speed;
l._x += speed;
mb._x += speed;
}
}
if (Direction == “Right”) {
if (bg._x+bg._width<=670) {
//speed = 0;
bg._x -= speed;
platforms._x -= speed;
for (j=1; j<=32; j++) {
eval(“f”+j)._x -= speed;
eval(“l”+j)._x -= speed;
eval(“ledge_wall”+j)._x -= speed;
eval(“s_hit”+j)._x -= speed;
eval(“ladder”+j)._x -= speed;
}
wall._x -= speed;
l._x -= speed;
mb._x -= speed;
} else {
bg._x -= speed;
platforms._x -= speed;
for (h=1; h<=32; h++) {
eval(“f”+h)._x -= speed;
eval(“l”+h)._x -= speed;
eval(“ledge_wall”+h)._x -= speed;
eval(“s_hit”+h)._x -= speed;
eval(“ladder”+h)._x -= speed;
}
wall._x -= speed;
l._x -= speed;
mb._x -= speed;
}
}
}
}
//---------------------------------------------------------------------//
//Make to fall down//
//---------------------------------------------------------------------//
if (jumping == true) {
if (platform == “on”) {
gravity = “on”;
vel_y = 0;
jumping = false;
//hero._y = origYpos;
curStage = 1;
hero.gotoAndStop(curStage);
} else {
//trace(hero._y);
//trace(“origXpos :”+origXpos);
//hero._y = origXpos;
gravity = “off”;
//hero._y = origYpos;
}
//-------------------------------------------------------------//
//Make to jump up//
//------------------------------------------------------------//
vel_y -= accel;
if (vel_y<-12) {
vel_y = -12;
}
hero._y -= vel_y;
hero.gotoAndStop(curStage);
}
}
//---------------------------------------------------------------------//
if (hero.hits>0) {
if (Key.isDown(Key.UP) && upFlage && !walk) {
//trace(“hero is hanging from the right side”);
if (Direction == “Right”) {
//hero._x = Ledge._x+hero._width-35;
//trace(“Going Right”);
platform = “on”;
curStage = 5;
hero.gotoAndStop(curStage);
//hero._x = Ledge._x+hero._width;
hero._y = Ledge._y+hero._height/2;
L_Ypos = hero._y;
upFlage = false;
onTheLedge1 = true;
//speed = 0;
}
if (Direction == “Left”) {
trace(“Going Left”);
platform = “on”;
curStage = 5;
hero.gotoAndStop(curStage);
//hero.clim._x = Ledge._x;
//hero._x = Ledge._x+Ledge._width;
hero._y = Ledge._y+hero._height/2;
L_Ypos = hero._y;
//upFlage = false;
onTheLedge1 = true;
//speed = 0;
}
}
if (onTheLedge1) {
//trace(“hero’s Stage :”+curStage);
if (hero.clim._currentframe == hero.clim._totalframes) {
//trace(“move the hero left right”);
//hanging2 = false;
//jumping = false;
if (Direction == “Right”) {
upFlage = false;
//hanging1 = false;
//hanging2 = false;
//hero._x = Ledge._x;
hero._y = L_Ypos+hero._height/2-50;
}
if (Direction == “Left”) {
upFlage = false;
//hanging1 = false;
//hanging2 = false;
//hero._x = Ledge._x;
hero._y = L_Ypos+hero._height/2-50;
}
}
}
if (Key.isDown(Key.LEFT) && !upFlage && !jumpDown) {
trace(“hero position walking on the ledge :”+Ledge._x);
//walk = true;
speed = 0;
platform = “on”;
//hero._xscale = -100;
curStage = 2;
hero.gotoAndStop(curStage);
//hero._x = Ledge._x+hero._width/2;
hero._y = L_Ypos-hero._height;
if (onTheLedge1) {
//speed = 0;
}
}
if (Key.isDown(Key.RIGHT) && !upFlage && !jumpDown) {
speed = 0;
platform = “on”;
curStage = 2;
hero.gotoAndStop(curStage);
hero._y = L_Ypos-hero._height;
if (onTheLedge1) {
//speed = 0;
}
}
if (curStage == 1) {
hero._y = L_Ypos-hero._height+10;
trace(“hero has to go up”);
}
}
//---------------------------------------------------------------------//
if (onTheLedge1) {
if (hero.hitTest(ledge_wall8) || hero.hitTest(ledge_wall10) || hero.hitTest(ledge_wall12)) {
if (Direction == “Right”) {
jumpDown = true;
upFlage = true;
hero._xscale = 100;
curStage = 6;
hero._y = hero._y-hero._height/2+55;
hero.gotoAndStop(curStage);
if (hero.g_j_d._currentframe>=hero.g_j_d._totalframes) {
jumpDown = true;
upFlage = true;
}
}
} else if (hero.hitTest(ledge_wall7) || hero.hitTest(ledge_wall9) || hero.hitTest(ledge_wall11)) {
if (Direction == “Left”) {
jumpDown = true;
upFlage = true;
hero._xscale = -100;
curStage = 6;
hero._y = hero._y-hero._height/2+55;
hero.gotoAndStop(curStage);
if (hero.g_j_d._currentframe>=hero.g_j_d._totalframes) {
jumpDown = true;
upFlage = true;
}
}
}
}

//---------------------------------------------------------------------//
if (curStage == 6 && platforms.hitTest(hero)) {
hero.hits = 0;
platform = “on”;
onTheLedge1 = false;
hanging1 = false;
hanging2 = false;
onTheLedge2 = false;
upFlage = false;
jumpDown = false;
jumpup = false;
hero._y = (platforms._y-platforms._height)-hero._height;
p_ypos = hero._y;
p_xpos = hro._x;
if (platform == “on” && Direction == “Right”) {
jumping = false;
if (hero.g_j_d._currentframe == hero.g_j_d._totalframes) {
trace("///hero Xpos///"+hero._x);
hero._xscale = 100;
curStage = 1;
hero.gotoAndStop(curStage);
hero._x = hero._x+Ledge._width-hero._width;
hero._y = hero._y+hero._height/2-10;
}
}
if (platform == “on” && Direction == “Left”) {
jumping = false;
if (hero.g_j_d._currentframe == hero.g_j_d._totalframes) {
trace("///hero Xpos///"+hero._x);
hero._xscale = -100;
curStage = 1;
hero.gotoAndStop(curStage);
hero._x = hero._x-Ledge._width+hero._width;
hero._y = hero._y+hero._height/2-10;
}
}

}
//---------------------------------------------------------------------//
if (Key.isDown(Key.SPACE) && !walk && !jumping) {
for (p=1; p<=19; p++) {
if (hero.hitTest(eval(“f”+p))) {
products = eval(“f”+p);
f_bounds = new Object();
f_bounds = products.getBounds(this);
//trace(“Direction :”+Direction);
if (Direction == “Left”) {
//trace("hero hit the plate from left1 ");
if ((products._x+products._width/2-60)<=(hero._x+hero._width/2-40)) {
//trace(“hero hit the plate from left 2”);
food = eval(“f”+p);
score += 5;
lastCheckpoint[p-1] = food._name;
eval(“f”+p).gotoAndStop(2);
}
}
if (Direction == “Right”) {
//curStage == 1 &&
if ((products._x+products._width/2-60)>=(hero._x+hero._width/2)) {
//trace("hero will eat the plate R ");
food = eval(“f”+p);
score += 5;
lastCheckpoint[p-1] = food._name;
eval(“f”+p).gotoAndStop(2);
}
}
}
}
}
//-------------------------------------------------------------------//
//Enemy move//
//------------------------------------------------------------------//
if (hero.hitTest(wall)) {
if (Direction == “Right” && enemy_timeout>speed_countdown_timer) {
//en_in = true;
//enemy0._xscale = 100;
} else {
//en_in = false;
}
}
if (en_in) {
//waitCount++;
enemy0.ene_run.q_r._visible = true;
enemy0.gotoAndStop(“a”);
enemy0._x -= speed;
if (hero.hitTest(platforms) && en_in || !en_in) {
enemy0.ene_run.q_r._visible = true;
enemy0.ene_stand.q_r._visible = true;
enemy0.ene_run.q_g._visible = false;
enemy0.ene_stand.q_g._visible = false;
} else {
enemy0.ene_run.q_g._visible = true;
enemy0.ene_stand.q_g._visible = true;
enemy0.ene_run.q_r._visible = false;
enemy0.ene_stand.q_r._visible = false;
}
if (enemy0._x<=200) {
enemy0.gotoAndStop(“b”);
en_in = false;
//enemy0.q._visible = true;
//enemy0._x = enemy0._x;
//waitCount++;
}
if (enemy0._x<=950) {
blink.gotoAndStop(2);
//trace(“blinkCount :”+blinkCount);
if (blinkCount == 10) {
blink.gotoAndStop(1);
}
}
}
if (waitCount == 60) {
//en_in = true;
enemy0._xscale = -100;
//enemy0.q._visible = false;
enemy0.gotoAndStop(“a”);
enemy0._x += speed;
//waitCount = 0;
if (enemy0._x>800) {
waitCount = 0;
en_in = false;
enemy0.gotoAndStop(“b”);
enemy0._xscale = 100;
en_in = true;
}
if (hero.hitTest(platforms) && en_in || !en_in) {
//enemy0.q_r._visible = true;
//trace("Hero is on the platform ");
//en_in = true;
//enemy0._xscale = 100;
//enemy0.gotoAndStop(“a”);
//enemy0._x -= 10;
} else {
//enemy0.q_r._visible = false;
}
}
//------------------------------------------------------------------//
ladder = “off”;
platform = “off”;
gravity = “on”;
};
//---------------------------------------------------------------------//
this.onKeyUp = function() {
speed_countdown_timer = 0;
speed = normal_speed;
if (Key.getCode() == 83) {
jumping = false;
}
};
//--------------------------------------------------------------------//


Thank’s for spending some time for me!.

Regards.
Prafull.