A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Help with Strategy game

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

    Help with Strategy game

    I'm trying to make a strategy game where you build up an empire and army and all that and try to win the whole map. So I have the map and the players set up and everything, but what I need to do is have an initial city placed on each of the player's first territories.

    There are 100 territories set up in a grid. I then use this code to pick and place the 5 players on random starting spots.

    Code:
    function starts () {
    	c = 2;
    	while (c<=6) {
    		num = Math.round(random(99))+1;
    		tellTarget (_root.num) {
    			gotoAndStop (_root.c);
    }
    		c = c+1;
    	}
    }
    starts();
    c is the frame number of the territory MC. The MC has 6 total, 1 is blank for nuetral territory, and the other 5 are different colors to represent different players. So c starts at 2 because it's the first player color.

    num picks the random territory to place the player on. So now I want to place the player's capital city on their first territory so that the game can start. And I tried this:
    Code:
    function starts () {
    	c = 2;
    	while (c<=6) {
    		num = Math.round(random(99))+1;
    		tellTarget (_root.num) {
    			gotoAndStop (_root.c);
    			duplicateMovieClip (_root.basecity, _root.city[c][num], c);
    			_root.city[c][num]._x = _root[num]._x + 20;
    			_root.city[c][num]._y = _root[num]._y + 20;
    
    		}
    		c = c+1;
    	}
    }
    starts();
    But this doesn't work. I use +20 on both of them because each territory is 40 pixels wide, and this would place the city in the middle of territory. _root.basecity is the MC of the city that I placed off the side of the stage in order to duplicate it. I guess I could have linked it in library instead, but oh well.

    Any ideas?
    Last edited by Wattz; 04-27-2003 at 02:57 PM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    First, I dunno if you call your functions only from 1 place, but to keep things correct, I would use _root. with c and num variables:

    _root.c = 2;
    while (_root.c<=6) {
    _root.num = Math.round(random(99))+1;
    and so on...


    When you place cities, you duplicate them into depth=c.
    But your territories are also in the depth _root.c I guess.
    So what might happen, is that city mc replaces territory mc and so when you try to place it with
    _root.city[c][num]._y = _root[num]._y + 20;
    then _root[num] mc doesnt exists anymore since its been replaced by _root.city[c][num]. Its just a guess, but try placing cities above everything else, like
    duplicateMovieClip (_root.basecity, _root.city[c][num], c+10000);

    I also dont see much point using names
    _root.city[c][num]
    while you can safely use just
    _root.city[c]


    Hope it helped a little

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    Ehhh...

    It won't duplicate the city MC and place it. That's all I need help with. _root.city[c][num] is used 'cause I need to know which player it belongs to and which territory it's on. In the future players can build more cities, but only one per territory.

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Yes but did you change variables to _root.num and _root.c?
    Code:
    tellTarget (_root.num) {
    	gotoAndStop (_root.c);
    	duplicateMovieClip (_root.basecity, _root.city[c][num], c);
    	_root.city[c][num]._x = _root[num]._x + 20;
    	_root.city[c][num]._y = _root[num]._y + 20;
    }
    after you use tell target(_root.num), you cant just write
    duplicateMovieClip (_root.basecity, _root.city[c][num], c);
    because Flash expects to find those num and c variables now inside _root.num mc. I wont write whole code again for you, only this line:
    duplicateMovieClip (_root.basecity, _root.city[_root.c][_root.num], _root.c);
    but its affecting almost many lines.

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