Bottom Page

Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Handle giant 2D map
Hi everyone !

I'm posting here to get some help about a "concept" in coding. In fact, i've coding a little code which allows me to display an object that you can move in a window. This "player" can go outside the window and it will load the next map etc.. So basically my program is based on files which contains 20*20 numbers which represent a tile for each ID/number and i blit this array every times in the loop.

But in terms of "gameplay" it looks like the old "prince of persia" on pc : when you reach the limit of the window the next "scene" or "map" replace the current and you have the impression to move around the level by travelling through "canvas/pictures" . It's the first idea i've had to handle a giant map : make more and more little files with 20*20 tiles and blit them as the player go far.

But my question is : How can I handle a type of "open-world" map ? How can I display a 10000*10000 pixels map and moving through it without rendering everything and without loading in the memory a giant array of 10000*10000 IDs ?! It's really a concept that escapes my logic so any help or any observation will be appreciated !

thanks for your help !

( I point you out on the fact that English is not my native language, I'm french but i'll do my best to let you understand what i mean.)
Conceptually, it's the same as either of these two cases:

(1) Imagine you have a nested (2D) list. Normally you'd access it like my_list[a][b]. But you could have a function, or better yet a class which offered a similar interface, my_class.get(a, b). Now imagine the contents of this list are always such that my_list[a][b] = a * b. There's really no need to store that, right? If the computation were more complex, it might be worth "caching" but conceptually, there's no need to pre-compute every value since you can compute it as-needed.

(2) Perhaps the computation isn't "pure" or merely expensive, such that you can't just compute it on the fly (or can't after the first time, or something). You can store the contents in a file on disk. In fact, this would be true of a video (easily >1GB) being viewed on a device with insufficient memory. You can't simply compute the value at a specific time, but you can look it up, and there can be ways to find the place in the file you want.
I've not really understand what you mean by my_list[a][b] = a * b because my file is like as you said : Array[a][b] = x but the "x" could be 1-9999 so i'm not really understanding why a*b as a result.

If i make a class as you said so i need to hardode my entire file ? Because making a method which open/read/write a file seems to me to be "heavy" ? Am i wrong ?

Ps :
To give you an example of the type of file i'm trying to handle, and imagine those 0 could be 1 or any number until 99 : İmage
It was just an example. The right hand size doesn't really matter. I don't understand what you mean about Array, and you hadn't mentioned x previously.

Making a class doesn't mean you'd need to hard code the the file. The method call on the class can reference the file as-needed. It's "heavy" in the sense that it's not as fast as keeping the entire thing in RAM, but your original problem here seems to be that that's not an option. Unless you need to read a ton, it should be fine, reading from disk is a normal activity.

What are you trying to communicate with the screenshot?

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)