ClitherProject / Slither.io-Protocol

The Documented Slither.io Protocol
151 stars 37 forks source link

How should sector's be created on the server? #73

Open RowanHarley opened 8 years ago

RowanHarley commented 8 years ago

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?

Mat2095 commented 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?

RowanHarley commented 8 years ago

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

Mat2095 commented 8 years ago

All sectors have the same width and height, so one coordinate would be enough.

RowanHarley commented 8 years ago

How should I go about creating the sector's? Should I add sector_count_along_edge and sector_size to the equation?

Mat2095 commented 8 years ago
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.

RowanHarley commented 8 years ago

Ok, thank's! I'll try implement something like that

RowanHarley commented 8 years ago

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

Mat2095 commented 8 years ago

You're using a two-dimensional array I guess?

RowanHarley commented 8 years ago

No, I'm using a one-dimensional array of Sector()'s. Each one holds the start x, start y, end x and end y.

Mat2095 commented 8 years ago

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).

RowanHarley commented 8 years ago

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?

Mat2095 commented 8 years ago

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.

RowanHarley commented 8 years ago

Ok, now I get you. Thanks I'll try implement it that way then

Mat2095 commented 8 years ago

Any updates?

RowanHarley commented 8 years ago

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