Wednesday, June 17, 2009

Achievements/Awards - trivial?

I'm currently stuck on figuring out how to model the AI (implementing the behavior tree was only 50%^h^h^h20%^h^h10%? of the work - now I have to write and compose those behaviors into something sensible).

So I began working on something I had motivation for instead: some sort of achievement component (they can't actually be called achievements). I figured it would take a few hours at best, or maybe a day. That was 3 days ago. In total, I've probably spent about 15 hours on it. There's a lot to think about.

First, the UI:

  • The award notification that pops up/animates at the bottom of the screen
  • An awards screen that lets you see all your awards, and the ones you haven't received yet.
  • An awards summary on the player selection screen (so online players can see your awards)

Other than the standard tedious pixel-pushing, that's all pretty straightforward. I considered trying out one of the ready-made XNA achievement components found on the web. But the implementation was fairly minimal - just UI. Another one, "Goal Component", was more complete but lacked some features I wanted and didn't include source code (so if there were deal-breaking bugs, I was out of luck).




My main concern was making sure I don't block the UI thread. I don't have any background threads in my game at the moment other than some content preloading at startup. So I thought about implementing a task scheduler of some sort, until I found one made by jwatte on the XNA forums. It seemed solid (and so far so good).

I wanted the process to be as transparent as possible for the rest of my game. So here's how it works.

There is a class that describes all the awards, along with the icon that goes with them. This class also holds other persistent player data such as flags that - when combined together - may yield an award (these flags may be set across play sessions, so they need to be persisted). The class also contains the smarts for figuring out when particular flags turn into awards. I'm kind of breaking OOP principles here - the award class is doing double duty (I've lumped other persistent player data in here).

There is a DrawableGameComponent that shows the animated notifications. It's always around, so it also serves as the logic for responding to "new award" requests, and scheduling load/save tasks (IAwardService).

When a player signs in, the following happens:

  • A component is responsible for showing the StorageDevice selector for this player. It has a queue, since multiple players may get signed in at once (the device selector will be shown sequentially in this case). Having a StorageDevice connected is a precondition for doing anything awards-related.
  • The IAwardService monitors SignedInGamers until it sees a StorageDevice has been selected for one. At that point, it schedules an award LoadTask (to load persisted awards from disk)
  • At some point later, the LoadTask completes and communicates the information back to the main thread.
  • Up until this point, any "receive an award" requests have just been queued up. Before starting a SaveTask for them, we need to wait until we have completed our first LoadTask. This way the awards we know about at runtime can't stomp the awards saved on disk. They are merged the proper way.

This seems to work so far.




Next up are the other places in the UI where awards are shown. These are the two screenshots you see here. Originally I based the awards system on my PlayerProfile class. But then I realized this only exists in the context of a NetworkSession (which I use for local games too). But I want awards to be visible before you have entered the lobby. So I had to change everything to be based off of SignedInGamer (which makes much more sense).

Finally, I had to transfer award information to other network players. This was pretty straightforward - just an extra int in the "player info" I send around in the lobby.

I still need to do a little UI polish. And implement some of the remaining awards.

Thursday, June 11, 2009

Making the AI imperfect.

Once I got the basic "capture flag" AI working, I started trying to play against it. It was clearly way too perfect to even have a chance to beat. For example:

  1. It's aim was perfect, it rarely missed a shot
  2. It knew exactly when to stop shooting bullets due to overheating, so it was achieving the theoretical maximum fire power


The second point was the first one I tried to fine tune. I added a parameter on the Actor that is "ChanceOfCheckingForOverheat". Every time the AI fires a bullet, this gives us the possibility that it won't check for overheat (and thus may actually overheat and not be able to shoot for a while).

The second one was a little harder. I wanted to introduce a random offset to the angle to which the AI turned. However, my aiming behavior was constantly aiming towards the target on every update cycle. So I introduced a timer that made the AI re-aim only every once in a while (once a second). I think this more accurately models how a human aims.

So now it re-aims every second, and the Actor has a property that indicates how bad its aim is. So for more difficult AI opponents, I can give them better aim (I can also make them check for overheating more reliably).

Here is a video that demonstrates this a little bit. The gameplay is still not fun at all (which increases my worry that playing against the computer just won't be very fun). But at least the AI is less-than-perfect in an intentional way (there are still some path-finding issues that are problematic, so it's less-than-perfect in an unintentional way too).



