Computer Science Canada Random integers and their properties |
Author: | DJ [ Sun Jun 29, 2003 9:33 pm ] |
Post subject: | Random integers and their properties |
Yes, i now need help creating random integers that i can then assign properties to. i want to make obstacles in random spots in my game that have properties, like u die if u run into them. the thing is, these guys move with the rest of the game and each time the screen moves, their position re-randomizes i can't understand the help manual's thing on rand.set and rand.next and the suchlike, and the example it gives doesnt work DJ |
Author: | Dan [ Sun Jun 29, 2003 11:27 pm ] | ||
Post subject: | |||
well to randomize and things location in a 2d spcae you need to randomly genreat intagres that are betwen 0 and maxy as well as one that is betwen 0 and maxx. then make the guys loaction equal to thess. Ex.
|
Author: | Tony [ Sun Jun 29, 2003 11:58 pm ] |
Post subject: | |
the way I see DJ's problem, you dont assign properties to random integers, you randomly assign location to objects ![]() since the map moves, you first create obsticles thoughout the map at random locations using Rand.Int then as the map moves, you also change the location of each of the obsticles with the map to keep them aligned. |
Author: | Andy [ Mon Jun 30, 2003 8:22 am ] |
Post subject: | |
what i would do is have a type containing each of the properties u need using variables then just have an array of the type and just randomly pick a slot in the array |
Author: | DJ [ Sat Jul 12, 2003 3:16 pm ] |
Post subject: | |
i like tony's bit about random positions to objects, but i need about 50 of these objects, and each needs properties like dying if you run into them. is there an easier way to make this than copying, pasting and changing variable numbers? |
Author: | Tony [ Sat Jul 12, 2003 3:21 pm ] | ||
Post subject: | |||
yeah... write a class for the object and then declear an array 1..50 and point to the class... You'll have an array of independant objects. At that point you to assign a random position to each of them. As for running into them, include a collision detection function into the class and have something like
|
Author: | AsianSensation [ Sat Jul 12, 2003 3:21 pm ] | ||
Post subject: | |||
yep, array and type have a type for location, and declare an array of that type make sure you have some way of assigning random values to it though, like in a loop. example:
Edit: Oops, posted the same time as tony, oh well, classes are better if you desire speed and organization, but types are, IMO, easier to understand than classes |
Author: | Tony [ Sat Jul 12, 2003 3:30 pm ] |
Post subject: | |
types are probably easier if all you need to do is just store the location. Then you global collision function will take (array(i).x,array(i).y,currentX,currentY) as its arguments |
Author: | DJ [ Sat Jul 12, 2003 3:39 pm ] |
Post subject: | |
can someone give me a working example of an array? i fiddled around with th turing help and it doesnt help. |
Author: | AsianSensation [ Sat Jul 12, 2003 3:41 pm ] |
Post subject: | |
an array? there are two currently excellent tutorials in the tutorial section, one by tony, and another by dodge_tomahawk... so check those out, ask questions if you don't understand though |
Author: | DJ [ Sat Jul 12, 2003 5:08 pm ] |
Post subject: | |
good tutorial, but i'll be back |
Author: | DJ [ Tue Jul 15, 2003 11:21 pm ] | ||
Post subject: | |||
As promised: How can i turn this errored peice of crap
into good stuff? arrays dont work like for loops, now do they i read the array tut but no help. |
Author: | Tony [ Tue Jul 15, 2003 11:25 pm ] | ||
Post subject: | |||
wtf? you cant have by whatever when declearing an array. Its not a range, its a series of numbers... If you really wanna do it, use
but thats still stupid and I donno if its gonna work or not. Just declear a range you need... like 1..26 |