DEV Community

Alek Westover for enchantedForest

Posted on

enchantedForest[5]

SAVING SYSTEM

Today we wrote a saving system for our game.
It's really starting to feel like a real game now!
Once we add real quests, and you can save your quests and level up and stuff it's going to be super epic!

In writing the saving system we had some adventures.

Most notably our .git file got corrupted somehow, resulting in massive panic, and cp -ring and scp -ring. In the end we found a pro solution though: rm -rf .git, and then cp -r .git from a different clone of the project. As they say "high quality".

Anyways, as expressed I'm super hyped about the checkpoints saving your progress.

For the curious people out there here's what our createAccount function looks like:

    mongo.db.users.insert_one({"username": username, "pwd_hash": pwd_hash, "data": {
        "checkpoint_room" : "llamaPlains", 
        "health" : 50,
        "coins" : 100,
        "mana" : 100, 
        "completedQuests" : [ ], 
        "level" : 1, 
        "xp" : 10, 
        "items" : [ ] 
        }
    })

Also, another really nice thing that we did is we kind of messed around with the stats and stuff. Like we made the mana generation rate more reasonable.

Also, @kaisucode made an absolutely epic health bar, that is way better than hearts imo.

Also a little comic strip for your enjoyment:

Alek: yo how do you update something in MongoDB?
Kevin: let me look it up
Alek: wait no I can just drop the database
Alek: how do you insert something into a database?
presses up arrow 100 times
Alek: found it!
Alek: Aw crap we're hashing the pwds
Alek: loolllll creates account with same pwd, copies hash
Alek: drops database again
Alek: wait should I drop the database again? ok
Alek: hmmm.
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: Why can't I press tab to autocomplete filenames when I'm scping. oh wait. lolll.
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: db.dropDatabase()
Alek: ayy it works! ok we're never allowed to modify the database btw.

Next time we're gonna be making the game more legit. In particular, we will be

  • adding the first boss
  • adding some more rooms
  • making the quests real
  • making the npcs real
  • making the merchants real

It's going to feel like a real game!
Get ready!!!!!

Finally, I would like to close with an inspirational thought.
When testing the game saving stuff, we made it save health first. In order to get the test to pass we had to lose health, and then reload the page and have the low health. Getting to a checkpoint took a while though. This prompted the following brilliant realization: if the player died, it respawned close to the checkpoint.

You would kill yourself to get to the checkpoint faster?
Some things are worth dying for.

pretty much.

Ah, what an enchanting forest.

Top comments (0)