Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-09-2010, 11:45 AM   #1
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default [AS2] ladders for a game (and an array)

I know this no the best post. im not actualy expecting a response
How ever if some one has had experience with using ladders in a platform game. As this way could be possible. if i could say if touch ladder_one or ladder two hittest == true for both values not just 1

i dont think i can use an array. with the example below.
of the variable(player_on_ladder checks wether the player has touched a ladder.
Now the problem is the player is touching the first ladder, however is not touching the second ladder.
which returns
This fine when i want the player to climb the ladder. however i want to make the player when not touching the ladder
fall towards the ground. So created both variable to check wether the player has touched the ladder and
then is not touching the ladder. When the player touches the ladder the loop checks and returns ladder one has touched(true)
and Ladder_two not touched and the value is false.
as true and false. This is correct


ActionScript Code:
var ladder = new Array(ladder_one,ladder_two); var player_on_ladder:Boolean = false; var ladderTouches:Number = 0;          player.onEnterFrame = function(){ for(var i=0; i < ladder.length; i ++){     // climbs the ladder if player on ladder     if(player.hitTest(ladder[i])){     player_on_ladder = true;         textLadder.text = player_on_ladder;     trace("hit =" + ladder[i]);     ladderTouches = 1;             //  problem  which is correct //output panel .     // value returned true and false table_one is touched and table_two is not touched.     // making the variable     }else if(!player.hitTest(ladder[i])){         player_on_ladder = false;         textLadder.text = player_on_ladder;         trace(player_on_ladder); } // make player go up the ladder  when touching the ladder if(Key.isDown(Key.UP)and player_on_ladder == true){     player._y -=5; } // make player climb down the ladder  when touching the ladder if(Key.isDown(Key.DOWN)and player_on_ladder == true){     player._y +=5;     //player not on ladder //______________________________________________________player fall when after touching and decides to leave halfway point________ }else if(player_on_ladder == false and ladderTouches == 1){     player._y +=3;     // now here lie my problem as the output panel is showing.     // this correct however this why cant work at the moment.         } }     }
hansolo is offline   Reply With Quote
Old 11-09-2010, 01:06 PM   #2
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

sigh.....just exit the loop when you are on a ladder, that is as soon as player_on_ladder becomes true. He cannot be on multiple ladders at the same time, so there is no point in checking further.
__________________
My Site :- http://blog.bluemagica.com

I need a spriter, and a story writer for arcade fighter and a side-view RPG. If you can help, please pm me!
bluemagica is offline   Reply With Quote
Old 11-09-2010, 03:59 PM   #3
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

try http://www.emanueleferonato.com/2008...art-6-ladders/
neilmmm is offline   Reply With Quote
Old 11-09-2010, 08:23 PM   #4
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

cheers for that neil.

i still not done in in a tile engine i keep avoiding it.so i think by next week im gonna have to just go with trying to create a game in tile egine world. oh definitley my next game attempt. ive used movieclip to knock in differnet ways to knock em off.


my method is inaccurate though. cheers
hansolo is offline   Reply With Quote
Old 11-09-2010, 08:25 PM   #5
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

sorry blue magica

ive never exited a loop before. I didnt know ii could.

can you show me an example how to exit the loop.


sigh.....just exit the loop when you are on a ladder, that is as soon as player_on_ladder becomes true. He cannot be on multiple ladders at the same time, so there is no point in checking further.
hansolo is offline   Reply With Quote
Old 11-09-2010, 09:12 PM   #6
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

You can use "break" to exit a loop.
ActionScript Code:
for (loop whatever) {   if (something happens)     break; }

If you weren't familiar with "break", you could still get by with something like this:
ActionScript Code:
dontbreak=true; for (i=0;i<ladderlist.length AND dontbreak;i++) {   if (ladderhit)     dontbreak=false; }

Or, not as efficient as breaking, but it was something I would use a lot when I was younger:
ActionScript Code:
ladderfound = false; for (each ladder in ladderlist) {   if (ladderhit)      ladderfound=true; } if (ladderfound==true) {   ...move on ladder... } else {   ..fall down... }

Last edited by rrh; 11-09-2010 at 09:15 PM.
rrh is offline   Reply With Quote
Old 11-10-2010, 09:34 AM   #7
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

when i run this code trace yes does not appear. And its only stops running the trace (no) when i hit the firstobject in the Array not on the second or third obect..

ActionScript Code:
var  blocks = new Array(box_two, box_one, box_three); player.onEnterFrame = function(){ for (i = 0; i < blocks.length; i++) {  if (player.hitTest(blocks[i])) {    break;     trace(" yes ");     trace(blocks[i]);         }else if(!player.hitTest(blocks[i])){     trace(" no "); }




your code

ActionScript Code:
for (loop whatever) {   if (something happens)// should the be handler here      break; }
hansolo is offline   Reply With Quote
Old 11-10-2010, 12:23 PM   #8
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

Man, do you even think before you code? if you break "before" trace(" yes "); how can you expect your program to execute that?

Code:
var  blocks = new Array(box_two, box_one, box_three);
player.onEnterFrame = function()
{
    for (i = 0; i < blocks.length; i++)
    {
        if (player.hitTest(blocks[i]))
        {
            trace(" yes ");
            trace(blocks[i]);
            break;
        }
        else if (!player.hitTest(blocks[i]))
        {
            trace(" no ");
        }
    }
}
And another thing, why the heck are you doing a !hitTest in the else? if the "if" hitTest is false and it reaches the else, it naturally means there was no collision...
__________________
My Site :- http://blog.bluemagica.com

I need a spriter, and a story writer for arcade fighter and a side-view RPG. If you can help, please pm me!
bluemagica is offline   Reply With Quote
Old 11-11-2010, 10:17 AM   #9
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

ok cheers for that. I do think but i am making mistakes. how ever by you pointing them out i can rectify my mistakes.

so i thank you

I wasnt sure what the break statement does. I thought the trace statement would have ran through.now i know it wont if a break before the trace. thank you


ActionScript Code:
var  blocks = new Array(box_two, box_one, box_three); player.onEnterFrame = function(){     for (i = 0; i < blocks.length; i++){             if (player.hitTest(blocks[i])){                     trace(" yes ");             trace(blocks[i]);        } else{                     trace(" no "); }
hansolo is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:34 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.