I'm playing around with PyGame.
Now I'm trying to implement a QIX clone.
I have my game loop, and I can move the player (cursor) on the screen.
In QIX, the movment of the player leaves a trace (tail) on the screen, creating a polyline.
If the polyline with the screen boundaries creates a polygon, the area is filled.
How I can accomplish this behaviour ?
How store the tail in memory ?
How to detect when it build a closed shape that should be filled ?
I don't need an exact working solution, some pointers, algo names would be cool.
At start, there is only the gray border, where the player can move his cursor around.
- First scenario:
The user moves his cursor from point A trough point B, drawing the red multiline until point C. At this point, because of crossing the border, the point A should be connected with point C automaticaly, creating a polygon, which should be filled (that orange stuff on my drawing). Filling the polygon is damn simple in PyGame, because I provide the sequence of points,and PyGame cares of the rest.
- Second scenario:
The user moves on the border to point D, from where he draws a line to point E. Because he is crossing the line of the previous polygon, and with his lines and the border another polygon can be created, it should be filled too. (the green one).
- Third scenario:
The player moves further on the polygon (he can move on existing polygon lines), and draws a line from point G to point F. Here again, because of the border and the existing lines, another polygon should be filled (the blue one).