The Daily Click ::. Forums ::. Klik Coding Help ::. Enemy A.I.
 

Post Reply  Post Oekaki 
 

Posted By Message

eyeangle



Registered
  12/06/2003
Points
  1683
30th July, 2010 at 16:39:11 -

Has anyone designed something like this before, or can you guide me in the right direction towards a tutorial or similar board, or already made movement?
I'm trying to design this for my platform game.

Enemy

Walks left and right. He stops sometimes, but continues walking after a few seconds.

If you get within 250 pixels from him he shoots at you. He shoots at a rate of 2 bullets per second.

Height of Enemy = 60 pixels
Width of Enemy= 20 pixels

He should walk at a set speed, however when you are with in 250 pixels from him he should walk at 1.5x his usual speed. Walking/running animation can stay the same, but just increase the speed.

Unable to shoot you when you are directly above or below him.

Jumps randomly every few seconds and is able to die if he jumps into spikes.

 
theonecardgame.com

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
30th July, 2010 at 17:23:09 -

Give the enemy a variable called "direction" or something.

Put up two actives where you'd like the enemy to turn around at. When the enemy hits those, set the direction to 1 or -1 (respective of the direction you want him to go).
Obviously then, you have to tell the enemy to face according to it's direction variable.

For stopping, you need 3 values, a stop timer, a randomizer, previous direction and a refresh timer. The basic idea is that when the refresh timer hits zero, the stop randomizer hits a random number, and once it hits a specific number, the enemy sets its previous direction to it's current direction, its direction to 0 and the stop timer to a certain number plus a random certain number. Then once that reaches 0, set it's direction to the previous direction, and of course the refresh timer to a certain number plus a random number. Then just make sure that when the direction is 0, the enemy plays it's stop animation.

To have the enemy fire within 250 pixels, use the distance formula. I usually use the one within the advanced direction object for readability. (just put the advanced direction object in the game, then set a value to advanced direction object/distance formula/float and plug in the x and y for both your character and the enemy.) Then just say when player is within 250, then do your shoot event. Now, to stop from shooting when above and below, you could have the enemy shoot a detector, but if you're just worried about him being above and below, then just make your distance event also have When player Y is greaterthan or equal to enemy Y - whatever, and player Y is lowerthan or equal to enemy + whatever.

For jumps, you can use a detector just like in the left/right code, just for this specific one, he does his jump code, (whatever it might be).

I would recommend using the platform movement object for the characters if you aren't expirienced with doing custom movements. I believe assault andy has a really good tutorial on it somewhere, but it will save you alot of headaches and look good.

Hope this helps, if I need to elaborate on anything, please feel free to ask.

Also, if you check out my game, Halloween Candy(Do Over), I make use of the left, right stop concept I listed here.

Edited by HorrendousGames

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
30th July, 2010 at 19:44:08 -

Yeah a variable for the stop timer is important so you can set it to 3 (or whatever) and set a flag to "on". Then every second that enemy's flag in on you take 1 away from that stop timer variable #. When it's zero you can set the flag to "off" again and start him walking around some more.

Pixelthief has a great method for distance as he always stores the distance between an enemy and the hero inside an enemy's variable so he has it to work with. Then you can just compare those and when it's <= a certain # the hero's within range and the enemy can shoot or otherwise act. (I think I'm remembering this right, sorry if I'm not Pixelthief!)

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
30th July, 2010 at 20:02:29 -


Originally Posted by Del Duio
Yeah a variable for the stop timer is important so you can set it to 3 (or whatever) and set a flag to "on". Then every second that enemy's flag in on you take 1 away from that stop timer variable #. When it's zero you can set the flag to "off" again and start him walking around some more.

Pixelthief has a great method for distance as he always stores the distance between an enemy and the hero inside an enemy's variable so he has it to work with. Then you can just compare those and when it's <= a certain # the hero's within range and the enemy can shoot or otherwise act. (I think I'm remembering this right, sorry if I'm not Pixelthief!)



Yeah, that's basically how I do both methods as well, although I tend to shy away from flags. Flags are great, but unless you keep really good track of them, you could run into issues down the way if you accidentally reuse the same flags. Other than that, they're great, and there's lot of them to use.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160
   

Post Reply



 



Advertisement

Worth A Click