one forward, two back

I had some breakthrough moments. After many nights of staring at diagrams like this:

Right...but how much linear momentum is left over?

Right…but how much linear momentum is left over?

…I was finally able to create a realistic response to impulses at an arbitrary location.  I guess an engineering degree is useful for more than linear algebra.  Realizing that you are deriving the parallel axis theorem the hard way falls into that group.  Anyway!

SUCCESS!

Voilà!

As is obvious, I still have many missing features.  The collisions are not reliable or clean.  My collisions only respond to vertex collisions.  My edge-edge detection is terrible (faked by multiple vertex collisions).  It’s not apparent, but my collision detection is a spaghetti mess, and the collision resolution is shoehorned right into the same code.  My broadphase is nonexistent.

Bittersweet though it may be

Long story short…I need a big refactor.  I need to gut all my progress, and revise it to make it work properly.  I would love for it to smoothly handles collisions in more circumstances.  But I want to play around with what I’ve got! I want to see if I can get some fun gameplay going!  Quandry!

Truth be told, I’m already a little sick of implementing physics.  A. That’s not a good mental position for starting over.  B.  I want to implement more game, less engine.  C.  I have reconsidered using a physics library…and it might be appropriate.  D. I have enough of a working base to start doing things with it.

So I’m writing managed code, right?  C#, in all it’s OO-featureful glory?  I ought to be able to take my existing physics manager class, and use it for gameplay, and go back later and completely change it.  Right?  That’s how well-defined components and internal APIs work.

Terrifying.  But fuck it, let’s go for it.

So what else is going on

I have professional opportunity to hone my wordpress skills.  I believe I learn new skills best when I have a task to complete.  So I’ve come up with a few blog features that I hope to implement soon.  I added a new field to my posts to allow for longer titles, without screwing up the slugs or whatever.  It turns out that adding the field is trivial.  Popping it into the theme is useful, though.

My other idea is to create a place for me to park my non sequitur rants and stories within my posts.  I would like my posts to be on-topic, but I still want to write down random crap.  Hopefully I can work this out.

How-to Program 2D Physics

Like that title?  Google hits, here we come.  It’s not meant to be misleading, but it may not be what a person would want to find on www.google.com.  Nobody will learn how to program by reading this article.

No, I’m writing to help myself hash out the fundamental pieces of the physics I want to implement.  I’ve written before about the features I need.  It is my opinion that there is not a pre-made physics system which will provide those features.  Even if there was, I would miss out on that understanding that only comes from trying and failing.  For reference, here’s that short set of features:

Deformability
Not a soft-body physics system, but rather rigid bodies that may be modified by infrequent events.  Rigid body mechanics most of the time, but objects that react with more variety than the AngryBirds™ puff of smoke.
Platforming
Mario, Braid-guy, and (maybe most dramatically) Sonic do not feature simple 2D physics.  Rather, they have both less and more.  Their motions are custom, their environments mostly static.  They do this for good control feel, for character actions other than standing and bumping into walls.  I want to do all that AND have realistically moving environments.

Should be easy, right?  HAHAHAHAHAhahahell no.  But I’m going to do it anyway.

Object definition

All my physics objects will be instantiated with a simple list of vertices, with position relative to their object’s center of motion.  For soon-to-be-explained reasons, I’ll store those as a struct for both position and texture coordinate.  To use those structures for both physics and drawing, I’ll keep separate collections of indexes for drawing and for convex hulls.  This will avoid the need for data duplication, while still allowing efficient batching of draws and collision interactions.  Here’s a diagram:

Vertex data storage visual aid.

Indexes into vertex buffer data, allowing both drawing and collision detection

Quads and Collisions, Merged Vertices

When my physics objects change their shapes, I obviously want that to reflect visually and in their physics.  To draw the deformation, I need the same motion of vertices as required in the colliding shapes.  If each texture coordinate was stored separately from the vertex, I would need to somehow align those data when I made any change.  Surely any system that did that would have a bigger memory and cycle consumption that simply storing the coordinates in the same struct as the vertex.

