Author Topic: How should I store levels?  (Read 2322 times)

0 Members and 1 Guest are viewing this topic.

Offline Downsider

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 12
  • Rating: +0/-0
    • View Profile
How should I store levels?
« on: February 03, 2011, 12:40:02 am »
Okay. In my game, I currently store levels in 1024 bytes of data, making a 32x32 level. I store it like this:

[0101010101010101010101010101010101010101010101010101010101010101]
[0101010101010101010101010101010101010101010101010101010101010101]
...
[0101010101010101010101010101010101010101010101010101010101010101]->GDB0

The problem with this is that some tiles are destructable and it modifies GDB0's data directly. How can I have GDB0 reload from what I set it to when I launch the game again or when the player dies? Currently, the destroyed tiles stay destroyed, unfortunately.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: How should I store levels?
« Reply #1 on: February 03, 2011, 03:54:04 am »
If this remains a program, and not an app, then you can can continue to use self modifying code by adding an extra buffer.  So lets say GDB1 is the unchangeable level and GDB0 is your level buffer (this is what you use in the game).

[...lots of level stuff...]->GDB1  .Your level data for level 1
[...lots of level stuff...]->GDB2  .Your level data for level 2
Zeros(1024)->GDB0       .Your buffer
Copy(GDB1,GDB0,1024)    .Copy all of level 1 into the level buffer
...Feel free to modify this now...
Copy(GDB2,GDB0,1024)    .Copy all of level 2 into the level buffer
...Feel free to modify this now...
Copy(GDB1,GDB0,1024)    .Reloads level 1 again, restored to normal like it should
...etc...
« Last Edit: February 03, 2011, 03:54:27 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: How should I store levels?
« Reply #2 on: February 03, 2011, 03:10:38 pm »
I was just wondering, how do you change tiles in the middle of the game?
In-progress: Graviter (...)

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: How should I store levels?
« Reply #3 on: February 03, 2011, 07:07:58 pm »
leafiness0:
Code: [Select]
(New tile value)->{(Yposition of new tile) * (Width of level) + (Xposition of new tile) + (Level data start)}