PDA

View Full Version : How to loop these.


keskk
03-28-2013, 07:05 AM
I want to make a game where my character keep running forward along a path. along the way, obstacles are going to appear randomly. My character has to move, left, right or jump dependingly. (I know many similar concepts available in the market)

My question is, how do I loop the environment objects to appear randomly? Any guidance is appreciated cos no luck so far in figuring out what my loop argument should be. Without this loop, it would mean creating 10s maybe 100s of objects to place along the path which is not efficient. Have created the running, controls and procedures less the loop.

Thanks for advice.

djslater107
03-29-2013, 07:48 AM
Add a set of objects that you would like to appear randomly... Then create an array, not a list, loading all of the objects into the array... Then generate a random number that is within the range 0 <= index < number of objects in the array (in other words, if you have 10 objects in the array, the random number should be in the range {0 .. 9}). That random number then becomes the index value of the array, and you can then place the object at ary[index] into the scene appropriately.)

Hope this helps.

keskk
04-04-2013, 05:27 AM
Thanks for reply.

I tried out what you mentioned. I'm still unclear on how I am going to make the obstacles appear randomly. Even though it is in an array, does it still mean I need to create the total number of obstacles (lets say 50) and individually place them in their appropriate places? Or anyway I can loop it such that I create only 5 obstacles but keep repeating them along the path of the main character randomly?

One more question. For collision detection, I am able to only detect on the first obstacle. It doesn't work for other obstacles. I attached my file for reference. Appreciate any advice. Thank you.

P.S Just working out the codes first before adding any nice scenario and movements so nothing fancy in the codes yet.

djslater107
04-04-2013, 08:08 AM
Or anyway I can loop it such that I create only 5 obstacles but keep repeating them along the path of the main character randomly?

One more question. For collision detection, I am able to only detect on the first obstacle. It doesn't work for other obstacles. I attached my file for reference. Appreciate any advice. Thank you.

5 obstacles, placing them in the path of the character by moving them from former location to new location, i.e.

(do all of these things with duration of time 0)
* pick object from array
* make it invisible
* move it to a location in the path of the main character
* make it visible

You are testing for collision on the first object in every case... You have to rest what you are testing for (and each object may have different center points that you are measuring from)

keskk
04-04-2013, 09:47 AM
Hi,

Thanks. I got the idea for looping the obstacles. :)

Regarding Collision detection, slight confusion.

I am using the parameter type value as 'model' to measure, which from my understanding is universal to detect all Alice models. Moreover all the objects are the same in my case thus no difference in center points.

As you pointed out, it is only detecting the first object and nothing else. When I loop it and this first object re-appears at another spot, it is not detected too.

Sorry if you have already answered this but I'm not getting the picture. Attached the file for reference. Thank you.