A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Creating a random land mass.

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    146

    Creating a random land mass.

    So I have this idea for a game involving islands. I was thinking of a way to create random islands on the stage by using a MC of a dot and placing it randomly (and randomly sizing them) on the stage. In the original MC there would be collision detection code for all other MCs that require it.

    My question is, does my plan sound like it will work?

    I think I could randomly size them by making a trap using the duplication counter. like if this.count <> _root.islandMC.count then size = random(60);

    My plan for the HitTests is to use "this._x, this._y" so that each of the island MCs can be hit by other MCs.

    Also, I was kind of wondering about ways to make the island MCs take certain formations like you would see in real life. My idea involves drawing out a line... like a parabola or maybe even a circle. then duplicate the movieclips and pick out sequential numbers based on the number of the island clip (given to it during duplication). That way the islands would be like Hawaii, where they're all together and follow a line of mountains or valcanos.

    But at this point I'm just rambling. Does this sound feasable and does anyone have any suggestions or maybe even ideas to add?

  2. #2
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    ok i've reached my first snag. i'm trying to randomly place the MCs around the stage. The stage is 550x550.

    Code:
    islands = _root.numisle;
    for ( i =0; i < islands; i++ ) {
    duplicateMovieClip ( _root.land, "_root.land"+i, i );
    }
    stop();
    that's in the first frame of the scene. _root.numisle is a variable used elsewhere to set up the game for play.

    this is the code in my MC:

    Code:
    onClipEvent (load) {
    	this._x = random(550);
    	this._y = random(550);
    }
    The problem I'm seeing is that all the duplicate MCs spawn in the same x/y as the source MC, but the source MC gets randomly placed on the stage!

    I've used similar techniques in another game but this time it doesn't seem to be working. Can anyone tell me why?

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    Code:
    islands = _root.numisle;
    for ( i =0; i < islands; i++ ) {
    duplicateMovieClip ( _root.land, "land"+i, i );
    	_root.land[i]._x = random(550);
    	_root.land[i]._y = random(550);
    }
    stop();
    i tried this but it doesn't seem to work either...

    am I missing something?!

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    code:

    islands = _root.numisle;
    for ( i = 1; i < islands; i++ ) {
    duplicateMovieClip ( _root.land, "land"+i, i );
    _root["land"+i]._x = random(550);
    _root["land"+i]._y = random(550);
    }
    stop();



    Dont start from i=0, and use _root["land"+i] to access new mc's.

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