Also, storing multiple indices allows a couple storage optimizations.  All the data is in one place, but if either operation does not require a given set of data, it can simply be skipped in the index collection.  For example, although I will need 3 coordinates per triangle, I will not have to store any duplicates.  There will be multiple references to a vertex instead (standard indexing benefit there). But, the collisions also get the benefit.  They can index the vertices they need, arranged as the edges between them, and ignore internal vertices that don’t matter to collisions.  AND! I can store a convex hull and multiple concave areas, all using the same data.

Where in the world

Each object has these vertices that change, but they’re all in local space.  For converting to world coordinates, I’ll need a transformer.  I intend to define my own 3×3 Matrix (I can’t easily use XNA’s 4×4 system).  That gives rotation and translation in convenient operation, which can be updated independently of the vertex data itself.  Perfect.

It can be applied to each vertex prior to drawing, giving O(n) for that.  Worse for colliding, but I have a plan for dealing with that.

Half-space magic collisions

I don’t want to do 6 multiplications and 4 additions for each reference to a vertex (not counting what I actually do with it), per collision test.  Instead, vertices will reside in their local coordinates, and the edges get the transform.  Specifically, I’ll keep a set of slabs (halfspace pairs) for an object being checked.  Each slab needs a single direction vector and two distances.  The directions are converted to the local vertex coordinates, then both object’s translations are added.  These values need only be calculated once per pair of objects, rather than once per vertex.

After that, It’s all dot products with early exit.  I believe this will provide enough efficiency for me use a very crude broad phase, such as bounding circles per object.

Then what?

Eventually, I’ll need to do something with those collision tests.  Impulse, or some sort of force collection…something.  I’ll have a simple, single location to apply those forces, at least.

I’m going to get to work on drawing the quads first.

Berating != encouraging

Today’s topic is about productivity.  Again.  It’s a topic I will return to often, as this blog is, remains, probably forever will be, about how to make myself a game maker.  I hope to cross a boundary where it will become about dev itself, but I have no idea when that will happen.  So today I’ll write about the part of that attempt where I try to make headway.

We should totally start a game studio!

I tried to convince one of my cohorts that we should work together.  Being accountable to each other, I argued, would motivate both of us.  (He is arguably more engaged in indie dev than I am, but also somehow less active in it.  I thought I was the paragon of contradiction on these two topics, but I think he beats me.)  He declined, for perfectly legitimate, non-laziness reasons.  So I later proposed to him my idea that I would be creating my own physics.  He argued that such a thing was ludicrous, when boxed solutions are available.  Our argument is not unique, and he caused me to investigate available solutions more thoroughly.  My opinion didn’t change.

All that led to an idea.  I would make a website for the two of us (he pays his bills with web projects, too).  Every day, log in, and rate yourself for the previous day.  Scale of 100% to 1%.  The rating is our own satisfaction with our productivity.  That gets logged, and I push the data into a google chart.  You can see how well you are doing.  Or how poorly.  You may provide an excuse for description of your day’s data point.  When you suck, you see it.

As it turns out, that was not helpful at all.  I stopped using this website after about three days.  I hadn’t accomplished anything, I didn’t want a formal record of it.  Somehow I thought that if my chastisement came from myself, it would be more tolerable.  NOPE!  Turns out, hating yourself for being unproductive is way worse than someone else telling you about it.  But I didn’t feel particularly bad anyway.  All I saw was that it wasn’t making me do anything differently.  Nothing improved.  It was purely negative reinforcement, and I have an almost pathologically bad reaction to that.

Today, I had a new idea.

Often times, I sit down at my computer, fire up Visual Studio, and possibly run my project once.  I gradually recall the particulars of the incompleteness I left it.  I start staring at a few of the classes I had written, and ponder where I could write some more code.  I realize I should pick a feature, and then go about implementing it.  I ponder a little more.  I look at my (tragically) simple physics flowchart.  I realize it doesn’t equate to code at all, so I look at classes some more.  Eventually, I’ve got netflix or youtube or gamedev.se open.  I make zero headway.

Lately at work I’ve been griping about terrible workflow.  I am a total hypocrite.  The workflow I make for myself is worse than what other people impose on me.  My mind wanders a lot; I know this about myself.  Find work, do work, is a recipe for me to slack off.  But I do it to myself most nights that I sit down to work.

