Mega's Competition Dev Log #3

Posted by Astryl on April 7, 2014, 11:26 a.m.

One week in and 23 days to go.

Most of my work has been on the engine, unsurprisingly, though I have taken the time to work on some art for the game.

My next challenge began this morning. It involves this:

These enemies are all static placeholders in the game; I have yet to add their AI. And on that topic…

Designing an AI system

With the original game, I was rushed. I'm rushed now too, but I just happen to have taken a hint from the last time that the copy-paste enemy code reuse in Exile was bad. It got to the point that, while I was working on the old improvements before I lost them, I just deleted all Enemy related code. That also happened to trim 5000 lines of code from the game.

In the original 'system', every type of enemy inherited some virtual methods from the Enemy class. And that's where the natural C++ code reuse ended.

One of the things I copy-pasted frequently was the billboard drawing code. For each enemy I had copied the same 100 line segment and pasted it in. Collision code? Same thing. Movement code? Same thing.

This time, I've been taking bits of code that I know I'm going to be reusing and adding them to the base class. The update method for my Fallen Knight enemy contains a single line:

drawBillboard(spr_walk, position);

Of course, it will contain quite a few more lines by the end of this, but already this is far better than the nightmare that was my 2012 Enemy class.

Anyway. AI. I'm using a simple state system, using an enum to store a few basic states:

AI_IDLE
AI_FIND
AI_ATTACK
AI_SHOOT
AI_FLEE

For each of these I'll create a method in each derived class to handle these states (Or ignore them and change state to something that class can handle).

Then, using the methods in the base class, I detect and change between states.

I'm envisioning something like this:

void EnemyFallenKnight::ai_idle() // Starting state
{
    if(Map::GetMap().isPlayerNear(this->pos) && 
       Map::GetMap().checkLOS(this->pos, Player::GetPlayer().pos))
    {
        // Wake up, we can see the player
        this->state = AI_FIND;
        this->clearPath();
    }
}

void EnemyFallenKnight::ai_find()
{
    // Find a path to player if possible
   if(path.empty()) 
   {
        path = findPath(this->pos, Player::GetPlayer()::pos);
   }
   else
   {
        // Move towards path.front(), then pop it and 
        // continue on to the next point, until we're one step away from the
        // player.
        if(nearnEnoughToPlayer)
        {
            this->state = AI_ATTACK; 
        }
   }
}

Some pseudocode, though I have a few of the methods implemented already.

Should have this done by tomorrow, if I can get a few hours of solid work in tonight.

On another front, I added in some better 2D editing to my editor. Box selection, which you can fill/set the height/flatten/fill with lights. Pretty easy, though reliant on keyboard shortcuts.

One last screenshot, then I'm back to planning.

Comments

death 10 years, 7 months ago

wait… so this back up plan would be an entirely different game on another engine right? lol that doesn't sound like a good back up since it would require starting from scratch :P

but the idea is solid, it could be fun but it depends on how it handles multiple enemies and transition from platforming controls into the fighting controls.

Astryl 10 years, 7 months ago

Well, it's a much easier game to make in a shorter space of time. It'll be 2D, and probably done with GM. I've made a few concept sprites for the player already:

Have to decide what palette I'm going to use; maybe a subset of the NES palette, or something of my own design. I'll figure it out.

Multiple enemies I intend to handle carefully; possibly one at a time with potential flanking (And a way to counter that by turning around quickly).

As for the transition, that's where I have to be careful. Karateka made the transitions very difficult. For an NES games, the animations of the fighter were pretty fluid, but for some unfathomable reason, the developers used acceleration and momentum for the running.

More often than not, you'll run across the level to meet the first opponent, but end up running right into his fist because you couldn't stop on time. I want transitions to be 'instant', and I intend to let the player run up to an enemy, drop into battle mode, pull off a few hits, then leap back again.

EDIT: Oh, and there's the possibility of a shield (I've been drawing a few frames where the player is holding one, and working out how that would work on paper).

death 10 years, 7 months ago

spriting shields on characters and having it clearly visible and not covering other important elements of the character is pretty tough, at least it is to me. Especially top down. i suppose it'll be easier in a side scroller.

what happens if a fight takes place on a small platform or on two platforms with each fighter being on a different one? if the arrow keys handle the sword, how will the player jump? :P

Astryl 10 years, 7 months ago

If you jump it'll 'snap' out of the fighting stance and you'll regain control. I want it to be easy to dodge.

And as an addition to that, I want to make sure that the levels are designed fairly, so there aren't any impossible to deal with situations.

death 10 years, 7 months ago

well you got things worked out pretty far :P seems like you've thought this out more than a mere back up plan lol.

Astryl 10 years, 7 months ago

I've had this idea on paper for at least a month, possibly more :P

I've been getting into the habit of writing my ideas down, and thinking them through whenever I have a chance.

death 10 years, 7 months ago

the sad truth about writing down ideas is that the majority of them will never ever be started, let alone finished :P. but its nice at least, makes us feel really creative when we peek inside that folder lol

Astryl 10 years, 7 months ago

Yeah, and it also gives me a pool of concepts or mechanics to work with if I'm ever out of ideas. :P

death 10 years, 7 months ago

Quote:
Yeah, and it also gives me a pool of concepts or mechanics to work with if I'm ever out of ideas. :P
heh why do we expect that to happen? it's like we are stocking up for some inevitable creativity destroying apocalypse that will leave us starving for new ideas :P some how, i doubt there will ever be a day when we are out of ideas, it's more like we have too many ideas to work with.