Next I will start adding AI for the skills. This will require the notion of parallel behaviors, which I haven't yet implemented in the tree.

Monday, June 8, 2009

Behavior Trees

Over the past few weeks I've been digesting behavior trees - trying to learn all I can about them.

I finally decided I knew enough to start implementing my own. I'll go into more detail in future posts, but I'm happy with how things are coming along so far. Once I had the basic building blocks in place, it was pretty easy to cobble together a test behavior that does the following:

If the flag is available, go to it, pick it up, and bring it back home (and drop it). If someone else has the flag, try to kill them.

Once you've got the building blocks in place, you basically have a "language" through which you can build behavior. Kind of neat to see it coming together.

I quickly realized that assembling these trees in code was way to complicated though. After toying around with various options for UI, I settled on a small Winforms app in which I manually bind the UI to the behavior tree hierarchy. There is a little bit of tedious UI work to get this up and running, but I decided it was a more prudent option at this point than learning about WPF databinding.

The result is what you see in the linked photo (that screenshot is the behavior for the AI I described above). I'm able to add/remove/re-arrange the nodes, set parameters on them, and save this out to an XML file which can be deserialized by the game.

I haven't done this yet, but it should be straightforward to have the game "hot load" the AI as I make changes in the editor.

Now *all* I need to do is write the AI, and fix all the design issues I haven't forseen.

I need to think about/implement:
  • target selection
  • memory
  • behavior vtables to aid in the re-use of certain subtrees


Sunday, June 7, 2009

More game reviews

Just some more notes on what I liked or didn't like for some games that caught my eye.

