2

What is the game all about?

It's a puzzle game. I am using AndEngine to build it on Android platform (currently). I have divided the game into various World, with each World containing various Levels.

What is the Issue?

See the Game design below. The purpose of the game is to drag-and-drop the broken pieces into the "drop" area (a.k.a. holder) and form the circle. I've developed the basic 2 levels of the game. This is the third level. Where there are 3 pieces as different objects named 1,2,3. I've to drop all 3 pieces into the drop. The issue is how do I know that all the broken pieces have filled the holder? I'm using AndEngine for the first time and have very little idea how this can be done. Tapping on any broken object would rotate it by 90 degrees. So there can be 4 possible solutions for each of them).

Level3

Also, the logic should hold true for any shape, any number of broken pieces, any number of holders.

Ideas that I've thought about

We've thought to solve this using:

  1. Area of the holder is filled -> But how do we programmatically do that?
  2. Take center coordinates of each broken piece and find the distance from the center of the circle. Verify this in all the 4 conditions (all 4 rotations by 90 degree each). -> We're trying to figure this out.
  3. See if all the broken pieces are used in the holder area -> What if there are more than one holder?

Any technical help or any references would be really great.

3 Answers3

2

Given that the 3 puzzle "pieces" can be rotated by 90 degrees hence there can be four solutions . Let the four configurations be called the four "stages" that the sprites can have . So we have four stages for each sprite.

Try this :

1) Get the middle coordinate of each sprite (Using converToLocalCoordinates() ) .

2) Make a table with rows as Sprite 1 , 2 , 3 and columns having Stages 1 , 2 , 3 , 4 .

3) This will give you 12 coordinates .

4) Fill the table , after finding the center coordinates of each sprite in the solutions for different stages .

5) You can make a "snapping" function that when the sprite enters the "holder" in a specific stage then it is set to the appropriate coordinate according to the table made above .

6) To implement snapping better take a range around the answer coordinate where the snapping is implemented .

7) Also if a sprite is already inside the holder and another is inserted , if they collide or if the sprite is not within the "snapping range " then the sprite can be put back to it's original place .

8) Note snapping will happen only if the piece enters according to right state which is determined by the stage of the first sprite that is snapped into the holder.

PadiRulz
  • 46
  • 4
1

You can use mysql and a spatial index for this. Then you can check the user input if all broken pieces together make a circle? Here is link for check polygone-inside-polygone: Check if polygon is inside a polygon?

Community
  • 1
  • 1
Micromega
  • 12,486
  • 7
  • 35
  • 72
0

If the pieces all rotate by 90 degrees, there are four "different" solutions to each puzzle, right?

I'm not sure about technical implementation, but perhaps area could be calculated pixelwise? You would have to count non-transparent pixels rather than using the bounding box (assuming .png sprites).

Your idea of calculating based on proximity to the centre of the circle would not be too difficult to implement, however. Once you have the (x,y) of one solution based on the size of the sprite bounding box, you can add and subtract the circle's radius in pixels as necessary. You just need to know which quadrant of the circle the piece's anchor point resides in.

I hope these ideas help.

x4nd3r
  • 855
  • 1
  • 7
  • 20