
-----------------------------------
Mr. T
Thu Aug 10, 2006 7:26 pm

2d array coordinates
-----------------------------------
I am using a 15 by 30 grid (2d array) and I was wondering how i could determine the pixel coordinates of each individual block in the grid?

-----------------------------------
[Gandalf]
Thu Aug 10, 2006 7:40 pm


-----------------------------------
Simply multiply the index of each square by the size of the grid, for example:
const GRID_SIZE := 25
var grid : array 1 .. 10, 1 .. 10 of
    record
        x, y : int
    end record
for x : 1 .. upper (grid, 1)
    for y : 1 .. upper (grid, 2)
        grid (x, y).x := x * GRID_SIZE
        grid (x, y).y := y * GRID_SIZE
        Draw.Box (grid (x, y).x, grid (x, y).y, grid (x, y).x + GRID_SIZE, grid (x, y).y + GRID_SIZE, black)
    end for
end for

If that's not the answer you were looking for, I suggest you be a little more specific in your question.

-----------------------------------
Mr. T
Thu Aug 10, 2006 7:45 pm

Alex's opinion
-----------------------------------
Well, in my game I need to know if a ball has collided with a filled block in the grid.  I need the specific block to be in pixel coordinates in order to determine if the ball coordinates = the block coordinates.  In which case, a collision has occurred.

-----------------------------------
[Gandalf]
Thu Aug 10, 2006 8:07 pm


-----------------------------------
Ok, then use the method I posted above combined with classical rectangular collision detection.  Right?

-----------------------------------
Mr. T
Thu Aug 10, 2006 8:10 pm

Alex's Opinion
-----------------------------------
I dont see the neccesity for a record.  Ive never used one before when dealign with a 2d array.

-----------------------------------
[Gandalf]
Thu Aug 10, 2006 8:24 pm


-----------------------------------
Umm... why not?  There's no reason to not use one now.

Fine, if you really don't want to use a record, you can create a Grid class and start using OOP in your program.  Or use parallel arrays, but that's really just a worse method of using a record.

-----------------------------------
Mr. T
Thu Aug 10, 2006 8:26 pm

Alex's Opinion
-----------------------------------
I'm not looking for an alternate to records; rather I'm asking why use them at all in this case?

-----------------------------------
[Gandalf]
Thu Aug 10, 2006 9:12 pm


-----------------------------------
I, on the other hand, am asking:  Why?  Why not use them?  If not now, then why ever use records?  What's the point of records at all?

We're using a record because it shows that a grid has both x and y co-ordinates.  If you use parallel arrays (don't use records) you have two completely unrelated variables being used together, which is hardly expressive.  A class would work well too.

-----------------------------------
Windsurfer
Fri Aug 11, 2006 6:06 pm


-----------------------------------
Why not post your source code and let people help you find the best method?
