Feb 16, 2019 - Useful Gamedev Articles

Comments

Over the years I’ve found myself referring back to the same handful of gamedev articles, because their advice is useful and timeless. I’ve decided to collect them here in one place for easy reference. Hope you enjoy!

Reducing Visual Confusion In Your Game by Peter Angstadt

Side-by-side screenshot of DoTA 2 with a greyscale vs full colour version, with the greyscale image showing the important visual elements like characters and UI

A lot of game devs know how to make good-looking screenshots but the game itself is unreadable because everything looks too busy, too dark or too washed out. This article goes into the visual design theory of why, and really easy ways of improving the readability of your game.

The Theory and Practice of Cameras in Side-Scrollers by Itay Keren

Animation of Super Mario World, with guide lines overlaid showing the boundaries of camera movement. The camera follows Mario at an anchor point and shifts to a different anchor point as he turns and runs.

This article contains an encyclopaedic list of 2D side-scroller cameras, many of which can also be applied to 2D games in general. Essential reading for anyone making a 2D camera.

adventures in level design: Wolfenstein 3D (1, 2, 3) by Liz Ryerson

A screenshot of Wolfenstein 3D showing a barrel blocking an exit elevator

This series of blog posts dissecting a few Wolfenstein 3D levels contains surprising insights, covering not just the classic level design goal of pacing, but also narrative and the surprising effect of confusing map layouts and what that says about an ultimately ridiculous game setting.

Traversal Level Design Principles by Travis Hoffstetter

A rough sketch of a building exterior, with many arrows and labelled points illustrating traversal actions such as climbing up/down, entering/exit points, and going over/across the building.

Traversal is an oft-overlooked but key component of open-world games. Great traversal means it’s fun to get around in the game, and this is just as important as having an interesting world. Good reference article for anyone making a game that involves travelling across a world.

Fix Your Timestep! by Glenn Fiedler (Gaffer On Games)

Normally I’d recommend game devs use a good engine, so you won’t need to write a game loop. But for the stubborn engine developers, or just the morbidly curious, this is a really good article on why your homebrew game loop probably sucks. At least you’ll know what the heck delta time means.

        while ( accumulator >= dt )
        {
            previousState = currentState;
            integrate( currentState, t, dt );
            t += dt;
            accumulator -= dt;
        }

Build a Bad Guy Workshop - Designing enemies for retro games

A big list of retro enemy behaviours. Really great reference for retro game devs.

Splitter The enemy can split into multiple other enemies while destroying itself. Examples: Rogue Legacy’s Slimes, Legend of Zelda’s Vire and Biri.

Cloner The enemy can duplicate itself. Often, the duplicate is an exact clone, but sometimes, the duplicate is very slightly modified (such as having reduced health, or being faster). The enemy that does the cloning is not destroyed. Example: Zelda’s Ghini

Miyamoto on World 1-1: How Nintendo made Mario’s most iconic level

Miyamoto on World 1-1: How Nintendo made Mario's most iconic level

This short (~15min) video by Eurogamer analyses Super Mario Bro’s world 1-1 with its creators including Miyamoto. In it he explains how they designed the level to teach players the fundamentals of playing platformer games, using escalating challenges and sequences. It’s a powerful technique and a superior alternative to overt tutorials and manual instructions.

The same idea has been explored in other places, but this video is a great, concise introduction to the concept.

Reverse Design articles by The Game Design Forum

These are really quality design analyses of classic games. All of them are very good but of particular use are:

  • Final Fantasy 6 and the special way it’s designed around the dungeon as the unit of content, and how that influences everything from battle durations and how to balance those pesky RPG curves.
  • Super Mario World is a masterclass in cadence design - how to ramp up difficulty in a challenging yet pleasing way.

The guide to implementing 2D platformers

Screenshot of Megaman X with Megaman standing on a sloped surface, a hitbox shown and arrows following the sloped surface

An invaluable resource for platformer devs, and also a great article to show people who underestimate the amount of work required for this genre. It even covers tricky cases like slopes, moving platforms, stairs and more.

Jan 27, 2019 - How to Design a Gun

Comments

