January 15th, 2016Making Room

Look at that, it’s been precisely a week and already there’s enough to talk about to sorta-justify another one of these thinly-veiled excuses to slowly move my blog away from all the serious seriousness of The Day to something a little more lighthearted and fun in the hopes that I can one day talk about cooking and movies without it being too jarring a change in tone.

Anyway.

Last time I was very excited about scripting and drawing houses, and in a way that hasn’t changed, except that now the house looks something like this:

Almost looks like an actual game, doesn’t it?

A lot of rearranging and restructuring of the code aside, the main addition to my little CORE project are the Renderer and Sprite classes. After an image is loaded and basic information like dimensions, position, scale, etc. are stored, the renderer will draw them using a single set of vertices which are transformed according to each sprite’s definition. My goal is to render all sprites with a single draw call, so instancing is probably the next thing I’ll look into.

But of course that alone wouldn’t be much fun if you couldn’t do it from script, so you can, which makes building the room above as easy as this:

function load()
{
    try {
        renderer.add("room.jpg").SetPosition(400, 173);
        renderer.add("hud.jpg").SetPosition(320, 426);
        renderer.add("book.png").SetPosition(362, 400);
        renderer.add("arrows.png").SetPosition(320, 426);
        renderer.add("verbs.png").SetPosition(320, 426);
        
        renderer.add("weirdo.png").SetFilter(GL_NEAREST, GL_NEAREST)
                                  .SetPosition(470, 216)
                                  .SetScale(0.8, 0.8);
    } catch(id) {
        ::print("SQUIRREL ERROR: " + id + "\n");
    }
}

Speaking of that weird try/catch thing, my biggest issue the past few days has been getting Squirrel to talk to me, and I’m still not entirely sure how it works. It either fails silently or outright crashes the program, so after way too many hours of tweaking the binding of classes and functions I finally got the idea to use this little workaround, and voilà! Creating 2D worlds from script!

Now, scripting game logic is technically already possible as well, but of course there’s too much functionality missing to actually do anything exciting with it at this point. Therefore the next steps will include figuring out instancing, flipping images, Z-order, and offering the access needed to get images moving; perhaps input even!

Well then, since I’ve been writing about this two Fridays in a row, maybe there’s a chance I’ll do it again next week (knowing me, though, that’s a big maybe, so breath holding is not advised).

Crabman out.