I have finished one project, that silly rubik’s cube app for the even sillier platform of the windows phone.  The launch date for that platform was mere weeks away, and I wanted to make something for it.  I considered making something from scratch, but a good friend advised otherwise.  Because of that, and one simple technique, I was able to rapidly produce a game.

  1. Inventory what I had already completed.
  2. Make a list of things I had yet to complete.

1. What have you already finished.  At first glance, nothing.  But my friend’s advice was “take something you’ve already got, and make it work for the phone.”  Holy shit.  Brilliant.  I had been making the rubik’s code for the 360 indie games (a laughable idea).  But it was absolutely perfect for a phone app.  All those features I want to implement but never finished…those just got the chopping block.  I needed a manipulable cube.  Done.

2.  What did I need to get from point A to point B.  From a lot of working code to a feature-complete phone app.  The list was short.  I could do a few of them every day.  I didn’t think of everything at once, but that didn’t matter.  It was quick and dirty time.  Add saves.  Add a simple modal info window.  Add a button for solving.  Implement gesture control (turned out to be simpler than trying to use a controller).  There it was, written in front of me.  A list.  The magic bullet.  Itemize it.

Completing objectives

I will not be making a list for my current project.  At least not a complete one; I couldn’t possibly fathom it yet.  But similar: I will make an objective for each night that I have available to me.  By the time I sit down at my computer, I will know what I am going to work on.  Perhaps it can be two things, and I can work on either of them.  Eventually I’ll have a list.  It works for Cliffski.  It works for Tommy Refenes.  I wroked for me.  It will again.

I Got Gamified

Hey folks, very little game making progress this week.  But I made lots of progress on playing a game that was made out of a website!  You contribute to community of helpful information, and then you get points!  It’s like every other game where you shoot hordes of zombies in the head, except instead its hordes of people asking each other how to make games, and you shoot them full of answers.  Anyway, I managed to grind my way up to 4 digits worth of those points.  Voila!

profile for Seth Battin at Game Development Stack Exchange, Q&A for professional and independent game developers

Also, stack exchange is more gratifying than killing zombies, because people actually benefit from your posts.  And only helpful posts get points.  And helping others is fun.

I don’t want to imply that I have made no progress on my game. I have attempted to implement 2D physics in a quick and dirty way, and I’ve realized that I require a custom 2D system (XNA’s SpriteBatch won’t cut it). I also got into a good argument with a coworker about whether or not to roll my own 2D physics. I’m not sure I convinced him. But I have still convinced myself, reaffirming that I need non-convex and deform-able shapes. I’m not going to get that in a free library.

Except maybe Havok’s new free framework

Distraction of the Week

The latest thing that has kept me from the game dev is this gem:  http://nodewar.com/.  It’s a programming game in which you design the AI for a small swarm of melee spaceship triangles.  The game features realistic-ish physics and n-body gravitation.  There are three moons ready to kill you on contact, and the legal field of play is a constantly shrinking circle.

Nodewar exists entirely within the browser, including a pretty good javascript editor.  You can also write in coffeescript, if you are one of those Ruby weirdos.  You can submit your AI to a public ladder.  Whoever is at the top of that ladder at the end of month wins 10 bitcoins.  (Or they might give you $2000 instead, because bitcoins are so ridiculously unstable.)

Programming games have a special place in my heart, because my only juvenile programming experience was playing Robot Battle.  This one grabbed me too, but I’m not sure I’ll stick with it.  Still, I’m having fun with this alpha/contest.  My AI based on simple orbit-keeping looks somewhat impressive, although it has no mode where it actually attempts to kill anything.

But tonight, I’m working on my own physics engine.  Here’s what it needs:

  1. Concave shapes
  2. Platformer physics compatibility
  3. Destroyable objects

If you have some familiarity with physics libraries, you may note that these features are present neither in Box2D nor any of its myriad ports.  Hence the decision to make my own physics system.  Sure, creating a physics library is a giant undertaking, but I’ve got a few thing going for me in my attempt to create it.  The first is a reasonably good physics education, having gradated from this school (it helps with the “space” battle programming games, too).  The 2nd is that I don’t have to design some massive physics simulation, but merely a small feature set.  I get the features I want the way that I want, without having to learn a foreign API.  Good all-around.