I love guns in video games; there’s a lot that look and sound really cool. Many games feature gun designs that are so iconic they become part of the identity of the game: there’s the versatile gravity gun in Half Life 2, the beefy assault rifle in Halo, clever portal gun in Portal, and beastly lancer in Gears of War.

assault rifle lancer

Some guns are not only iconic in games, but in movies, even in real life. James Bond’s favourite pistol, the Walther PPK. Or the AK-47, perhaps the world’s most famous assault rifle, well-known in Counter-Strike and many other games, as well as real life - even the flag of Mozambique. Needless to say, their appeal is universal.

ppk ak47

Let’s say you want to design some cool guns for your game. How would you do it? A lot of first-time designers might take bits they like and mash them together. There’s a lot of art kits and even some programs that allow you to do this. Unfortunately, the result often doesn’t make sense, and looks inconsistent.

gun kit

Some designers try to make something that looks the part - guns with powerful-looking big chunky shapes, or cool-looking shiny streaks - but there’s often little sense going into these designs.

future gun

Instead I think form should follow function. Understand how a gun should work, how it’s held and operated, and you can design a gun that makes sense, fits the setting, and looks great.

Let’s try with a futuristic version of the humble firearm. Even today’s modern assault rifles are mechanically very simple, and are fundamentally very similar to the earliest firearms, like muskets and hand cannons.

musket

It may not seem so at first; a modern firearm looks sleek, has many moving parts, and it’s not clear how they work just by looking at it. But break it down and you can see the basic components:

modern gun

  • A barrel - this is where the bullet goes, an explosion pushes it out the other end
  • Something that sets off that explosion - in modern firearms it’s a pin that strikes a primer
  • A grip and trigger
  • A way to load new bullets - usually a magazine

That’s it really, at least the basics. A common feature in semi-automatic and automatic firearms is a mechanism that uses some of the explosive power to load the next cartridge and ready the firing pin. For example, gas-operated firearms funnel some of the high-pressure gas from the barrel back towards the chamber, ejecting the spent case, loading the next one and cocking the hammer, ready to strike and fire the next round.

gun mechanism

Even state-of-the-art firearms are simple machines. You might wonder why they’re not more complex, or more high tech. And they could be; we could, today, include features like electronic firing, caseless ammunition, and digital ammo counters, but they are seldom used in real guns, only in toys and prototypes.

The reason is twofold: cost and reliability. Guns are serious tools, used in extreme circumstances, and so reliability is a top concern. Having a gun fail in combat makes a life-and-death difference. Guns are also used in large quantities - there could be millions of them in a large army - so their cost needs to be reasonable.

beat-up ak

What this means is that even in the near future, firearms will resemble those of today, maybe with some whizzbang extras.

Let’s try with an example. Suppose it is 100 years from now, firearms technology has advanced to allow some of the aforementioned whizzbang to be reliable and widespread. But it won’t look radically different from today. After all, the venerable Colt 1911 pistol has been used by armies for almost a century! Today’s firearms won’t look so out of place even in the not-so-distant future.

So let’s start with the bare minimum. A firearm is like a hand-cannon, it needs a barrel, and something to load bullets at the end. Let’s stick with the humble magazine; it’s worked for centuries after all. [Caseless ammunition] means we can pack more cartridges in our magazine, and aren’t so limited in its shape, so it doesn’t have to curve like a banana.

gun 1

Next we need some way to fire the gun. Keep it simple and stick with the grip-and-trigger that we humans are comfortable with. But let’s stop a moment and consider how the operator should hold and fire the gun. In theory, how the operator holds the gun isn’t beholden to its internals. What’s more important are the ergonomics, if the operator can hold, aim and fire comfortably and with precision. Look a the bullpup design, popular in many of today’s rifles, which moves the grip forward - away from the chamber - but allows the barrel to be moved back, shortening the overall size of the gun, and making it more comfortable to use.

Let’s go with the same layout. In our setting, it’s still important for operators to fire from the shoulder, as he/she needs to aim down the sights. So let’s place some grips where the weight of the gun will be well-supported, as well as a butt against the shoulder.

  • Now if this was 200 years or more into the future, perhaps we can say that computer-assisted aiming is ubiquitous, and guns are fired from the hip, which is more comfortable than from the shoulder. Or maybe even as arm attachments: just point and shoot. Maybe ballistics science and smart bullets mean barrel lengths can be drastically reduced without sacrificing accuracy or firepower. It all depends on your setting, but that’s what we’re doing here: we’re taking into account the principles of what we’re designing.

