on Aug 21, 2013
A quick reminder that while I’m writing this in the present tense (easier for me than switching tenses) we’re actually looking at this game as it existed three weeks ago. My first code check-in is dated July 29, so we’re visiting the past right now. If things go the way they usually do, then this series will eventually catch up to the present, since coding tends to slow down as a project grows.
So I’ve got my world of random walls and I’ve got a little avatar I can fly through it. I guess next we should work on AI. But to work on AI we need some foes. Well, there’s no sense in adding foes if they can’t attack me, and I don’t want to debug both AI AND shooting mechanics at the same time, so I should add shooting first. Of course, shooting will require collision detection. And to add these things to the scene I need textures for it all so I can tell one thing from another.
I’ll be using one texture for all the foes and projectiles in the game. In old 8-bit games this was called a sprite sheet and it looked like this:
Basically, you’ve got a big ol’ tablecloth of little images, and the program cuts it up and uses it according to whatever scheme the programmer devises. In a strict sense, I don’t think you can call what I’m doing a “sprite sheet”, although to my non-existent art team the two things would be identical. Sprite sheets are for sprites – which (as I understand the word) are usually raw pixel transfers of the source image. I’m not using sprites, I’m using polygons that kinda look sprite-ish. But I’m calling it my sprite sheet anyway. You can’t stop me. I’ve got the source code.
(For the rest of these screenshots, the player avatar is just a random image from my sprite sheet. None of this is how it’s supposed to look. While I was doing this coding I was also talking little breaks and making sprites to see what sorts of things look good and what doesn’t. I messed with colors, shapes, and I messed with background colors of varying levels of saturation and intensity. The screenshots in the next few entries will therefore seem kind of schizophrenic. There’s no sense in my trying to document the art changes, even if I remembered them.)
This sprite-sheet business is a huge timesaver. In a normal 3D game, you can’t just stick all your high-resolution wall textures onto a single texture like this. Well, you can, but unless you’re doing something fancy it’s not worth the hassle. You don’t want all the textures for your entire level stuck on ONE texture, since you probably don’t need ALL of them at any given moment. You’ll just be gobbling up GPU memory for no good reason and giving your artists a bunch of hassle. (I’ll bet arranging 1024×1024 textures on a huge grid would be a nightmare in photoshop.)
But here I don’t need a lot of pixels. This saves me the usual hassle of keeping track of what texture is in use, switching textures when needed, and designing the program to switch textures as rarely as possible.
Making sprites out of triangle pairs is effortless. Projectiles are easy in 2D. Collision detection is simple.
Next up is shooting.
In 3D, translating the mouse pointer into the scene and figuring out what is being clicked on is an exercise in madness. You’ve got to project the 2d position into the 3D space, which takes some math and can go wrong in a dozen different ways. Are you projecting a line from the center of the screen, looking for collisions for a hitscan weapon? Or are you translating the mouse position into 3D space to figure out what bit of scenery was clicked on? Do you need the actual position in 3D space or just the target object? (Or worse, the clicked position on the target object. Have fun with that.) Have you taken into account field of view? Aspect ratio?
Ha ha! We’re doing 2D, which means that converting from screen coordinates to world space is basically the same as looking at a map and converting centimeters to kilometers. You don’t even need to comment the code, because it’s so embarrassingly simple.
I set it up so that I can point my mouse somewhere on-screen and my little avatar will shoot at (towards) the cursor, letting me aim with the mouse. The only reason this takes more than five minutes is because I mistakenly believe it isn’t working. As I fly around the map I see my shots aren’t intersecting with the mouse target thing. It takes me a minute to realize of course the shots aren’t hitting the target, you’re dragging the target with you as you fly.
Are we done with this foundational stuff? Can we write some AI now? Yes? Good.
(Two hours later.)
Sidenote: Wow! JPEG compression does not like these shades of purple. Kinda turned my screenshots into mud. I didn’t really notice until I was done. I’m not going to go back and re-encode all these shots as PNG just so you can see these horrible graphics in crystal clarity. You get the idea. Let’s just move on.
Okay, I have a system where bad guys operate according to a few rules:
- If you’re too close to the player, back away. (While shooting.)
- If you’re far away from the player, close in. (While shooting.)
- If you’re at a happy distance, circle around the player. (Oh yes more shooting.)
Different robots have different pre-set “ideal” range, and they alternate which way they want to circle you. For each state they have a list of priorities. If they want to back away and they can’t (because you’ve got them against the wall) then they will circle. If they’re trying to circle and they can’t, they flip their circle-direction and try again. In short, these are some stupid robots. This is stone-age AI here.
And yet, it actually feels really good. Like, they’re dumb, but they feel devious. They blast you, but they’re hard to hit because they’re circling. So you close in to make it easier to hit them, but they back away. And you can’t head straight at them without running nose-first into their projectiles. And meanwhile the other robots are still pelting you.
These guys are really annoying in a good way. The way to beat them is to out-maneuver them, which is exactly the game feel I’m going for.
I was going to write A*, but I honestly don’t know what I’d use it for. I suppose I could use it to help a bot out if it gets stuck in a cul-de-sac. I don’t know if that will be a big problem or not.
This is a very strange game right now. I can’t die. It’s not even tracking damage. If I kill a robot another one instantly appears. There’s no sound system yet. So it’s this silent ballet where I’m endlessly attacked by an army of implacable flux capacitors.
I know it looks like MS Paint: The Movie: The Videogame Adaptation, but it’s actually turning out really well from a gameplay perspective. I’ve got bots that zap you from different distances and others that rush at you. (I could use these for melee or suicide bomb attacks.) You’re often engaging multiple foes at multiple distances and the only way to stay alive is to keep moving, keep dodging.
The only problem now is that with so many identical projectiles flying around it’s hard to tell which way everything is going. I’ll find myself plowing into slow-moving projectiles not because I ran out of room, but because I misjudged which way they were going. This is one of the things I dislike about shmups.
I enjoy zig-zagging through projectiles. When I get hit because I didn’t think fast enough, that’s fine. But in a shmup you sometimes get that feeling where the whole screen looks like noise. All the bullets look the same and when you get hit it’s not because you moved wrong, it’s because you didn’t even notice the bullet. Sometimes you just take damage and you don’t even know what you did wrong. I understand that’s how shmups work, but that’s not the kind of game I want to make.
I try elongating bullets so they have trails:
That makes a huge difference. This visual change just made the game several times easier. I didn’t change bullet speed or projectile size. (Unless maybe bullets got slightly bigger.) But now you can judge the incoming angles and get a sense of who is shooting at you and where all the laser-bullets are going.
(That’s how lasers work, right? Gluons make the photons all sticky so they gather up on a big ball you can shoot at the enemy at speeds greater than a professional baseball pitch! These high-speed photons then unleash their energy on impact, which will either melt through the hull or burn through the hero’s shirt to expose his manly chest, depending on context. Science!)
I like where this is going so far. It’s ugly as hell, but it’s fun.