Probably Dance

I can program and like games

A simple jump

Here at DigiPen people make a lot of platformers. And I see them getting the basic jump wrong over and over again.

It turns out that you can write a whole lot about the implementation of jumps in games (ideal jump height and speed, amount of air control, double jumps etc.) but in this post I’ll just explain how to start a jump, because this is where I see people repeating the same mistake: If you have stepped just one pixel too far over the edge of the platform before pressing space, you will fall to your death.

Fixing that is fairly simple.

Read the rest of this entry »

Loving std::unique_ptr

I am falling in love with std::unique_ptr.

It’s part of the new C++11 standard and is pretty much a smarter way of doing auto_ptr. The main difference is that you can not assign or copy it. Meaning it really is just a handle for a pointer that deletes it’s content when it gets destroyed.

Which doesn’t sound like much, but it will stop you from making so many mistakes. The benefit of it is that now you have a clear concept of who owns the content of the pointer.

Any time where you used to do

class Foo
{
    Base * member;
public:
    Foo() : member(new Derived()) {}
    ~Foo() { delete member; }
};

should just be replaced with

class Foo
{
    std::unique_ptr<Base> member;
public:
    Foo() : member(new Derived()) {}
};

Read the rest of this entry »

SSE2 in Visual Studio

So for some reason I thought I should be using SIMD in my student projects because it’s something that I should learn about, and I might as well do that when I’m not bothering other people with it.

It turns out that Visual Studio will hate you for it. It will hate you for using objects that have a specific alignment in memory.

The reason I’m writing this post is because I just had to write my most ingenious (not) workaround yet for getting a SSE2 class to work with Visual Studio:

class Vector4
{
    union {
        __m128 xyzw;
        struct { float x, y, z, w; };
    };
    /* ... */
#ifdef DEBUG
// for some reason visual studio sometimes copies a Vector4 to a non-aligned position
// in debug mode. which is illegal and crashes the game. it never uses that Vector4
// though, so just changing the copy constructor to not use SIMD is enough
inline Vector4(const Vector4 & other) : x(other.x), y(other.y), z(other.z), w(other.w) {}
#else
inline Vector4(const Vector4 & other) : xyzw(other.xyzw) {}
#endif

Read the rest of this entry »

It’s not a generational thing

I’ve often heard that for games to be properly accepted, we just have to wait a couple of years until those people who haven’t grown up with games are no longer in positions of power and then we’ll be fine.

I no longer believe that. I think that a large part of the current generation of young adults actually has a pretty bad opinion of games.

Read the rest of this entry »

Storing information in a .png

Spore did a neat thing where they stored the creature information in a .png file that was a picture taken of the creature. So to share the creature you had to share the image, which is pretty cool. And it turns out that it’s really easy to do. Well if you are already using libpng that is.

I implemented it for the game Leshy, but we only used the feature for the auto save functionality of the editor, because the game didn’t have loading and saving. (simply because it would have been too much effort to program a menu that allows you to load and save)

Autosave file for Leshy editor

Auto save file for the Leshy editor. This is the actual save file. I could load the level from this image.

Read the rest of this entry »

My “Way Too Generic Serializer”

I wrote a serializer for my engine that is extremely convenient and generic.

A piece of serialization code in the engine looks something like this:

class PlaceMode
{
public:

    // ...

    SERIALIZE_FUNCTION(1)
    {
        SERIALIZE_START();
        if (version < 1) SERIALIZE_BASE(State);
        else             SERIALIZE_BASE(EditorState);
        SERIALIZE(archetypeNames);
        SERIALIZE(lastPosition);
        SERIALIZE_END();
    }

private:
    std::vector<std::string> archetypeNames;
    Vector4 lastPosition;
};

Read the rest of this entry »

Template Metaprogramming, Reflection in C++0x

So I’ve been working on the serialization code for our engine. And I’m finally understanding the more complex aspects of template metaprogramming, and it turns out that there are some neat things you can do with it that aren’t directly related to serialization.

OK let’s say you have an editor in your game, and in this editor you have a button “Add Component” which adds a new component to an entity. That button would open a pop-up menu, where you can select from all your component types and after selecting one, a new instance of that component-class is created and added to the entity. How do you populate that list? My solution using template metaprogramming and reflection is after the jump:

Read the rest of this entry »

About Playtesting

So I’ve been thinking a lot about playtesting recently. Mainly triggered by Portal 2, my experience in making the game Leshy over the last semester, and also by lots of other stuff like this talk by Jonathan Blow.

I was showing the finished version of Leshy to our composer, Tyler and I was watching him play the game. He eventually got to an area where he got stuck. And I knew exactly that the reason why he was stuck was, that he had gotten to this area too early and that he didn’t yet know about a game mechanic that another area would have instructed him about.
If you have ever done a playtest, you know that this is a horrible situation. In playtesting you are not supposed to intervene. You don’t give hints, you just watch the player play and see if he figures it out or not. So I was sitting there watching this guy trying various different things, all of which were destined to fail. It was extremely frustrating to watch this. I knew that he couldn’t succeed because the game hadn’t instructed him yet, but yet he kept on trying. He got it almost right and failed. He got it very wrong and failed. He tried the very wrong thing again and failed. He failed, failed and failed again. And I’m sitting there just wanting to shout and scream and just tell him how to do this, and that this wasn’t his fault and that we’d fix this and oh why won’t you at least give up and go somewhere else first so that you may come across the training section that you missed.

Get the sphere up to those stairs. Shouldn't be that hard, right?

Anyway. That was my impression. He on the other hand was having a good time. For him this was a challenging puzzle that he was trying to figure out. It is totally OK for a player to be working on a puzzle for five minutes, at least as long as he can keep on trying new stuff and isn’t completely stuck. And he did eventually figure it out.
I don’t think he was frustrated at all. It was just me being frustrated. Below the jump I think about Valve in relationship to this experience:

Read the rest of this entry »