Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

EDIT

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.

share|improve this question
    
How do you know, where to cut? What if player connects left and right border of initial rectangle or "cutted" rectangle? –  zacharmarz Mar 29 '12 at 13:47
    
@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. –  kaoD Mar 29 '12 at 15:11
    
@kaoD yeah! you're right! –  Mauro Destro Mar 29 '12 at 15:48
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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