1
\$\begingroup\$

I'm currently working on a 'Tiny wings' like game. I've already asked about the angle of the items in curved lines and i solved (thank you for responses),i'm currently placing the items in random positions, but the terrain it's dynamically and i don't get this working.

I've a vector with the points of the terrain, and i'm doing something similar to this (Iterating trough vector):

if( _SPManager && i % 15 == 0 && i != 0 )
{
    if (  _settings.specialPoints && _currentPoints < _settings.specialPoints )
    {
        _SPManager.addPoint( _hillsPosition[i].x , _hillsPosition[i].y );
        _currentPoints++;
    }
}

But it isn't working as i expected. It isn't displaying the right number of items (Always shows less than i specified).

How do i should place the items?

Thanks :)

\$\endgroup\$
2
  • \$\begingroup\$ Could you comment the code you share perhaps? I am not sure it is making much sense currently.. Why not, just do this: see answer \$\endgroup\$
    – AturSams
    Sep 27, 2012 at 19:12
  • \$\begingroup\$ Just to be clear, making much sense as in readable to people who are unfamiliar with it, not as in good or bad - just as far as comprehension goes. \$\endgroup\$
    – AturSams
    Sep 27, 2012 at 19:22

1 Answer 1

0
\$\begingroup\$

It is not clear from the code, what you are achieving by iterating. Could you do this instead:

//I am guessing:
//_settings.specialPoints == //wanted amount of items

var j : int = 0;
for(var i : int = 0; i < _settings.specialPoints; i++) //I'm assuming the above
{
    j = Math.floor(Math.random() * _hillsPosition.length);
    _SPManager.addPoint( _hillsPosition[j].x , _hillsPosition[j].y );
}

Will that work, again please clarify your goal and how the current code describes the steps to get it done. (add commenting) Thanks

Do you only want indexes that divide by 15 with no remainder for some reason?

//replace the earlier randomizer with this:
j = Math.floor(Math.random() * _hillsPosition.length); //same as before
j -= j%15;
\$\endgroup\$
4
  • \$\begingroup\$ Sorry, it seems that it was clear to my but not for everyone else. The vector grows when the main character reaches a distance, the world generates a new hill and the new points are added to the vector and so on. In the code described above, i was iterating through that vector to place the items in a certain point of the hill. The 'i % 15 == 0' was to 'skip' an amount points in vector. My problem is that the terrain it is created 'on fly'. Is it better now? Maybe i'm not explaining correctly, sorry for that. \$\endgroup\$ Sep 27, 2012 at 21:02
  • \$\begingroup\$ Yeah, it makes sense, so is the player on 'i'? What is happening when you are adding new items? \$\endgroup\$
    – AturSams
    Sep 27, 2012 at 21:56
  • \$\begingroup\$ Thank you very much for helping me think in a different way, was just what I needed. Now I'm emptying the vector every time a new part of the land is drawed, then the points are updated and placed in the right place, it was simply a matter of thinking it. Thanks again. \$\endgroup\$ Sep 28, 2012 at 1:01
  • \$\begingroup\$ You are very welcome. :) \$\endgroup\$
    – AturSams
    Sep 28, 2012 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .