0

I am trying to develop a android runner game for school purpose.. I am still new to this and please I need your assistance..

You guys can view my CS5flash file at >>> http://www.filedropper.com/test_37

The obstacles and coins are on random. But the obstacles and coins are overlapping each other.. Which is very bad for a runner game because it looks very bad and the gameplay gets very very complicated.

How can i fix it??. Is there any way to fix it?.

And i am also thinking if I can set the obstacles and coins to a specific area (not on random). So the game will be more oganized and the gameplay won't be complicated. Which i still don't know -_-.

But i still prefer it on random. So guys please help me fix it..

HeOne
  • 3
  • 1
  • 3

1 Answers1

0

You will need to change the way you are adding the coins and obstacles! I suggest using a timer for each. Atm you are adding a ton of them on every frame, calculating overlaps would use too much resources! and put them in an array or better a vector! i would reccomend using an object Pool aswell!

so limit the amout of coins and hurdles that can be present, like 5 or so. then remove them from the array/vector when they are offscreen or collected! then when you add new stuff you can check against the array/vector what the allowed values are!

when you got your Array you can pass it to the randomRange() function and exlcude those values! would look somthing like this! not testet!!

function randomRange (min:Number, max:Number, exclude:Array = null):int
{
    var val:int = (min + Math.random() * (max - min)) >> 0;
    if (exclude)
    {
        for (var i:int = 0; i < exclude; i++)
        {
            while ((val < exclude[i].x + exclude[i].width) && (val > exclude[i].x))
            {
                val = (min + Math.random() * (max - min)) >> 0;
            }
        }
    }
    return val;
}

Its still quite exspensive performance wise. but with only a few object you should be fine

M4tchB0X3r
  • 1,531
  • 1
  • 15
  • 28
  • Wait i'll try to code it. Thanks BTW :) So first i have to make an array.. Right? – HeOne Mar 02 '13 at 07:57
  • Waaaaaaaaa I can't get it right! :(( Please help me M4tchB0X3r . The deadline is very near already. Please help me pleasssssssssse – HeOne Mar 03 '13 at 16:18