The world is initially a rectangle. The player can move on the world border and then "cut" the world via orthogonal paths (not oblique). When the player reaches the border again I have a list of path segments they just made.

I'm trying to calculate and compare the two areas created by the path cut and select the smaller one to remove it from world.

After the first iteration, the world is no longer a rectangle and player must move on border of this new shape.

How can I do this? Is it possible to have a non rectangular path? How can I move the player character only on path?


Here you see an example of what I'm trying to achieve: 5 phases of a rectangle being cut smaller by other rectangles

  1. Initial screen layout.

  2. Character moves inside the world and than reaches the border again.

  3. Segment of the border present in the smaller area is deleted and last path becomes part of the world border.

  4. Character moves again inside the world.

  5. Segments of border present in the smaller area are deleted etc.

  • \$\begingroup\$ How do you know, where to cut? What if player connects left and right border of initial rectangle or "cutted" rectangle? \$\endgroup\$ – zacharmarz Mar 29 '12 at 13:47
  • \$\begingroup\$ @zacharmarz he'd like to cut the smallest area. I guessed this because it looks like he's trying to achieve a Qix/Gals Panic clone. \$\endgroup\$ – kaoD Mar 29 '12 at 15:11
  • \$\begingroup\$ @kaoD yeah! you're right! \$\endgroup\$ – Mauro Destro Mar 29 '12 at 15:48

It's difficult to understand the context of your problem without an image. It sounds like the player is given the ability to divide a polygon along an arbitrary axis thereby producing two, possibly irregular, polygonal shapes. The process of actually splitting a specified Rectangle into these two shapes is rather simple.

If the axis must bisect the entire shape, it produces two sets of Vector2s that represent the vertices of two polygons. To determine the area of these two irregular polygons would require a simple triangulation of the polygons. There are existing implementations of well known triangulation algorithms like Delaunay triangulation, but for simple shapes you may be able to roll your own with little issue. If this is not the situation you're facing, please elaborate on the context of your question and I'll give it another shot.

| improve this answer | |

So, I first assume you are trying to make a game with gameplay elements highly similar to that of Cacoma Knight in Bizyland You have the general idea down, but you are imagining too much that adding a new rectangle requires the game to "remove" the overlapping borders of the old rectangle. This is not the case at all. Simply maintain a list of rectangles, with the first item in the list being a rectangle occupying the entire gameplay screen. Whenever the player sucessfully traces a new rectangle, it is added to the list.

In your game loop's update function, check the rectangles in the list as the player moves, and do not permit them to cross a horizontal line of a rectangle while moving vertically or the vertical line of a rectangle while moving horizontally. In addition, the entire time, do not permit them to move to any coordinate that is not on the border of a rectangle, unless they are currently "cutting" from the world.

Special things to consider include logic to use the edges of already existing rectangles to create the new ones. The parameters of the already existing items in your list are sufficient to perform the necessary logic for this. Also, this is a more simple form of gameplay than the video I linked, in which you can create more complex shapes. If you want to do more complex shapes, you would use a list of lines instead of rectangles, which would either run purely vertical or purely horizontal. The same concept applies, in which the player can't cross horizontal lines vertically or vertical lines horizontally, but you need to add some complex logic for keeping track of the lines the player is cutting out, as well as to help define when a shape is complete.

I wish you the best of luck, and hopefully I have been of help.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.