Showing posts with label AI. Show all posts
Showing posts with label AI. Show all posts

Tuesday, March 9, 2010

Happiness is a procedurally generated explosion


Arrow keys for movement and crouching, spacebar to jump. Use arrow keys while swinging to increase his spin. Hold down spacebar to make the jump last longer. Hit spacebar again when holding on to a wall to wall jump. A is for punch and D for kick. Press S to hold a grenade, the release S to throw it (be careful - hold it too much and you'll blow up!


Dreg goes Boom now!

Well, sort of - he throws grenades! To make it work, hold S start holding a grenade, then release S to throw it (I did it this way so that you can hold a grenade and wait until just before it explodes to throw it at an unsuspecting enemy who won't have time to run away). Or you could simply not release S then get blown up. As you wish.

This was a big ol' undertaking! It required a bit of work everywhere - I needed to make the grenades respond to the gravity shifts, and seeing as I'd been a bit stupid this meant fiddling around with things that I'd done badly, but hey, I'm used to that by now.

So yeah, it meant working on collision and physics for the grenade, on computer AI to make the thugs run away, on graphics for the explosions, on level set-up to have walls that can be blown away and on player input.

To give the player a decent amount of control over how Dreg throws grenades, I decided to have the arrow keys dictate a fair amount of how the grenade is thrown, as well as Dreg's movement at the time of the throw. Notice that if you throw the grenade while Dreg is crouched, he'll just drop it in front of him.

It also caused unexpected headaches, more on which later!

Anyway, I now have all the major items for Dreg to find within the game. By major item I mean those things that allow him to access new areas. At the beginning of the game, Dreg will have no objects and will only be able to wall jump once at a time. As he progresses he'll get these (probably in this order):

- triple wall jump
- whip (can latch on to poles and damage enemies - can be upgraded)
- double jump
- grenades (deadly against enemies, and smash through weak walls to reveal new areas)

If the list seems a little small, bare in mind this is only the beginning - I think I mentioned in an earlier post that I want to make a couple of "chapters" for Dreg. This is nice because it justifies all this work on the game engine (if more than one game will come of it), and it allows me to make the aims for the first game more realistic. In later games I can have additions like guns, grappling hooks, instant transportation devices etc.

Also, there'll be other items to get, such as better armor and offensive stuff (but focusing on unarmed combat). There'll also be stuff like the ability to have unlimited wall jump, but it won't be vital to complete the game.

It all feels so close now! we might see this game completed yet!

Anyway, if you're interested in the nitty-gritty of the grenade-a-thon of last week, read on!

< geekanisation >

So the reason I had to do a lot of fiddling is that I had foolishly focused on the Character class (Dreg and the thugs are extended from Character) when a lot of the functionality (such as collision detection and resolution) should have been in the parent class, MovingObject. Grenades, obviously, are moving objects, but not characters. So that was boring

But the really weird problem was the issue I had with having Dreg hold the grenade in his hand before throwing it. I thought this would be necessary to give the player control over when the grenade blows up after being thrown, but the issue was that I wanted the grenade visible before it got thrown.

I obviously didn't want to animate a run, jump, skid etc. cycle for Dreg with him holding a grenade, so I thought I could simply add an image of a grenade to Dreg's hand and be done with it.

The issue is that Dreg and his various components are scaled to different degrees, and the grenade would fiendishly change shape depending on what animation loop Dreg was in. I had a problem: I needed to have the grenade appear behind his hand, at the same position and rotation as the hand, but maintaining the grenade's original scale.

The solution involved a hell of a lot more involvement with transformation matrices than I would ever have liked to experience. That said, I feel super smart now.

Easiest of all, surprisingly enough, were the explosions. I had a clear idea of what I wanted, and it worked pretty quickly!

The most annoying part was making the map screen aware of walls being blasted away. It was all very hacky. At least it seems to work now!

< geekanisation />

Thursday, September 17, 2009

Combatalicious!


Arrow keys for movement and crouching, spacebar to jump. Use arrow keys while swinging to increase his spin. Hold down spacebar to make the jump last longer. Hit spacebar again when holding on to a wall to wall jump. A is punch and D is kick. Press A while running against an enemy to throw him. Click on the game to start interacting with it.

To avoid the thugs, your best friend is the roll - jump while crouching, and you'll avoid those nasty punches and kicks



Yes! I think I've done it!

So I've just gone ahead and added the one major missing ingredient - blocking. Blocking for Dreg was pretty easy to program - so long as you're not moving, or attacking, and their attack isn't one of the slow powerful ones, and you're facing the right direction, you'll automatically block the attack.

As for the thugs (let's call them 'Arry and Manphred), well, here's where I was really clever. Like, seriously clever. So clever I simply don't know how I could possible do my cleverness justice. Anybody reading this will think it's simply empty showing off, but no, seriously, this isn't anything like show-offy enough, believe me.

Anyway, the thing is that now the Thugs learn as they suffer - each time they get hit, they'll develop a certain resistance to that type of attack. So if you think you can just go ahead and spam the same move over and over again, you've go another thing (think? my brother insists the expression should be "you've got another think coming" which kinda makes sense) coming.

I like the little animation Dreg does when a throw gets blocked.

I'm going to go into further geeky detail, so look away ye laymen

< geektion >

Whenever a character does a fight move, at the moment of impact a collision object (which I, entirely unprofressional, have called "DeathBall") is created. Obviously DeathBall contains size and position information, but it also has a "type" variable (which is modified and check using bitwise operators).

There are six types - air (jump attacks), high, low, strong (the slow, powerful attacks), weak (fast attacks) and throw.

Accordingly, the thug has and array of six numbers - each number represents the Thugs resistance to an attack type. If the number is 100, he will always block, and if it is 0, he will certainly get hit. If the thug is attacking when he gets hit, this resistance is reduced somewhat.

Some attacks can be of more than one type - so the double-dragon spin kick thing is both "strong" and "air", and the little kick you do while crouching is both "low" and "weak". In this case, the Thugs resistance is the average of the resistance numbers he has for each type.

At all times, the total of all the resistance numbers is equal. I refer to this as the "resistance pool". In the case of the demo above, the thugs has a resistance pool of 200, so 1/3 of the 600 points available (six attack types).

Following me so far?

So when the thug is hit, we get some redistribution of points. 40 points will be removed from those resistance types that are not involved in the attack, and they are distributed among the resistance types that are. It makes sense, trust me.

In any case, the idea is that the player has to vary his or her attacks, hopefully making the game more challenging and fun!

</ geektion >

So yeah, enjoy!

Tuesday, September 15, 2009

AI refined


Arrow keys for movement and crouching, spacebar to jump. Use arrow keys while swinging to increase his spin. Hold down spacebar to make the jump last longer. Hit spacebar again when holding on to a wall to wall jump. A is punch and D is kick. Press A while running against an enemy to throw him. Click on the game to start interacting with it.

To avoid the thugs, your best friend is the roll - jump while crouching, and you'll avoid those nasty punches and kicks



Ok, after the beating you probably got in the last update, let's hope it's a little easier now, eh?

Well, to be honest, they're still as blood-thirsty as ever. But I've made a few changes that I think are cool.

After they try to attack you, they'll pause for a short while - this is your window to get behind them and perform the neck breaking move (move into them from behind and hit A). This also gives you time to run away if you find yourself getting pummeled.

Also, they'll try to knock you out of the air if you jump over them, so if you jump onto the pole at the beginning, for example, you'll quickly be brought back down.

You may have noticed a multitude of bugs in the last update involving characters weirdly floating upwards at inopportune moments. I think that's all been dealt with now (God I hope so...).

Some fun things happen - if they're close together and you jump over them, chances are that in trying to get you, they'll end up getting each other. Hohohoho.

Oh, and notice all of the new moves they have!

Also, the fun spin-round-his-neck move (run towards him and press A just before you reach him) will also get the other guy if he's behind. If you do the normal throw (press A or D while moving into him) and you throw him into the other one, they both fall down. Yes! Fun fun fun!

Anyway, my next step is to get blocking in place. But for now, enjoy!

Sunday, September 13, 2009

Generic thug fights back! And he's brought a friend.


Arrow keys for movement and crouching, spacebar to jump. Use arrow keys while swinging to increase his spin. Hold down spacebar to make the jump last longer. Hit spacebar again when holding on to a wall to wall jump. A is punch and D is kick. Press A while running against an enemy to throw him. Click on the game to start interacting with it


Hullo!

Last week I was rather lazy and neglected poor old Dreg, but these last three days have seen a flurry of programming activity, resulting in the rather hectic mess you see above this.

So as you may have noticed, the thug now has a mind of his own! Wheee! He'll no longer just passively take what you dish out - he'll punch back!

Ok, so this is still very early days. I was just getting started giving the thug some AI and having Dreg react to being hit, when I thought "let's see what happens when I add another bad guy". I enjoyed the result so much that I haven't done any more work since, hence my decision to update my blog!

There's still lots more to do:

- I want to give the thug several new moves, and the interaction between characters needs some more cleaning up. At the moment the two thugs can hit each other, which seems silly (but it does add to the fun, I think).

- I also want to give them the ability to block attacks, so that you can't just keep hitting the same buttons to defeat them.

- You can get hit while rolling or performing a throw, which I want to change.

- The pace is a little too fast. Maybe the thugs should stop when they're near you and sort of side step backwards and forwards... as it is, they feel a little bit too aggressive...

- I want thugs that you have thrown to knock down any other bad guys they hit.

In any case, I have to admit this isn't really worthy of a full update, but it's been so long I feel the need to let you know how things are coming along. Please point out any bugs you notice, of course...