Original Post
Hi,
In my platformer game, i split up the map file into "sectors." The size of 1 sector is the same size as the screen. When i draw and update game objects, i just deal with the ones that are in the same sector as the player and one sector in every direction(not diagonal). Like this:
[-][-][-][-][-][-]
[-][-][-][color="#ff0000"][-][-][-]
[color="#000000"][-][-][color="#ff0000"][-][color="#ffff00"][color="#0000ff"][-][[color="#ff0000"]-][-]
[-][-][-][color="#ff0000"][-][-][-]
[-][-][-][-][-][-]
[color="#0000ff"][-] [color="#000000"]- Player's sector
[color="#ff0000"][-] [color="#000000"]- Sectors to update
So, i need to calculate which sector the player is in from his coordinates.
I've tryed this:
It calculates the player's sector perfectly when at ground level. When i go up it goes into negative numbers. The origin of the screen is in the top left so sector 0,0 should be in the top left.
How can i correctly calculate the current sector?
In my platformer game, i split up the map file into "sectors." The size of 1 sector is the same size as the screen. When i draw and update game objects, i just deal with the ones that are in the same sector as the player and one sector in every direction(not diagonal). Like this:
[-][-][-][-][-][-]
[-][-][-][color="#ff0000"][-][-][-]
[color="#000000"][-][-][color="#ff0000"][-][color="#ffff00"][color="#0000ff"][-][[color="#ff0000"]-][-]
[-][-][-][color="#ff0000"][-][-][-]
[-][-][-][-][-][-]
[color="#0000ff"][-] [color="#000000"]- Player's sector
[color="#ff0000"][-] [color="#000000"]- Sectors to update
So, i need to calculate which sector the player is in from his coordinates.
I've tryed this:
SectorX = (int)player_struct->Position.X/G_SCREEN_WIDTH;
SectorY = (int)player_struct->Position.Y/G_SCREEN_HEIGHT;
player_struct -> CurrentSector = SectorX+(SectorY*CurrentMapFile.WidthInSectors);
It calculates the player's sector perfectly when at ground level. When i go up it goes into negative numbers. The origin of the screen is in the top left so sector 0,0 should be in the top left.
How can i correctly calculate the current sector?