Saving the world ... or at least, a small puzzle

Published July 14, 2008
Advertisement
Well, I've finally done it: I've started working on letting my little cow lose a life.

This is something I've been putting off (for literally years) for quite a few reasons: I didn't know how to portray the "death", I didn't know whether I wanted lives or health or both, I didn't know how to handle puzzle and item state across a character death. And it's not that I've necessarily resolved all those problems - but I figured I just needed to make a start on it.

The first thing I did is punted on the death animation/rag doll bit - and for now, I just catapult the little cow into space when he hits something deadly. In the test moovie below, the "Spikes" model has a "Toxic" behaviour attached to it which sends a "Damage" message to the cow, and for now at least, the cow loses a life rather than some hitpoints. I might look at adding health-style damage later - but my immediate goal is just getting the spawn-play-die-restart cycle working.

Next, I had to handle resetting the current area/map/room. This turned out to be a really interesting problem - and a lot harder to solve that just saving/reloading the current game state (which is already solved via the built in object serialisation). You see, the plan is for the cow to get lot of little puzzles to solve: How do you reach the key up on that platform? How do you open that door? Etc. So what happens when the player goes into a room and destroys some block that they actually need to finish the puzzle? Or they push the key off the cliff? I need a way of resetting all the elements of a given puzzle back to a solvable state.

Before I waffle on about the boring behind the scenes work, here's a little moovie of it working in a test scene: there's a switch which is setup to remove a block from the room, and there's a gun that rests on the block (so flipping the switch lets the gun fall to the ground where you could pick it up). In the vid, you can see the cow flips the switch, and then suicides on the spikes. When the character respawns, not only is the cow put back as he was, but the switch flips back, the block re-appears, and the gun falls back down from its starting point.

Disabled

To implement this, I've added a Snapshot object. Whenever you enter a new area, the game populates the Snapshot with all the puzzle elements for that area and takes a snapshot of their current state. Then, whenever you die or re-enter the area, it restores the snapshot. The cool thing about the snapshot is that it's built on top of the exiting serialisation mechanism, but modified so that it restores values on the existing objects, rather than replacing them with a new object. This allows it to "undo" literally any change (e.g. not only can you move things around and have them put back, but you can remove the physics from an object and it will put it back, you can destroy an object completely and it will resurrect it for you, you can change the state of a state machine and it will put it back, you can turn off gravity and collisions on an object and it will turn them back on, you can change the colour of the shader ... you get the picture). And because it restores the current objects, it won't break any relationships to other objects in the gameworld (for bigger quests, etc). As a bonus, because it's a layer on top of the serialisation code - I can choose to use XML (for dev/debugging) or binary (for speed/size) to implement the snapshot - which has already saved me hours in debugging the feature to start with.

Next I need to think more about how many Snapshots the game will actually use to properly handle independently resetting the room vs specific parts of the player's character (e.g. right now, the snapshot restores the character's life count ... which kind of defeats the purpose of letting him lose a life in the first place). Still, I can now start a new game (from my spiffy menus of last entry), walk around until I lose a life, then restart the current room ... which is getting much closer to actually having a very simple end-to-end game cycle working.


Cheers!
Previous Entry User Interface
Next Entry Game Over
0 likes 5 comments

Comments

rip-off
Very nice. I like the randomness of being flung into space.
July 15, 2008 06:26 AM
MarijnStevens
Darn I like your journal.

I was thinking about how you keep track of changes in the snapshot. If you unlocked the door in Room1, doesn't the snapshot lock the door again if you enter Room1 ? How do you keep track of changes ?

Also your death animation more looks of a "beam me up, scotty" thing. Can be more of a dead animation if you actually leave the dead cow on the ground, and let a translucent cow go up in the sky with a little halo above it... :)

Oké I will quit rambling. Keep up the nice work.
July 15, 2008 08:59 AM
Aardvajk
Seem to remember the mighty Head Over Heels had a similar system of resetting rooms as a method to stop you getting stuck on puzzles.

Damn you, MudCake, now I have to install QuickTime [smile].
July 15, 2008 01:11 PM
Milkshake
Quote:Original post by rip-off
Very nice. I like the randomness of being flung into space.


Hehehe - it was just the best I could come up with that only took a few lines of code and didn't require any new animation. I was thinking for a while I might even keep the camera on the cow, launch him into the air, and then bring him back down at the respawn point after the room resets (so it happens offscreen).

Quote:Original post by MarijnStevens
Darn I like your journal.

I was thinking about how you keep track of changes in the snapshot. If you unlocked the door in Room1, doesn't the snapshot lock the door again if you enter Room1 ? How do you keep track of changes ?

Also your death animation more looks of a "beam me up, scotty" thing. Can be more of a dead animation if you actually leave the dead cow on the ground, and let a translucent cow go up in the sky with a little halo above it... :)

Oké I will quit rambling. Keep up the nice work.


Thanks and thanks =)

That's a very good question about the door - and there's a similar problem with items you pick up (as when an item, like the gun say, is in the world, it has physics on it, but when you pick it up, it removes the physics and attaches it to your character's skeleton). I only really covered the basic Snapshot behaviour in the main post for fear of boring people, but it's capable of more subtle behaviour as well.

Firstly, the snapshot will soon support random access into the undo data - meaning the game can choose to individually control which items get reset. Items are a good example of this - you need to snapshot the gun's initial state so you can make it fall back onto the block if the room gets reset before the player picks up the gun ... but if the player does get the gun, you shouldn't restore the gun (as this would replace the physics, reset the ammo count, etc).

And secondly, there will be a way for the level designer to select which objects (if any) get saved/restored when the room is reset. So you can create a room full of enemies that don't respawn, but if a certain puzzle requires an enemy to be there, you can include that in the snapshot set. I haven't fully worked out what this will look like just yet - but my current thought is to actually have a Puzzle object attached to the room that identifies all the components of the puzzle, and has a "Completed" input that you can set when the puzzle is finished so the puzzle stops resetting. This behaviour really depends on the game logic, so I'm holding off on this until I have something a bit more playable.


Quote:Original post by EasilyConfused
Seem to remember the mighty Head Over Heels had a similar system of resetting rooms as a method to stop you getting stuck on puzzles.

Damn you, MudCake, now I have to install QuickTime [smile].


I'm so impressed you recognised that from Head Over Heels! Bravo!

Most of the time, Head Over Heels actually just reloads the room from the compressed map data. But there is one scenario where it does save/restore the current room state (when one character enters a room already occupied by another character). But even then, I suspect the game actually just had one "live" room slot for each character and it copies them across when you die when they're both in the same room together.

But in any event, I'm hoping my Snapshot will be a little more flexible that HoH in that you can pick and choose what gets reset. But I will totally admit I've designed it with my future Head Over Heels remake in mind =)
July 15, 2008 05:26 PM
Milkshake
Quote:Original post by EasilyConfused
Seem to remember the mighty Head Over Heels had a similar system of resetting rooms as a method to stop you getting stuck on puzzles.

Damn you, MudCake, now I have to install QuickTime [smile].


I replied to this ... but for some reason it popped out above your post ... strange.

And let me take this opportunity to apologise profusely for the QT install. I'm on a mac, so it's relatively painless ... but I seem to recall from my old PC days that the Quicktime plugin for windows is one of those annoying bits of software that just doesn't stop bugging you for stuff.
July 16, 2008 02:18 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Moose Sighting

1394 views

Constraints

1563 views

Moose

1296 views

Melon Golf

1855 views

Toon

1358 views

Spaceships

1110 views

Rendering Pt2

1201 views

Hardware Shaders

1240 views
Advertisement