Too much writing; must make progress!

The Passion and the Prototype

Today’s post has nothing to do with Easter or Mel Gibson.  That may have been obvious from the prototype alliteration.  No, no, this post is about conflicting advice from noted independent game developers.  Looking at these adages now, it seems obvious to me that they oppose each other.  But I only recently had this notion, after absorbing a large quantity of video interviews.  So I’d like to express my…revelation?  Inspiration?  Stupid opinion; that’s what I was going for.

Three pieces of advice:

  1. Make lots of games.
  2. Make lots of prototypes instead of making games.
  3. Love your games; imbue them with quality using that love.

Numbers one and two directly oppose each other.  And number three seems to oppose both of the other two.  Let’s get on with a little more detail.

If you want to become an indie game developer, make lots of games.

Everyone who has ever spoken publicly about indie development has said this.  It’s plainly true.  The barriers to learning to create games are virtually nonexistent, except in the minds of people who don’t do it.  Anyone who owns a computer can find a free, inexhaustible quantity of starter resources and mixed-quality advice.  So the only reason that a person can’t make games is that they prefer to assume they will fail at something, rather than actually try and have a hope of not failing.

BUT! I don’t want to say that “just not getting started” is an unfathomable failure.  I suffer from it.  I can think of all kinds of terrible excuses for not making games, such as “I need to sleep to not get fired from my job”, or “I want my children to recognize me and not shy away from the minuscule gestures of affection I give them”.  People who have already overcome the problem and actively make their living as developers understand it.  Anyone who “just doesn’t get around to” anything understands it.  Sometimes, humans are lazy and don’t accomplish things, in spite of having all required opportunity and skill.

There’s another facet to this advice, though.  Edmund McMillen always notes that before making very high quality games, he made a plethora of awful, awful games.  He refers to it as a learning exercise.  Making games is the kind of skill you can only gain by doing it.  Coding works the same way, although the ability to code does not constitute the ability to make a good game.  It’s more similar to writing.  Read lots of books, practice writing (get an editor, because their job is to make you write better), show your writing to lots of people and get lots of feedback so that you can improve.  In exactly the same way, making lots of games is a must for an indie developer wannabe.

Who disagrees?  Oh, nobody you know, just some guy called Jonathan Blow.  He doesn’t really disagree that people learning to make games need to make a lot of games.  As a matter of fact, he is on record as being in the group of “Everybody” who believes in the first piece of advice.  But Mr. Blow is no game development learner.  An industry veteran, columnist, consultant and lecturer, he doesn’t need to figure out how to break into game development.  Instead, he has advice for how to make games that don’t suck: don’t make them.

Instead of making game, make prototypes.

Prototypes show you how a game works without the time investment of a full game.  In his paraphrased words, “you only have a limited amount of time on the Earth, so you want to choose carefully which projects you devote years to.”  Sure.  Make game-ish things, don’t worry about creating a complete package, wait for a great idea to fall out of your experiments.

But how many years should be devoted to learning to make games?  How much time should you “waste” in transitioning from a person who never makes a whole game, to a person who actually completes a game?  There must be some transition from making lots of crappy games to making only excellent games that you choose.  Maybe that transition is completely smooth, like any artist growing into their prime.  Either way, both tactics are at odds with the third piece of advice.

Pour your whole soul into your game.

Jonathan Blow certainly believes this.  He takes “games-as-art” to an almost elitist level.  His idea of a good game is something that portrays an abstract emotion and forces a player to feel something while playing.  He’s not wrong, but he exists somewhat outside the common purview of game players.  That’s his prerogative, as he certainly is a connoisseur of game development.

But he’s also not alone.  McMillen, that outspoken advocate of making a big stinking pile of games, also discusses an obsession with making his game perfect.  Designing with the videogame version of literary symbolism in mind.  Making a character that is based on his childhood.  Everyday shooter’s Jonathan Mak thinks that every facet of indie development is secondary to making something that is meaningful to its creator.  Originality, good features, artistic quality can all slide, as long as you love your game.  If it is well received, fine.  But the ART is what matters.

