Open RowanHarley opened 8 years ago
You probably don't need IDs, since the x and y coordinates of a sector should identify it. Creating them all at once would probably make most sense, or would that take too long?
Would I need the x and y of 2 point's or just 1? I'm thinking 2 because that would be the only way to identify whether the player is inside the sector
All sectors have the same width and height, so one coordinate would be enough.
How should I go about creating the sector's? Should I add sector_count_along_edge
and sector_size
to the equation?
for (y = 0; y < sector_count_along_edge; y++) {
for (x = 0; x < sector_count_along_edge; x++) {
createSector(x, y);
}
}
In createSector
you create a sector that goes from x * sector_size
(inclusive) to (x+1) * sector_size
(exclusive), the same for y. Keep in mind that coordinates of food/prey/snakes might not be integer.
Ok, thank's! I'll try implement something like that
Ok, so I've used your code to make the sector's and store them in an array but I'm not sure how to check which sector the snake is inside. Sorry for taking so long to reply. I had problems with my internet for a while
You're using a two-dimensional array I guess?
No, I'm using a one-dimensional array of Sector()
's. Each one holds the start x, start y, end x and end y.
Use a two dimensional array. That way you can just get the sector with sectors[(int)(snake.y / sector_size)][(int)(snake.x / sector_size)]
or similar and don't have to go through all of them to find the correct one (which would probably take too long).
I'm not sure I understand. So should each sector have just x * sector_size
and y * sector_size
? Do I need (x + 1) * sector_size
and (y +1) * sector_size
?
Let's say you have x * sector_size
as sector_x_start
. You CAN have sector_x_end
(as (x+1) * sector_size
), but you don't have to because you can easily get it when needed: sector_x_end = sector_x_start + sector_size
.
If you need sector_x_end
very often, it can be a good idea to have it, but if you don't need it often, just use sector_x_start + sector_size
instead.
Ok, now I get you. Thanks I'll try implement it that way then
Any updates?
I'm finding it hard to update this project this year. I'm currently in junior cert (exam year) so need to spend some time studying and homework
How should I go about creating the sector's for my slither server? Should I create them all at once and if so, do each of them need ID's?