Author [EN] [PL] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [ID] Topic: Old-School Enemy AI (won't make CV3 any easier)  (Read 4903 times)

0 Members and 1 Guest are viewing this topic.

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Old-School Enemy AI (won't make CV3 any easier)
« on: October 07, 2012, 02:22:01 PM »
+1
I decided to share some of the mechanics I find in CV3's enemies as I find them. Since I'm hacking the actual code for the enemies, I can tell you exactly how certain enemies are programmed to behave. This is an extension of my crows post. Note that a number preceded by a dollar sign is hexadecimal, so multiply the first number by 16 then add the second number to that (e.g., $23 = 35). Also when something is random, it's not really random -- a robot would be able to elicit the same results every time.

Crows/Ravens
In CV3, a crow will wait until Trevor is less than $80 pixels away (give or take) both horizontally and vertically, the crow will fly up with both horizontal and vertical acceleration of 1/20 pps, hover for a second, then choose one of four flight paths from one of two sets (based on proximity to Trevor) at random. It will attack Trevor in this way 8 times before flying straight off the screen horizontally.

Ghost/Specter
When flickering, a ghost will be invincible in its wisp form, although there may be a split second in which you can slay it before the invincibility mode toggles on. It will then move in Trevor's general direction, either up or down, for one second before reorienting itself.

Hunchback
In CV3 the hunchback will wait for one second as soon as it appears. It will then either hop toward Trevor with double Trevor's move speed or leap high into the air with the same horizontal speed as Trevor. It will only leap high if Trevor is within $50 pixels of the hunchback and Trevor is facing in the hunchback's direction, otherwise it will simply hop low. When Trevor gets hit, he automatically faces his attacker, which will cause the hunchback to leap if it hops into Trevor. After five leaps, the hunchback will hop away off the screen.

Bone-Tossing / Whipping Skeletons
The two skeletons that can jump will move toward Trevor unless he is less than $40 pixels away, in which case the skeletons will back off. Their movement is subjected to a friction of roughly 1/40 pps, but this is mostly for cosmetic purposes. After roughly one second the enemy will attack. This is the same for Sword Skeletons and Dhurons. Jumping skeletons differ in movement when encountering pits or walls. If a normal skeleton encounters any kind of obstacle at its feet (a wall in front of the skeleton's face won't affect it), it will reverse direction. A jumping skeleton will jump over a pit. If there is a block in front of the jumping skeleton's feet but not in front of its head, the skeleton will jump over that block. If there is a literal wall in front of the skeleton, it will reverse direction. Timers do NOT get reset when direction changes.

Living Armor
The boring suit of armor that just paces back and forth. Based on Trevor's proximity and the current step (see note about randomness), it will set a timer to one of four possible values. When the timer reaches zero, the armor will reverse direction.

Wing Demon
These guys are bitches. They're no different than a Medusa Head, except their vertical speeds change at set intervals. When created, a timer is set. When the timer zeroes, the vertical speed will be reversed and set to a different value, which increases the amplitude of its movement. As I said elsewhere, Wing Demons were never programmed to exist in horizontal stages -- if allowed to exist in a room longer than the time it takes to traverse a single screen's width, they will glitch out.

Medusa Head
The code is beautifully simple, which is why it's so funny that people hate them so much. A Medusa Head spawns at Trevor's y-coordinate (a Medusa Head's origin is 8 pixels below it) and that value is saved in the CPU. It then moves upward. Every step, the distance from the Medusa Head's starting point is used to augment the vertical speed, which creates a wave pattern. It's so simplistic and predictable.

Slime Ball
The slime ball is nearly identical to the hunchback, with two considerable differences. First off, it can hop on the ceiling. When it leaps up, it will look for a collision with the ceiling and bump its head, just like a hunchback, but when leaping it will go off the screen if no ceiling is encountered or else it will flip itself and stick to the ceiling. Slimes will also leap high at a closer proximity (16 pixels closer). Another significant difference is slimes do not slow down when leaping high into the air.  If a slime is less than $F8 with upward velocity (so 8 pixels off screen), it will respawn and drop down on Trevor.

Owl
Owls may or may not blink (which is really just the owl going invisible). After a couple seconds, the owl will appear. It then checks Trevor's proximity and based on that chooses from nine possible speeds. The closer Trevor is, the easier it will be to dodge because the owl will fly slower. It will swoop down then fly up a little and hover. After hovering for a second, it will check Trevor's proximity once again and choose from nine possible speeds. Again, the closer you are, the easier it will be to dodge. In most cases, Trevor can simply duck.

Headless Pirate / Dhuron
Something I never actually noticed in the game but apparently it's a factor in the Headless Pirates: They will avoid crumbling walkways and pits (good to know if you ever want to include fake floors in a fan mod). It's a pretty straight-forward enemy. Like the equipped skeletons, it will move toward Trevor then attack, or move away from Trevor then attack, depending on if it's less than $40 pixels away. The irony of the pit avoidance and crumbling floor avoidance is the Headless Pirate is actually scripted to fall if there's nothing under it.

Normal Skeleton / Blood Skeleton
These minions walk back and forth until a timer, which is always the same value, goes off. However, unlike enemies like Living Armors (below), the skeletons will continue moving toward Trevor when the timer resets if they are within a close enough proximity horizontally (vertical proximity is ignored). Like most enemies, they will reverse direction when a pit or wall is encountered.

Living Armor
This is just a fancy normal skeleton. A timer is set and the armor walks toward Trevor until the timer goes, at which point the armor turns around and the timer is set to one of four random values (based on the linear seed modified by Trevor's current x-coordinate). If a pit or wall is encountered it will turn around.

Whip Skeleton
This version of skeleton will keep moving toward Trevor until it's less than 64 pixels away, at which point it will attack then retreat for a second. There's not much to it and infrequency of attacks makes it a bit easier than the other armed skeletons.


I'll post more as I get to them. I'm slow.
« Last Edit: October 28, 2012, 11:03:07 PM by TheouAegis »
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Old-School Enemy AI (won't make CV3 any easier)
« Reply #1 on: October 28, 2012, 10:37:13 PM »
0
As an example, here is a diagram showing how hit boxes are calculated in CV3.



As you can see, the general function is simply along the lines of

abs(enemy.x - Trevor.x) < 14 && abs(enemy.y - Trevor.y) < 26

It's slightly more complex than that, though. The green box is the perceived hit box based on that formula, but it's really comprised of four parts.

The horizontal bounds are the sum of the skeleton's x-offset and Trevor's x-offset. Typically Trevor's offset is 8. As you can see in the chart below, not all enemies take Trevor's bounds into consideration the same way.

08 08 0A 08 10 10 06 0D 0C 18 10 06 0C 0C 0C 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 0C

For the skeleton in the diagram above, the skeleton's horizontal bounds are 6px from x and Trevor's are 8px from x for a total of 14px.

The vertical bounds are handled similarly but are based on y-16 instead of the y-offset. Trevor's bounds are typically 14, but not always; sometimes they're 4 or 8 or even 16. In this skeleton, the vertical bounds are 12px from y-16 and Trevor's are 14px.



Here you can see how the values translate into hit boxes as you would expect to see them in Game Maker or other UI's that contain such features. The red box is the skeleton's bounding box as defined by the figures on the right (yeah, I typoed -- it's supposed to be y-16, not y). The pink boxes are Trevor's bounding box as defined by the figures on the left (again, typoed). If we assume 8 is the standard deviation from x and 14 is the standard deviation from y-16, we can then extrapolate the bounding boxes for those enemies which use different bounds for Trevor by calculating the deviation from the standard and adding it to the enemy's. (Or at least we could in theory, as I haven't actually tested this yet since it's really damned tedious to match bounds to enemies.)

Note that CV3 does not use the same bounds for collisions with tiles. For example, Trevor's vertical bounds when starting a jump extend past his head, but once he's off the ground the vertical bounds are only waist-high. Enemies are always bounded waist-high for tile collisions.
« Last Edit: October 28, 2012, 11:00:18 PM by TheouAegis »
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Offline Phoenix7786

  • Legendary Hunter
  • ****
  • Posts: 518
  • Gender: Male
  • Neg on that, Chummer
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles.
    • Awards
  • Likes:
Re: Old-School Enemy AI (won't make CV3 any easier)
« Reply #2 on: October 28, 2012, 11:42:39 PM »
0
These are very fascinating. I'll make sure to forward this to any aspiring programmers I know.
12/1/12: Nominated for my 1st award! Thanks to all :D

Offline Inccubus

  • Wannabe Great Old One
  • Master Hunter
  • *****
  • Posts: 3265
  • Gender: Male
  • Warrior
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. SuperOld Dungeonite: Members who have been around since the oldOLD days. Permanent Resident: Seems to always be around to post/reply.
    • Awards
  • Favorite Game: Vampire Killer (MSX)
  • Likes:
Re: Old-School Enemy AI (won't make CV3 any easier)
« Reply #3 on: October 29, 2012, 01:23:49 AM »
0
Very enlightening as always.
"Stuff and things."

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Old-School Enemy AI (won't make CV3 any easier)
« Reply #4 on: November 16, 2012, 11:48:56 AM »
0

Bone Dragons spit fireballs that move a 1/2 step faster than normal fireballs.
Now you know.
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Tags: