
-----------------------------------
DJ
Sun Jun 29, 2003 9:33 pm

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

-----------------------------------
Dan
Sun Jun 29, 2003 11:27 pm


-----------------------------------
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.


randomize %makes shure there are difrent random numbers

loop
    var x : int := Rand.Int (0, maxx)
    var y : int := Rand.Int (0, maxy)

    Draw.Dot(x,y,1)
    
    delay(20)
end loop


-----------------------------------
Tony
Sun Jun 29, 2003 11:58 pm


-----------------------------------
the way I see DJ's problem, you dont assign properties to random integers, you randomly assign location to objects  :wink: 

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.

-----------------------------------
Andy
Mon Jun 30, 2003 8:22 am


-----------------------------------
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

-----------------------------------
DJ
Sat Jul 12, 2003 3:16 pm


-----------------------------------
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?

-----------------------------------
Tony
Sat Jul 12, 2003 3:21 pm


-----------------------------------
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

for i:1..50
if object(i)->collide(currentX,currentY) then
put "game over"
return
end if
end for


-----------------------------------
AsianSensation
Sat Jul 12, 2003 3:21 pm


-----------------------------------
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:

type Location :
    record
        x, y : int

        /*or, depends on what kind of math
         you are doing on those positions*/
        x, y : real
    end record

var Pos : array 1..50 of Location

for rep: 1..50
     Location.x := Rand.Int(1, 100)
end for


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

-----------------------------------
Tony
Sat Jul 12, 2003 3:30 pm


-----------------------------------
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

-----------------------------------
DJ
Sat Jul 12, 2003 3:39 pm


-----------------------------------
can someone give me a working example of an array?
i fiddled around with th turing help and it doesnt help.

-----------------------------------
AsianSensation
Sat Jul 12, 2003 3:41 pm


-----------------------------------
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

-----------------------------------
DJ
Sat Jul 12, 2003 5:08 pm


-----------------------------------
good tutorial, but i'll be back

-----------------------------------
DJ
Tue Jul 15, 2003 11:21 pm


-----------------------------------
As promised:

How can i turn this errored peice of crap
var m : array 400 .. 5400 by 200 of int
into good stuff?
arrays dont work like for loops, now do they

i read the array tut but no help.

-----------------------------------
Tony
Tue Jul 15, 2003 11:25 pm


-----------------------------------
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


for i:400 .. 5400 by 200
var m:array i..i of int
end for


but thats still stupid and I donno if its gonna work or not.

Just declear a range you need... like 1..26
