I'm developing a Game like paper.io in C++ with Win32 API. My Game data is stored in an array like:
1 = Player's Head
2 = Player's base
3 = Player's tail
Now I want to fill the polygon (Player's tail) with the Number 2 (Player's base).
Scan Line Algorithm:
What works:
- If I scan the 5. line The first 3 trigger the algorithm and toggle the painting function. The next 3 toggles it again it stops the painting function again
Problems:
- If I scan the 2. line After Every 3 the painting function will be toggled and after the line, it will paint further, because it's an odd amount of numbers.
Solutions:
- Toggle on the transition from zero to non-zero (and non-zero to zero)
Problems:
- I need to find the middle/spot to begin, that's in the polygon
There are a lot of special cases that make it tricky to determine which areas are inside the new base vs. outside, but this one is simple and reliable: