A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [Problem] Platform game not working as intended!

Threaded View

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    21

    [Problem] Platform game not working as intended!

    Hey!

    I'm making a platform game where I plan to make it so that you can move both backwards and forwards in the levels, but if you've killed/picked something up on a level and then go back to that level, it won't be there anymore. I've written some code for it which I thought would work, but it.. doesnt:P. The buggy code is on line ~168-200 in the file(I've tried a couple of variations, one is commented out). It only applies to coin objects so far(or should, anyway ^^), because since it's buggy I didn't bother writing it for the other stuff yet. What I tried is to do is add every objects x&y-value that gets hit by my hero to an array. Then when I start up a level I check if it's been visited before, and if it has I check if any objects has the same x&y-value as those the hero hit last time. If some of them have been hit, the code is supposed to remove them.. but that won't work:P I wondered if anyone would be kind enough to check this out for me and tell me why the code isn't working?

    I uploaded the game here, it's 1 MB size.

    Thanks in advance and kind regards,
    Zak


    PS. I added the code here, though I don't know if it makes much sense out of context.. ^^ this is part of the code that runs every time a level is started(and which doesn't work.. :P);
    PHP Code:
    public function examineLevel() {
        
    treasures = new Array();
        for(var 
    i:int=0;i<this.gamelevel.numChildren;i++) {
            var 
    mc this.gamelevel.getChildAt(i);
            if (
    mc is Coin) {
                if ((
    forestLevel1Visited == true) && (currentLabel == "forestLevel1")) {
                    var 
    p:int=0;
                    while(
    true) {
                        if (
    forestLvl1ObjectsDeletedX.length) {
                            break;
                        }else if ((
    mc.== forestLvl1ObjectsDeletedX[p]) && (mc.== forestLvl1ObjectsDeletedY[p])) {
                            
    gamelevel.removeChild(mc);
                            
    forestLvl1ObjectsDeletedX.splice(p,1);
                            
    forestLvl1ObjectsDeletedY.splice(p,1);
                            break;
                        }else {
                            
    treasures.push(mc);
                        
    gamelevel.mc.gotoAndPlay(Math.floor(Math.random()*21-1));
                        }
                        
    p++;
                    }
                }
                
    /*for (var z:int=0;z<=forestLvl1ObjectsDeleted.length;z++) {
                if (mc.x == forestLvl1ObjectsDeleted[z]) {
                    gamelevel.removeChild(mc);
                    forestLvl1ObjectsDeleted.splice(z,1);
                } 
                break;
                else {
                    treasures.push(mc);
                    mc.gotoAndPlay(Math.floor(Math.random()*21-1));
                }
                break;
            }
        }*/
                
    else {
                    
    treasures.push(mc);
                    
    mc.gotoAndPlay(Math.floor(Math.random()*21-1));
                }
            }
        }

    Thanks in advance and kind regards,
    Zak

    reformatted the code - Tony
    Last edited by tonypa; 03-24-2008 at 04:15 AM.

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