Jump to content

Loading levels in simple puzzle game.


Recommended Posts

Hi everyone!

 

I'm making a puzzle game and I already have one level mode pretty much complete. Now I want to add a puzzle mode. There will be a  level selection screen, that looks like all those flash games have. I'll probably not have the padlock though!

 

The information that I need to store about each level is very simple. There is a 4 x 4 grid, each cell contains an object, and all I need to save is the object color, direction, and whether it's moveable, or whether there is not an object at all. This could all be represented by one string that is the image name or by an object. There will probably be about 32 levels or maybe I'll go all the way up to 100.

 

There are so many things I'm not sure of, i'm finding it hard to know where to start. I've googled this many times and keep getting questions about level maps far more complicated than mine. I'll just ask a load of questions and tell you my thoughts and hopefully some of you will be kind enough to answer one or two or give me some kind of advice.

 

Do I need to store the levels in some kind of file or do I just write them in javascript  code?

 

If I do just write it in code, do i need to worry about memory having all those levels with arrays? What if I went up to hundreds of levels? I'm thinking I could store each level but keep each array in a getMap method that returns the level, therefore it won't be in scope until needed therefore not created ,therefore not in memory (I think, but I need to brush up on scope)  I still have a lot to learn about memory and also I have no sense of perspective about when I need to worry about there being too many objects.

 

If I store the levels in some kind of file, I'm guessing it would be JSON. I still need to learn about that. But when would I load them? Does it take a long time on some slower computers that I should load all levels at the start therefore making it pointless, and I may as well just stick them in code. Or do I load only when the user clicks on that level selection screen?

 

 

 

Link to comment
Share on other sites

you're asking too much questions :D

 

in your case it's up to you to store levels inside js code or in an external file ...
external file is cleaner since you keep code and data separated but it's not a rule.

 

now about memory, you say you have a 4x4 grid per level => 16 block.
each block stores

  • a color ; in worst case you'll use '#RRGGBB' format  => 7 bytes
  • a direction : here you'll use a number I suppose => 1 byte
  • a boolean (movable) => 1 byte.


so each level is 4x4x(7+1+1) = 16x9 = 144 bytes   lets says 200bytes per level.

100 levels will use about 20KB  :)


short answer : you are asking too many questions too soon :)
release your game with the simplest solution, then optimise later
 

Link to comment
Share on other sites

Thanks for replying. I will probably store them something like this, because it's easy for me to read and edit.

 

var level = new Level(50, 100, 400,
          [ ["BLUE-0", "RED-1", "GREEN-2", "BLACK-0"],
                ["GREEN-2", "BLACK-1", "BLUE-3", "BLUE-2"],
                ["RED-3", "RED-1", "GREEN-2", "GREEN-3", "BLACK-3"],
              ["GREEN-1", "BLUE-2", "GREEN-3", "BLACK-1", "BLACK-2"]]);

 

 

I'm trying to find out how to work out how many bytes are in a string now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...