So i wanted to make a clone of this game : http://www.physicsgames.net/game/3_Slices.html

someone can give me a hint how to make it works ?

3 posts
• Page **1** of **1**

So i wanted to make a clone of this game : http://www.physicsgames.net/game/3_Slices.html

someone can give me a hint how to make it works ?

someone can give me a hint how to make it works ?

**Posts:**9**Reputation:**695

B

15
S

2
The core part is being able to slice a polygon by a line into two polygons. This can be done by calculating the intersection between the line and the edges, as well as finding which side of the line a point is.

Here's one possible psuedcode of the algorithm to do it:

Next we have the issue of drawing an arbitrary polygon and changing the collision polygon. Vanilla C2 plugins won't help here. I don't use it but the third party polygon plugin by yann probably could work since it both lets you draw arbitrary polygons at runtime and it makes it's collision polygon match.

The rough psuedocode for that could be:

Also on a side note you'll want to set the new polygons' velocities the same as the old polygon otherwise the pieces will go at a complete stop after slicing.

At least that's a general idea how to do it. There might be some issues that need to be ironed out, such as I don't know how well the polygon plugin works with the physics behavior.

Here's one possible psuedcode of the algorithm to do it:

- Code: Select all
`for each edge clockwise`

if edge.point0 is on left side of line

add point to poly1

else

add point to poly2

if edge intersects line

add intersection to poly1

add intersection to poly2

Next we have the issue of drawing an arbitrary polygon and changing the collision polygon. Vanilla C2 plugins won't help here. I don't use it but the third party polygon plugin by yann probably could work since it both lets you draw arbitrary polygons at runtime and it makes it's collision polygon match.

The rough psuedocode for that could be:

- Code: Select all
`get the list of edges of a polygon`

try to slice the polygon in two with a line

destroy the old polygon and create two new polygons from the sliced polygons

Also on a side note you'll want to set the new polygons' velocities the same as the old polygon otherwise the pieces will go at a complete stop after slicing.

At least that's a general idea how to do it. There might be some issues that need to be ironed out, such as I don't know how well the polygon plugin works with the physics behavior.

**Posts:**5,495**Reputation:**81,678

B

95
S

34
G

128
R0J0hound wrote:The core part is being able to slice a polygon by a line into two polygons. This can be done by calculating the intersection between the line and the edges, as well as finding which side of the line a point is.

Here's one possible psuedcode of the algorithm to do it:

- Code: Select all
`for each edge clockwise`

if edge.point0 is on left side of line

add point to poly1

else

add point to poly2

if edge intersects line

add intersection to poly1

add intersection to poly2

Next we have the issue of drawing an arbitrary polygon and changing the collision polygon. Vanilla C2 plugins won't help here. I don't use it but the third party polygon plugin by yann probably could work since it both lets you draw arbitrary polygons at runtime and it makes it's collision polygon match.

The rough psuedocode for that could be:

- Code: Select all
`get the list of edges of a polygon`

try to slice the polygon in two with a line

destroy the old polygon and create two new polygons from the sliced polygons

Also on a side note you'll want to set the new polygons' velocities the same as the old polygon otherwise the pieces will go at a complete stop after slicing.

At least that's a general idea how to do it. There might be some issues that need to be ironed out, such as I don't know how well the polygon plugin works with the physics behavior.

wow that a lot of explanation, thanks rojo

i will look forward to try this

**Posts:**9**Reputation:**695

B

15
S

2
3 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: Blendi1223, Neschalk and 5 guests |