To summarize this 3-way tug of war:

  1. Make a whole lot of crappy games as fast as you can.  
  2. Only make the really good games, so that you don’t waste time making crappy games.  Throw away the crappy ones.
  3. Invest your very soul into every game you make, even if they are crappy.

STFU, you know-nothing hack!

Indeed!  I have no authority to criticize any of these folks or their methodologies or advice.  But I have a strong interest in overcoming my lack of experience and making a great game.  So what can this set of advice do for me?

I’ve been experimenting with various projects on this blog.  That javascript maze, the text adventure, some XNA bits and pieces…but I haven’t really thought of those as prototypes.  I’ve thought of them as reasonably scoped projects, so that I could build up my pile of crappy games.  But in retrospect, making a pile of games purely for the sake of making a pile defeats the purpose.  I’m not learning to make games, I’m learning to make throwaway items.

So if I called my work thusfar prototypes, would that make it better?  Kind of!  I realized my maze idea was not fun before I invested a lot of heartbreak into difficult ancillary features, so that was good.  I realized that making a text adventure game in pure C with no global variables or memory allocation is euthanasibly stupid.  I realized that Unity’s physics is no magic bullet.

But am I any closer to having a real game out there?  No.

So here’s what I intend to do about that.  I think that what my games have been lacking is not initiative or technical chops or willingness to experiment.  I’ve been missing the love.  I want to work on a game that I love.  I want to pull a Phil Fish and bite off waaaay more game than I can chew.  On the one hand, this will limit my options, and I certainly love changing projects. But I want more than anything to finish a formal project.  If I’m going to get there, I need to love my idea.

I haven’t loved anything that I’ve worked on lately.  I will endeavor to fix that.

 

Antiproductivity

I’ve spent the last three nights not doing any development.  There have been about 12 hours (thanks for the tally, Steam) dedicated to playing and completing Antichamber. It’s a great game, I strongly recommend.  I still can’t decide whether I actually enjoyed it.  It seemed to me that too many of the puzzles weren’t based on reasoning, but instead required trial and error, or continual restarts to check the map to see what random teleport actually happened.  It reminded me of a summer camp card game where only the dealer knew the rules and talking wasn’t allowed.

Again, great game, a very good buy and highly enjoyable.  A lot of the puzzles were based on reasoning, and even though I just called those teleports random, they were actually completely reliable and predictable (and bizarre and infuriating).  I may yet attempt the speed run which is implied by the 90 minute countdown timer.  Of course, that would mean playing through it 8 times faster.

And no matter what, I am overdue for game making.  Today I got to see a friend’s project videos, and I hope their project goes to completion and a warm reception by the public.  Seeing other folk’s progress always inspires me to make some of my own.

Experience Points

This title popped into my head.  I am so fucking proud of it as a category, as a thing, as a pun…I can’t even describe my mirth.  They’re points…that I make…regarding experiences…about making gamesWHICH MAY OCCASIONALLY FEATURE EXPERIENCEMEASURED IN POINTS OMAFOMFMAOSDMFFFFFDG../…..

That’s for staying with me through that.  Here’s are today’s EXPERIENCE POINTS (you better believe this is going to be a recurring thing):

  1. A text adventure game is an adventure game, and adventure games are not easy to write.  It turns out, eschewing the GUI does not diminish the difficulty of making a game.
  2. Adventure games are really, really hard.  Inventories, location-determined actions, world states, player conditions, equipment, using tools in the environment…jeebus.
  3. I had no concept of what was hard about making an adventure game until I tried it.  Obviously there is a general lesson to be learned there.  And it further evidences the advice to green game devs like myself: the best way to learn to make games is to make games.

Extra point: C’s nature is bad enough, but the limitations imposed in my C course are crushingly difficult.  They are for my education…fine, but they’re killing my game.  No, not really.  My complete disregard for my own advice is what is killing my game.

Regardless, I am very glad to have tried to make an adventure.  I have a grand plan for a better adventure, and I would like it to be architected by a non-idiot (which will hopefully be me). And even better than the learning experience: I have a text adventure game loop, enough data structure to know where my player is and what they are doing, and the beginning of an input parser.  I’m already proud of it, and I have a good deal left to work on.  I am having fun.

The Ideal Game

