Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
October 22, 2019
arrowPress Releases







If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Wings and Thighs: Piecing Together Enemy Behavior in The Meating

by James Deighan on 08/29/19 11:02:00 am

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

Coding enemies is a lot like cooking. Answering the question of "How should this enemy behave?" is similar to answering "What should this sandwich taste like?" For both questions, the secret is in the ingredients.

Fried Thwomp

Chicken Idle

This is a chicken. It is a creature lovingly and internally referred to as a Thwomp, like the enemy of the same name from the beloved Super Mario Bros. It will probably seem edible to some players, and I must admit it has made me rather hungry sometimes.

Most of the time, it just hangs in the air, and it will stay there as long as we can control our hunger-pangs.

But sometimes, this happens.

Thwomp Smash

Oops, this can be dangerous. Let's see how these monsters work.

Let's start with the basics. We will make a list, which will consist of all possible actions of the chicken. Our chicken should be able to:

  • Wait for its victim in the air
  • Attack the victim
  • Rise to the starting position

We have several sprites that animate the chicken. Let's output these sprites as a sequence:

spr=oam_meta_spr(chickenX, chickenY, spr,

seqence_chicken_idle[frame]);

Now our chicken can hang in the air. Look at the first image again to see his delicious turkey jive.

Thwomp Smash!

Suppose our chicken has spotted prey. Now it needs to rush to the enemy, and try to squash it. Perhaps it will also stain you with fat in your game. It all depends on your imagination.

All we need to do is change the animation and increase the position of the chicken along the Y axis each frame. I think 4 pixels per frame will be ok, but you can experiment on your own. 

chickenY+=4.

But something has to stop the chicken. Otherwise, it will fly through the entire screen like an asteroid in a looping way, and this will not make any sense, so you have to add a condition that will limit attack. This may be the presence of the enemy or the floor under the chicken. 

Stopping it might look like this (I will use pseudocode):

if (chickenY < someObjectY)

     chickenY+=4;

Then we have to get the chicken back. We will raise it by 1 pixel for each frame.

if (chickenY > basicPositionY)

     --chickenY;

And now we will collect everything in one cycle:

while (gameLoop) {

    switch (chickenStatus) {

CHICKEN_IDLE:

        // print sprite
 
            spr=oam_meta_spr(chickenX, chickenY, spr,
            seqence_chicken_idle[frame]);
         
          // Do not forget about the condition sufficient to start the attack:
 
           if (playerX==chickenX)

                  chickenStatus=CHICKEN_FALL;

break;

// next state - attack
CHICKEN_FALL:
 
          spr=oam_meta_spr(chickenX, chickenY, spr,
          seqence_chicken_fall[frame]);
           
          // maybe there is some ground here
 
          if (isGround(chickenY))
 
          // and if so
 
          chickenStatus=CHICKEN_BACK;
         
         else
 
         chickenY+=4;
 
         break;
 
// and back over again:
 
CHICKEN_BACK: 

        spr=oam_meta_spr(chickenX, chickenY, spr,

        seqence_chicken_back[frame])

        // if Y = basic position Y
 
       if (chickenY==basicPosY)
                  
        // back it to idle mode
 
           chickenStatus=CHICKEN_IDLE;
              else
                       --chickenY;
  
             break;

}

}

What Else is in the Fridge?

Let's consider another enemy. It’s a ghost. Our character cannot destroy this ghost on his own, but he can use his own supernatural thermokinesis ability to light a candle. This will destroy the specter. 

Again, we need to provide states for this enemy - the ingredients of his behavior:

  • Ghost patrols the platform;
  • Ghost attacks the player if the distance between the player and the ghost is 4 cells or less;
  • Ghost dies if there is a lit candle within two cells.

Voracious Ghost

This same process can also be performed with bosses. Just describe how the boss should behave. It could be something like this:

  • Hunting - Boss patrols platforms at the same height as the player
  • Attack - Boss throws a hatchet at the player

Use telekinesis to throw the cleaver back!

 

 

Coding enemies and populating your game with dangerous, fun, and tasty creatures is possible if you skillfully use the state and parameters of objects. Try it yourself!

                                                         – – –

Want more tips straight from the retro pros? Welcome to our Discord!

Get mad meat on The Meating page now!


Related Jobs

University of Utah
University of Utah — Salt Lake City, Utah, United States
[10.21.19]

Assistant Professor (Lecturer)
HB Studios
HB Studios — Lunenburg/Halifax, Nova Scotia, Canada
[10.21.19]

Experienced Software Engineer
Bit Fry Game Studios, Inc.
Bit Fry Game Studios, Inc. — Portsmouth, New Hampshire, United States
[10.19.19]

Gameplay Engineer
Bit Fry Game Studios, Inc.
Bit Fry Game Studios, Inc. — Portsmouth, New Hampshire, United States
[10.19.19]

Game Network Engineer





Loading Comments

loader image