00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

A.I help? 2006-08-06 15:11:34


Okay I'm making a platformer game, I have most of the code down, but I need help with some simple A.I...

So...there's an enemy, and what I want to happen is that when the main character gets close, he has 3 options, the enemy either walks closer, attacks, or blocks, and I want it to be random ...Can someone help me? (I have minimal knowledge of Arrays and Random, I checked the As:Main but it didn't help much...)

Response to A.I help? 2006-08-06 16:45:17


You could do something like:
(this is on the enemy object)

onClipEvent(enterFrame){
if(PlayerObject._x > EnemyObject._x-100){
//actions to make the enemy move left//
}
if(PlayerObject._x < EnemyObject._x+100){
//actions to make the enemy move right//
}

Where PlayerObject and EnemyObject are the instance names of the player and the enemy. You could replace the 100's with larger numbers to make the detection range bigger. As for randomness, you could change the 100's so that they are random numbers e.g random(100);. Understood? Hope it helps.


...

BBS Signature

Response to A.I help? 2006-08-06 16:56:40


http://i32.photobuck..7/jon0tan/hjhjjh.swf

move=arrow keys
jump= Up key
umm...hump=CTRL
umm..phallus=ALT

Hit the ball at the end of the level for 1000 extra points

this my game so far (without enemies) i can't seem to get the coins to work though, i'll troubleshoot.....
'

You're probably wondering why he's naked, and why he used a censored phallus as a weapon, or why u get points for humping a pole.................But that will all be explained in the story once the game is done (expect it in a month)

http://i32.photobuck..7/jon0tan/hjhjjh.swf

Response to A.I help? 2006-08-06 16:59:10


hehe, love it. obscene platformer.


...

BBS Signature

Response to A.I help? 2006-08-07 12:21:20


Thanks! It's still underconstruction but I'm working on it...To anyone else, feel free to comment on it, constructive crittisism is okay! Well, I got 2 get back to flash, working on enimies..

Response to A.I help? 2006-08-07 12:40:51


At 8/6/06 04:56 PM, Jon_0_tan wrote: http://i32.photobuck..7/jon0tan/hjhjjh.swf

http://i32.photobuck..7/jon0tan/hjhjjh.swf

LOL! I hit Alt by acident,try it its funny

Response to A.I help? 2006-08-07 12:56:06


At 8/6/06 03:11 PM, Jon_0_tan wrote: Okay I'm making a platformer game, I have most of the code down, but I need help with some simple A.I...

So...there's an enemy, and what I want to happen is that when the main character gets close, he has 3 options, the enemy either walks closer, attacks, or blocks, and I want it to be random ...Can someone help me? (I have minimal knowledge of Arrays and Random, I checked the As:Main but it didn't help much...)

My about to make up a code from my expirience, but I've never used it before so it will probably need some tweaking but here we go:

pu this code on the enemy:

onClipEvent(load){
op = new Array("attack","block", "walk");
onClipEvent(enterFrame){
if(_root.guy._x<this._x){
//assuming this enemy is normally facing right
this._xscale = -100;
}
else{
this._xscale = 100;
}
if(Math.abs(this._x - _root.guy._x)<=50 and transition == true){
this.gotoAndPlay(op[Math.floor(Math.random
()*op.length)];
transition = false;
}
}

Now within the enemy movie clip make sure you have your attacking frame, your moving frame, and your blocking frame all labelled appropriately and at the end of the [insert action here] animation put in this code:

_parent.transition = true;

That should do it, but remember I never tested this so no promises.

Response to A.I help? 2006-08-07 13:07:13


Thank you VERY MUCH! This will help me ALOT, I'll mod it to work for me! I'll definetly give you a place in the credits!

<HAPPY> HAPPY! </HAPPY>

Response to A.I help? 2006-08-07 15:23:25


awsome, now this is what I've done with the enemy code (modded from the original code provided by MLproductions)

onClipEvent (enterFrame) {
if (_root.guy._x<this._x) {
//assuming this enemy is normally facing right
this._xscale = 100;
} else {
this._xscale = -100;
}
if (Math.abs(this._x-_root.guy._x)<=50 and transition == true) {
this.gotoAndPlay(op[Math.floor((Math.rando
m()*op.length))]);
transition = false;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x+6;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x-6;
}
}

this is a particualrly simple question, but how would I get the enemy to move when he goes to the walk frame...?

Response to A.I help? 2006-08-07 16:02:10


At 8/7/06 03:23 PM, Jon_0_tan wrote: _x = _x-6;

by the way, you can shorten that to:
_x -= 6;

Doesnt make any difference to the game, its just quicker to write...


...

BBS Signature

Response to A.I help? 2006-08-07 16:19:17


umm...thanks..lol

Response to A.I help? 2006-08-07 18:21:04


how would I get the enemy to move when it goes to "walk" frame?