gun 2

Now add the automatic mechanism. We want some sort of mechanical device to capture some of the explosive energy from the firing back to the chamber, to load the next round. Simple is always best, and to avoid interfering with the grips, it’ll be some tube-shaped device placed above the barrel, like it is with most firearms today.

gun 3

And that’s the basics. Anything else from here is extra, and you have more leeway to add your own flair.

Next we’ll need a sight. Guns used to be mostly aimed with iron sights, crude but functional, and the most reliable. Many of today’s firearms now have more sophisticated sights, from those that offer more visibility, to telescoping, or even offer enhanced, night vision.

In our imagined future, sights are critical. They not only offer greatly enhanced vision: magnification, night, thermal, you name it; they also include vital tactical information, like heads-up display, maps, target recognition and IFF, and anything that the operator might want. Let’s take a page from concept future-soldier guns like the OICW, and put a big sight-computer on top for the operator to look at.

gun 4

Don’t forget about firearms being hand-cannons: they get really hot! To prevent operators from burning themselves, the barrel should be covered with a shroud. This could look any way you want really, it just needs to prevent accidental contact with the barrel. If this were a machine gun, which gets so hot the barrel might warp and break, we’d have to seriously think about cooling, and add air holes and such, but that’s not the case here.

gun 5

What about attachments? Some firearms today have rails where useful attachments - grenade launchers, foregrips, laser pointers - can be added. This very much depends on the operator though. Special forces love these as they can build their perfect, individualised weapon, whereas for general infantry, a standardised, all-purpose weapon is enough. Let’s go with the latter, but add a sensor-package, which integrates with our bulky sights.

gun 6

Don’t forget that guns need to be carried around a lot. Let’s improve quality-of-life by adding carry-grips, pads and guards. Texture the grips, make it seem obvious where and how the operator should hold it.

gun 7

Guns need to be maintained, to be reliable. For all these parts we’ve added, think about how they should be disassembled. Add clear separators, clips, rails and so on, how each part can pop and slide off.

gun 8

Add the final dressing. Manufacturer’s markings, model numbers, [muzzle brake], power packs, rails. Think about the personality of the gun, and its history: perhaps its operator is a grizzled veteran, who’s added custom paint and unit markings, and the gun has scuffs and scratches on exposed areas. Maybe the gun itself is defective, has cracks or dents, and is patched together by bits of duct tape.

gun 9

And there it is, we’ve designed a fictional future-firearm, from basic principles, and added our own flair and personality. I hope you agree that this not only looks practical but cool too!

gun a gun b

Oct 2, 2018 - SDL_RenderCopyEx

Comments

SDL_RenderCopyEx is a function in SDL2 that allows you to rotate, scale and flip sprites. But how do you use it? I was wondering the same as I wanted to add bullet trails to C-Dogs SDL. The official documentation tells you what parameters to use but not how they will look. So I just tried it out myself:

sdl2-rendercopyex-demo

This is a simple demo project which uses SDL_RenderCopyEx to rotate, scale and flip a sprite. There’s also a center parameter which controls the center of rotation, which defaults to the center of the sprite you are rendering.

sdl2-rendercopyex-demo

Pretty simple, although you’ll probably want some boilerplate code like I did:

	int render(
		SDL_Renderer *renderer, SDL_Surface *s, SDL_Texture *t,
		int x, int y, double angle, double sx, double sy, SDL_RendererFlip flip)
	{
		SDL_Rect dst;
		int res;
		dst.x = x - (s->w * sx) / 2;
		dst.y = y - (s->h * sy) / 2;
		dst.w = (int)(s->w * sx);
		dst.h = (int)(s->h * sy);
		return SDL_RenderCopyEx(renderer, t, NULL, &dst, angle, NULL, flip);
	}

Source code here: https://github.com/cxong/sdl2-rendercopyex-demo/blob/master/main.c

Update

By using SDL_RenderCopyEx to rotate and stretch sprites, it can be used to create bullet trails, like this in C-Dogs SDL:

trails