I just finished authoring my last post, but I was assaulted by considerations of what makes up a perfect game.  That perfection is something that I’m thinking about in the abstract sense.  A game like Chess or Go or…Poker, where the game is a collection of rules, and story and theme and content are nonexistent.

So here’s what I think.  That ideal game should

  1. A learning curve that never levels off.  A player should always be able to get better at the game.  There should never be a point where a player is “the best”.
  2. There shouldn’t be only a single way to be the best.  Does that mean multiple victory conditions, or simply that different strategies are viable?  I don’t know.
  3. Players shouldn’t be limited based on some physical quality in order to compete at the highest level.  APM should not be a factor.  The game should essentially be playable by mail.  (Diplomacy did it, right?)
  4. Gameplay that requires feeling.  Chess is now a computer’s game.  That’s sad, but it was inevitable.  Go will have a lot more longevity against being “solved”, by shear magnitude of it’s mathematical complexity.  The ideal game is closer to go, where human players compete without attempting to solve, and computers can’t compete because they always try to.
  5. A game where metagame knowledge can be a liability.  A poker pro can be defeated by a drunk if that pro does not realize their opponent is drunk.  If the pro assumed their opponent is a skilled amateur, the pro will play wrongly to defeat that opponent and lose.

I don’t know what made me want to write this, and I feel like I haven’t conveyed it properly.  Oh well.

Complexion Inflection

Having a title that rhymed was so important to me that I chose it instead of one that made sense.  The alternative would have been “A complexity decision, and an inflection point therein”  Or maybe, “Complexity inflection point”.

What the shit is that supposed to mean?  It’s mostly about my text adventure project.  It’s also about how to architect a game.

I started writing my plan for this text adventure, and it went alright.  But I ended up writing more about the story of the game than I did about the planning.  So that was something of a discipline failure on my part.  Regardless, I hashed out everything that I thought the story required.  That may have been a failure of my original purpose, but it was a great thing to do for an adventure game, IMO.  I intend to make it a mandatory part of my process of conceptualizing.  The part of game development that appeals to me most of all is to tell a story, so surely I should tell a story early in the process, right?  End digression…

What happened was that I had thought I had conceived of the whole story, but I didn’t notice that I had covered almost none of the technical requirements. As a result, I felt I had deduced that a complex system of room nodes, and inventory management, and content importing into dynamic data structures, and implementing those structures in the first place, in C for christsakes…I felt that all that WAS NOT required.  In other words, I felt the game was not complex enough to warrant doing a bunch of infrastructure work. It would be perfectly acceptable to “cheat”, and avoid proper code for this one special case. (Oh God, how many terrible abominations of code have begun that way?) I could honestly say that that decision was good, because it got me working on the game instead of pondering the technical difficulties.  But I now I understand why that my determination was completely wrong.

Even though my game will be short and sweet, the details of how to make even a tiny number of rooms and items and actions…are daunting. The other falling shoe about my decision is the alternative to all those structures. I have already begun to write mountains of if blocks and switch statements and hard-coded arrays…the stuff of maintenance nightmares. I reached an inflection point in the difficulty of making the game, where taking short cuts could no longer be justified.  I completely underestimated the complexity of what I was about to do, ans I should have taken the time to build up the structures from the start.  I am going to need them to avoid an uncompletable garbage heap of code.

This realization has made me consider a more general case about doing work the proper way versus doing it the fast way. Complexity is always underestimated, on every project. This is true at my office, and it’s true of every game project (as far as I have heard tell). But my reasoning for going fast was based on an estimate of complexity. So if that estimate is always wrong…cheating is always wrong. There will never be a project where the shortcut should be taken.  Maybe. I don’t know. Just pondering some philosophy of coding.

No matter what the right answer is, this project will be a boon to my skill as a developer. How to stop marching headlong into a technical quagmire, and instead march (for a longer time) to the right destination. The ability to make that decision will serve me well.

So…I’ll post some C source code eventually.  I’m loosely planning a way to make a distribution of the compiled game.  I’m even more loosely considering how to make a website interact with a C binary that uses the standard input…but holy shit that sounds like a hellish ordeal now that I’ve written it down.  I will continue to ponder my options.