1
\$\begingroup\$

I'm new to LibGDX and android development in general and am trying to do a puzzle game. Being a level-based game, i'm trying to make it so in every level a certain number of blocks (just rectangular sprites) appear in a certain position / rotation, like in the image linked below:

https://i.gyazo.com/52e6c71e1f05ab4529e0fec9d4f80bd7.png

I've doodled some levels already but i'm really not sure about how to make the blocks's rearrangement over the levels. How exactly should one manage this? As the position of the blocks won't be random i was thinking about reading from files the information from every level (x, y, rotation, colors, etc. for every block) but to do that i would have to manually organize every level's blocks properties information (to then save), and, considering it would have atleast 100+ levels, it would take too long... Other than that, i could have them as plain assets but having an asset for every single level doesnt't look like an efficient solution either. Do you have any tips, please?

\$\endgroup\$
  • 2
    \$\begingroup\$ Your first step would be to create a level editor :) \$\endgroup\$ – Vaillancourt Nov 15 '15 at 19:37
  • \$\begingroup\$ @AlexandreVaillancourt Hey, thanks alot for the quick answer! Sorry to bother, but would you mind explaining a little bit about how exactly would the level editor work(or tell me where i could find more information about it), please? \$\endgroup\$ – Francisco Nov 15 '15 at 19:55
  • \$\begingroup\$ You have to make the level editor yourself, using LibGDX. Play around with mouse events. To draw rectangles, for example, you'd listen for when the mouse is down and record where the cursor was dragged across, creating your rectangle there etc. \$\endgroup\$ – Lolums Nov 15 '15 at 20:03
  • \$\begingroup\$ "How to get started" are off-topic questions for Game Development, and your question is very close to be off topic. However, I can try and point you in the right direction in the comments. When making a level editor, you have 2 options: in-game and out-of-game. In-game: you add the feature to your game to create, edit and save the levels. This has the advantage that you only have to code 1 engine, even if you need more than 1 'mode'. Out-of-game: you program a 2nd app which you use to create your levels. This makes the "mode management" easier, but you have to build 2 different engines. \$\endgroup\$ – Vaillancourt Nov 15 '15 at 20:04
  • \$\begingroup\$ @AlexandreVaillancourt think i got it, thank you very much! \$\endgroup\$ – Francisco Nov 15 '15 at 20:06
1
\$\begingroup\$

In a puzzle game that I have been working on I have found that an XML file has been a rather efficient way to store level data.

For example, you could have an xml file for each level pack

   <LevelPack>
      <Level number="1">
        <Block x="0" y="0" rotation="90" color="#FF0000" />
        <Block x="50" y="22" rotation="45" color="#00FF00" />
      </Level>
      <Level number="2">
        ...
      </Level>
   </LevelPack>

You could then serialize the xml file into some sort of model object in your code. Even with 100+ levels this should be easy to manage and is way less time consuming than making a level editor.

\$\endgroup\$
  • \$\begingroup\$ Hey, thank you very much for the answer! That does look like quite a good way to do it; i still remain with one question though: what would be best way to tell the x and y values of the blocks considering one block would start where the other block ends? I've tried some stuff, but the fact that each block has it's own rotation / height is making it a bit difficult... :( (I know this isn't really related to the question, but any help would be highly appreciated) i.gyazo.com/df8046a3879d3a90374d82de2c7c7867.png \$\endgroup\$ – Francisco Nov 16 '15 at 22:34
  • \$\begingroup\$ You can use Trig to calculate this. If you know the x,y rotation, and the length of the rectangle, then you can calculate its other endpoint by endX = x + cos(rotation)*length and endY = y + sin(rotation)*length If you want, you can even specify in the XML that some blocks have relative positioning and you can calculate this when you load the level \$\endgroup\$ – spectacularbob Nov 16 '15 at 23:05
  • \$\begingroup\$ Hey, i did try using trig but the values i was getting weren't matching the ones i tried manually :( Like, manually a block would start at let's say x= 110 but using trig the value would be like 85. Not quite sure why to be honest, but i will try it out again for sure, thank you so much. \$\endgroup\$ – Francisco Nov 16 '15 at 23:12

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.