Project Alpha
  • No music during the intro
  • Trial mode makes me choose a storage device even though you can't save games
  • I am confronted with a big screen of controls
  • The font is hard to read in places
  • Text appears on top of each other in places
  • The sound levels are very inconsistent
  • A few bugs (when I try to resume the game (with no saved game), things flash and I get the same error message back.

I looks like there may be some deep gameplay here, but the game is a bit confusing and doesn't feel very polished.

Spy Chameleon

  • Trial mode makes me choose a storage device
  • It is very bright and cheery
  • The art is basic - definitely "dev art", like my game.
  • Fairly clever gameplay mechanic
  • Introduces you gradually, which is nice

Overall I liked this simple game. For what it is, it seems fairly polished, though it isn't really the kind of game I would play.

Fittest

  • Made me choose a storage device
  • The difficulty ramps up nicely
  • Graphics are basic but good
  • The music is a little annoying

It lacks a little polish. The main menu, however, is fairly slick. This just makes the rest of the game feel under-polished.

Saturday, May 23, 2009

Trying out some more games

Half Brick Echoes

A very polished title. The basic arcade-style gameplay doesn't really appeal to me, but some things I liked:
  • very well done menu system
  • very artistic (I wish I had an artistic touch like that)
  • it explains things quickly and clearly, and gradually introduces more complex elements

Basically, it gets a lot of things right.

Hexement

Catchy box art and the screenshots looked nice, so I downloaded the trial. Notes:

  • Menus are basic and buggy, and don't conform to norms (e.g. B for back)
  • No instructions on what to do by pressing the default buttons.
  • I'm still not sure what to do
  • Music was nice and soothing... graphics are pretty good.

I get the feeling there is some interesting gameplay here, but there isn't much explanation of what's going on (perhaps part of the enjoyment is figuring it out? but that doesn't leave much upsell potential). There are a number of basic "gameplay rules" that are broken here.

A Fading Memory

Beautiful introduction. Nice music, very evocative art style. I like games that are art.

Gameplay: it is too easy to die and then I restart at the beginning of the level. I think the controls are a little weird, and don't behave like other platformers (when you center the stick you immediately stop moving if you're jumping... feels a little weird).

This may be a good game if you like twitchy precise platformers. But it kind of feels like Braid, and Braid is anything but a twitchy "must jump precisely the exact amount" platformer. The demanding precision here doesn't seem to mesh with the dark emotional feel of the game.

If it wasn't so difficult (I am impatient and grow frustrated when I keep dying and get no rewards), then I would probably buy this game. I'm curious how long it is, and what comes next.

A Wizard's Odyssey

Great music. Best I've heard in a community game.

The visuals are an interesting mix of beautiful and bland. The toon shaders are nice. The environment seems a little spartan a low poly. Looks like there is some ambient occlusion going on here? Looks fancy in some areas, but not in others. I thought there were no shadows at first, but I do seem them where light floods in from stained glass window. But only there (which is like 1% of the level).

This game seems interesting, but I don't know what I get by buying the full version (other than being able to play for more than 8 minutes). How long is the game... how many levels?

Again, the art doesn't seem to have a common theme, which is a bit unsettling.

Mithra - episode 1, chapter 1

This is a full-blown professional-looking game. Definitely the most graphically advanced game I've seen on XBLCG.

They aren't getting 60FPS, that's for sure. And there is a short (garbage collection?) pause every few seconds.

Though it was beautiful, it didn't seem too exciting to me.

Thursday, May 21, 2009

Seablast

Every one in a while I'm going to try to look at some of community games and see what I like and don't like. I saw positive reviews on Seablast, so I downloaded the trial.

http://marketplace.xbox.com/en-US/games/media/66acd000-77fe-1000-9115-d80258550141/

At first glance, it is frighteningly like Tank Negotiator!

For example:
  • Tank-in-a-maze: check (except it is subs in the sea, but same deal)
  • Menu system that is slightly 3d: check
  • Vortex: check (I freaked out when I saw this - it's my prize weapon!)
  • Nice particles: check (but - they are not "soft")

Over all the game is quite polished. These are some of the things I liked:

  • You can practise with the controls
  • Campaign that gets you into it smoothly
  • Quick to load
  • Visuals are polished

The things I don't like:

  • Low constrast selection on some of the menus
  • Things are a little too small (the subs/players, the text). I have this problem too, when I zoom out from the board (with lots of players)
  • No tips during gameplay (I kept forgetting the controls)

I was a little shocked that it seemed, in some ways, a lot like TN.

Some other thoughts:

  • There is a flow mechanic in some of the levels (water flowing, which pushes you). I was thinking of having a weapon/powerup like this too!
  • The terrain doesn't seem to be involved much in gameplay. This is the case with TN too. I wish I could think of ways to integrate it more (like you can with a shooter where you take cover, for instance)
  • Has the same unit movement as TN, which some people don't like (you aim straight ahead at all times)
  • 8 level shapes... about the same as TN.
  • Music is a bit cheesy.
  • Apparently no network multiplayer

There seem to be a lot less weapons/skills than in TN, and no upgrade path. The campaign seemed a little boring - I'm worried this will be the case with TN too. It's really meant as a multiplayer game.

There are several people on the credits (3 or 4). I'm just me!

Wednesday, May 20, 2009

Nav meshes


I'm finally getting back to what I need to do: AI.


A necessity of any AI is good pathfinding. I had a basic point-based pathfinding system working long ago, but didn't have proper steering algorithms (as proper as they could be for a point-based system). Overall it was not very convincing, despite it (usually) getting from point A to point B.


More recently, I investigated navigation meshes and decided I would like to try implementing them. The basic A* algorithm I have will still work here (they are just another graph after all), but I need to actually create these meshes somehow.


In the interest of saving time (and allowing for the possibility of users creating their own mazes), I investigated automatic generation of the meshes. I basically start with a rectangle, and subtract additional polygons from it (each polygon representing a wall I add). I used an algorithm for subtracting one polygon from another (not really trivial) and another for generating the "minimum decomposition" of an arbtrary polygon into a series of convex polygons (convex polygons are a necessity for navigation meshes). Some pretty heavy and boring math here, and I could never get it all to work.


What stopped me were floating point inaccuracies. When two convex polygons are adjacent and floating point precision comes into play, one of the polygons may no longer be technically convex. The algorithms I was using did not like that. After a week of trying to get things working, I (temporarily) gave up, decided it was not worth it.


I'm now back to creating nav meshes manually. As an aid, I auto-generate points based on the wall positions that will be useful for creating the polygons.


At the top of this post is an example of a completed nav mesh using the in game maze editor.
One benefit to creating them manually is that I get control over how they are positioned. I may want the individual polygons to be evenly distributed in terms of size/position if I end up using polygon-level conditions (e.g. an enemy is in this polygon, so increase the cost of moving through this polygon).