# Help in advanture type game

**URL:** <https://forum.kirupa.com/t/help-in-advanture-type-game/246679>\
**Category:** Uncategorized\
**Created:** [December 13, 2007, 11:21am UTC](https://forum.kirupa.com/t/help-in-advanture-type-game/246679 "2007-12-13T11:21:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AS\_is\_Life](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@AS\_is\_Life](https://forum.kirupa.com/u/AS_is_Life)\
**Post date:** [December 13, 2007, 11:21am UTC](https://forum.kirupa.com/t/help-in-advanture-type-game/246679/1 "2007-12-13T11:21:37Z")

</div>

Hi,  
Guyes!  
I am coming directly to the point,i am working on one adventure type of game,in that the hero will move Left to Right,jump in the air,while jumping if he is near the ledge he will grabe the ledge and hang and while hanging if user click the up key he will climb on the ledge,on the ledge he can walk as soon as he reaches the end of the ledge he will jump down on the ground this is the move of the hero but iam haveing proble on the ledge, hero is not walking properly,some times hanging is haveing problem. so you guyes help me or do you have have any relevant link, please let me know. i am haveing problem with uploading the .swf please see the code and guide me!

Thank’s

**Code** :

stop();  
Stage.showMenu = false;  
//Variables & Ojectes//  
fscommand(“fullscreen”, true);  
fscommand(“allowscale”, false);  
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;  
hp = 100;  
Points = 0;  
lastCheckpoint = [];  
hanging1 = false;  
hanging2 = false;  
changeStage = false;  
walk = false;  
upFlage = false;  
jumpFlage = false;  
//----------------------------------------------------------------------------//  
this.onLoad = function() {  
Direction = “Right”;  
};  
this.onEnterFrame = function() {  
origYpos = hero.\_y;  
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;  
hero.\_y = oriYpos;  
}  
//check if enemy is hit//  
if (hero.hitTest(enemy0)) {  
Points = score;  
}  
// If Hero hits the Ledge//  
if (hero.hitTest(ledge\_wall1)) {  
if (Direction == “Right”) {  
hanging1 = true;  
}  
if (Direction == “Left”) {  
hanging1 = false;  
}  
}  
if (hero.hitTest(ledge\_wall2)) {  
if (Direction == “Left”) {  
hanging2 = true;  
}  
if (Direction == “Right”) {  
hanging2 = false;  
}  
}  
for (i=1; i\<=ground; i++) {  
if (i == 1) {  
hero.hits = 0;  
}  
if (hanging1) {  
if (hero.hitTest(eval(“l”+i))) {  
hero.hits++;  
walk = false;  
Ledge = eval(“l”+i);  
l\_bounds = new Object();  
l\_bounds = Ledge.getBounds(this);  
if (Direction == “Right”) {  
if (t\_edge\<=l\_bounds.xMin) {  
if (curStage == 3) {  
hero.\_x = l\_bounds.xMin-hero.\_width/2+10;  
hero.\_y = l\_bounds.yMin+hero.\_height/2-12;  
}  
} else {  
}  
}  
}  
}  
if (hanging2) {  
if (hero.hitTest(eval(“l”+i))) {  
hero.hits++;  
walk = false;  
Ledge = eval(“l”+i);  
l\_bounds = new Object();  
l\_bounds = Ledge.getBounds(this);  
if (Direction == “Left”) {  
if (t\_edge\>=l\_bounds.xMax) {  
if (curStage == 3) {  
hero.\_x = l\_bounds.xMax-hero.\_width/2+60;  
hero.\_y = l\_bounds.yMin+hero.\_height/2-20;  
} else {  
}  
}  
}  
}  
}  
}  
//Moving Left & Right//  
if (Key.isDown(Key.LEFT) && !upFlage) {  
walk = true;  
hero.\_xscale = -100;  
if (walk) {  
if (bg.\_x == 0) {  
curStage = 1;  
hero.\_xscale = -100;  
Direction = “Left”;  
hero.gotoAndStop(curStage);  
}  
if (bg.\_x\>=-1) {  
speed = 0;  
curStage = 1;  
Direction = “Left”;  
hero.gotoAndStop(curStage);  
f1.\_x += speed;  
f2.\_x += speed;  
f3.\_x += speed;  
f4.\_x += speed;  
f5.\_x += speed;  
f6.\_x += speed;  
f7.\_x += speed;  
f8.\_x += speed;  
wall.\_x += speed;  
l1.\_x += speed;  
l2.\_x += speed;  
l3.\_x += speed;  
l.\_x += speed;  
mb.\_x += speed;  
ledge\_wall1.\_x += speed;  
ledge\_wall2.\_x += speed;  
ledge\_wall3.\_x += speed;  
ledge\_wall4.\_x += speed;  
ledge\_wall5.\_x += speed;  
} else {  
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;  
}  
f1.\_x += speed;  
f2.\_x += speed;  
f3.\_x += speed;  
f4.\_x += speed;  
f5.\_x += speed;  
f6.\_x += speed;  
f7.\_x += speed;  
f8.\_x += speed;  
wall.\_x += speed;  
l1.\_x += speed;  
l2.\_x += speed;  
l3.\_x += speed;  
l.\_x += speed;  
mb.\_x += speed;  
ledge\_wall1.\_x += speed;  
ledge\_wall2.\_x += speed;  
ledge\_wall3.\_x += speed;  
ledge\_wall4.\_x += speed;  
ledge\_wall5.\_x += speed;  
}  
if (bg.\_x\<=-1) {  
bg.\_x += speed;  
platforms.\_x += speed;  
}  
}  
} else if (Key.isDown(Key.RIGHT) && !upFlage) {  
walk = true;  
hero.\_xscale = 100;  
if (walk) {  
if (bg.\_x+bg.\_width\<=670) {  
speed = 0;  
curStage = 1;  
bg.\_x += speed;  
platforms.\_x += speed;  
Direction = “Right”;  
hero.gotoAndStop(curStage);  
f1.\_x += speed;  
f2.\_x += speed;  
f3.\_x += speed;  
f4.\_x += speed;  
f5.\_x += speed;  
f6.\_x += speed;  
f7.\_x += speed;  
f8.\_x += speed;  
wall.\_x += speed;  
l1.\_x += speed;  
l2.\_x += speed;  
l3.\_x += speed;  
l.\_x += speed;  
mb.\_x += speed;  
ledge\_wall1.\_x += speed;  
ledge\_wall2.\_x += speed;  
ledge\_wall3.\_x += speed;  
ledge\_wall4.\_x += speed;  
ledge\_wall5.\_x += speed;  
} else {  
// normal walking on the level //  
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);  
bg.\_x -= speed;  
platforms.\_x -= speed;  
f1.\_x -= speed;  
f2.\_x -= speed;  
f3.\_x -= speed;  
f4.\_x -= speed;  
f5.\_x -= speed;  
f6.\_x -= speed;  
f7.\_x -= speed;  
f8.\_x -= speed;  
wall.\_x -= speed;  
l1.\_x -= speed;  
l2.\_x -= speed;  
l3.\_x -= speed;  
l.\_x -= speed;  
mb.\_x -= speed;  
ledge\_wall1.\_x -= speed;  
ledge\_wall2.\_x -= speed;  
ledge\_wall3.\_x -= speed;  
ledge\_wall4.\_x -= speed;  
ledge\_wall5.\_x -= speed;  
if ((bg.\_x+bg.\_width) == 660) {  
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;  
}  
//Jumping//  
if (hero.hits\<=0) {  
//trace(hero.hits);  
if (Key.isDown(Key.UP) && !jumping) {  
upFlage = true;  
if (upFlage) {  
curStage = 3;  
platform = “no”;  
vel\_y = 22;  
jumping = true;  
walk = false;  
if (Direction == “Left”) {  
if (bg.\_x\<=0) {  
speed = 0;  
bg.\_x += speed;  
platforms.\_x += speed;  
f1.\_x += speed;  
f2.\_x += speed;  
f3.\_x += speed;  
f4.\_x += speed;  
f5.\_x += speed;  
f6.\_x += speed;  
f7.\_x += speed;  
f8.\_x += speed;  
wall.\_x += speed;  
l1.\_x += speed;  
l2.\_x += speed;  
l3.\_x += speed;  
l.\_x += speed;  
mb.\_x += speed;  
ledge\_wall1.\_x += speed;  
ledge\_wall2.\_x += speed;  
ledge\_wall3.\_x += speed;  
ledge\_wall4.\_x += speed;  
ledge\_wall5.\_x += speed;  
} else {  
bg.\_x += speed;  
platforms.\_x += speed;  
f1.\_x += speed;  
f2.\_x += speed;  
f3.\_x += speed;  
f4.\_x += speed;  
f5.\_x += speed;  
f6.\_x += speed;  
f7.\_x += speed;  
f8.\_x += speed;  
wall.\_x += speed;  
l1.\_x += speed;  
l2.\_x += speed;  
l3.\_x += speed;  
l.\_x += speed;  
mb.\_x += speed;  
ledge\_wall1.\_x += speed;  
ledge\_wall2.\_x += speed;  
ledge\_wall3.\_x += speed;  
ledge\_wall4.\_x += speed;  
ledge\_wall5.\_x += speed;  
}  
}  
if (Direction == “Right”) {  
bg.\_x -= 2;  
platforms.\_x -= 2;  
f1.\_x -= 2;  
f2.\_x -= 2;  
f3.\_x -= 2;  
f4.\_x -= 2;  
f5.\_x -= 2;  
f6.\_x -= 2;  
f7.\_x -= 2;  
f8.\_x -= 2;  
wall.\_x -= 2;  
l1.\_x -= 2;  
l2.\_x -= 2;  
l3.\_x -= 2;  
l.\_x -= 2;  
mb.\_x -= 2;  
ledge\_wall1.\_x -= 2;  
ledge\_wall2.\_x -= 2;  
ledge\_wall3.\_x -= 2;  
ledge\_wall4.\_x -= 2;  
ledge\_wall5.\_x -= 2;  
}  
}  
}  
//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 {  
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) {  
upFlage = false;  
if (Direction == “Right”) {  
platform = “on”;  
curStage = 5;  
hero.gotoAndStop(curStage);  
hero.\_x = Ledge.\_x+hero.\_width/2-35;  
hero.\_y = Ledge.\_y+hero.\_height/2;  
L\_Ypos = hero.\_y;  
}  
if (Direction == “Left”) {  
platform = “on”;  
curStage = 5;  
hero.gotoAndStop(curStage);  
hero.\_x = Ledge.\_x+hero.\_width;  
hero.\_y = Ledge.\_y+hero.\_height/2;  
L\_Ypos = hero.\_y;  
}  
}  
if (Key.isDown(Key.LEFT) && !upFlage) {  
platform = “on”;  
curStage = 2;  
hero.gotoAndStop(curStage);  
hero.\_x = Ledge.\_x+hero.\_width/2;  
hero.\_y = L\_Ypos-hero.\_height;  
}  
if (Key.isDown(Key.RIGHT) && !upFlage) {  
speed = 0;  
platform = “on”;  
curStage = 2;  
hero.gotoAndStop(curStage);  
hero.\_y = L\_Ypos-hero.\_height;  
}  
}  
//---------------------------------------------------------------------//  
if (hero.\_x\>Ledge.\_x-hero.\_width/2 && hero.hits\>0) {  
if (curStage == 2 || curStage == 1) {  
if (Direction == “Left” && hero.\_x+hero.\_width/2\>=l\_bounds.xMin) {  
jumping = false;  
hero.\_xscale = -100;  
curStage = 6;  
hero.gotoAndStop(curStage);  
} else if (Direction == “Right” && hero.\_x+hero.\_width/2\>=l\_bounds.xMax) {  
trace(l\_bounds.xMax);  
jumping = false;  
hero.\_xscale = 100;  
curStage = 6;  
hero.gotoAndStop(curStage);  
}  
}  
}  
//---------------------------------------------------------------------//  
if (curStage == 6 && platforms.hitTest(hero)) {  
hero.hits = 0;  
platform = “on”;  
jumping = false;  
hanging1 = false;  
hanging2 = false;  
hero.\_y = (platforms.\_y-platforms.\_height)-hero.\_height-10;  
if (platform == “on” && Direction == “Right”) {  
if (!jumping) {  
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”) {  
if (!jumping) {  
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) {  
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);  
if (Direction == “Left”) {  
if ((products.\_x+products.\_width/2)\<=hero.\_x+hero.\_width/2) {  
food = eval(“f”+p);  
score += 5;  
lastCheckpoint[p-1] = food.\_name;  
eval(“f”+p).gotoAndStop(2);  
}  
} else if (Direction == “Right”) {  
if ((products.\_x+products.\_width/2)-30\>=hero.\_x+hero.\_width/2) {  
food = eval("f+p);  
score += 5;  
lastCheckpoint[p-1] = food.\_name;  
eval(“f”+p).gotoAndStop(2);  
} else {  
}  
}  
}  
}  
}  
//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) {  
enemy0.gotoAndStop(“a”);  
enemy0.\_x -= 10;  
if (enemy0.\_x\<=200) {  
enemy0.gotoAndStop(“b”);  
en\_in = false;  
}  
}  
if (waitCount == 60) {  
enemy0.\_xscale = -100;  
enemy0.gotoAndStop(“a”);  
enemy0.\_x += 10;  
if (enemy0.\_x\>800) {  
waitCount = 0;  
en\_in = false;  
enemy0.gotoAndStop(“b”);  
enemy0.\_xscale = 100;  
en\_in = true;  
}  
if (hero.hitTest(platforms) && waitCount == 60) {  
waitCount = 0;  
trace(“waitCount till :”+waitCount);  
en\_in = true;  
enemy0.\_xscale = 100;  
enemy0.gotoAndStop(“a”);  
enemy0.\_x -= 10;  
}  
}  
//------------------------------------------------------------------//  
ladder = “off”;  
platform = “off”;  
gravity = “on”;  
};  
this.onKeyUp = function() {  
trace(“All key’s R Up.”);  
speed\_countdown\_timer = 0;  
speed = normal\_speed;  
if (Key.getCode() == 83) {  
jumping = false;  
}  
};
