Slice 'n dice
A downloadable project for Windows and macOS
A small casual puzzle game about slicing polygons to match the correct shape.
Slice 'n dice is a small project built around the concept of polygon's triangulation and line intersections.
Triangulation
The game's triangulation algorithm is based on the "ear-clipping method": https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
Every polygon in the game is just an array containing each vertex's x & y position in the room. The triangulation algorithm makes it possible to draw a filled out polygon, using the polygon's vertices, and simply drawing each triangle it contains.
The triangulation algorithm is also used for scaling the polygons in respect to the screen size and camera view, to keep the polygon in-sight. By triangulating the polygon, it makes it possible to calculate the area, by finding the sum of all the triangles in the polygon. Then applying the area of the triangle to find the offset value between the maximum size, and "scaling" each vertex from the origin of the polygon.
Line intersections
The game's slice mechanic is built on line intersections: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
Each slice has a start-point and end-point, that creates a line. To determine whether a slice has successfully "sliced" the polygon, we calculate each "intersection point" between the slice's line and each outer-line (two vertices: one vertex, and it's corresponding neighbour vertex -> clockwise) in the polygon. A successful slice contains a pair of "Entry" and "Exit" intersecting points. Entry is where the slice joins the polygon, and exit is where the slice leaves the polygon. If the final result contains an even number of intersecting points (meaning each intersection has an entry and exit), the slice would be seen as successful.
Leave a comment
Log in with itch.io to leave a comment.