Ai, like pac-man

Game Editor comments and discussion.

Ai, like pac-man

Postby Caaz Games » Wed Jul 25, 2007 4:38 pm

I need an AI code like pac-mans enemy's, like the character needs to move throughout the maze randomly. and there is four different animations faceing North(CopN), East(CopE), South(CopS), West(CopW). But i dont want the cops to move strait towards the Player, i just want them to randomly move around. if you need to see the maze i can post it. i didn't use a path be cuase they move to fast.
You are welcome to join my forum. 4 active members lol but it's a cool place. active... much talking :D it's fun!
http://caaz.freeforums.org/
User avatar
Caaz Games
 
Posts: 729
Joined: Wed Feb 14, 2007 9:09 am
Location: California....knows how to party!
Score: 25 Give a positive score

Postby Sgt. Sparky » Wed Jul 25, 2007 4:56 pm

I will make a Demo later. :D
(I must go now. :( )
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Caaz Games » Wed Jul 25, 2007 4:57 pm

ok
You are welcome to join my forum. 4 active members lol but it's a cool place. active... much talking :D it's fun!
http://caaz.freeforums.org/
User avatar
Caaz Games
 
Posts: 729
Joined: Wed Feb 14, 2007 9:09 am
Location: California....knows how to party!
Score: 25 Give a positive score

Postby Fuzzy » Wed Jul 25, 2007 9:28 pm

use a 2D array, with each element of the array saying which directions are open to be moved into. Since there are only four, it will be easy.
Code: Select all
 // place in global code
#define NORTH 1
#define SOUTH 2
#define EAST 4
#define WEST 8


See how i doubled each time? that allows no conflict and will let us pic from east and south, for example.

So maybe you have a square where you can go north or south.
Code: Select all
if(CopMap[cop.x,cop.y] == NORTH+SOUTH) // NORTH+SOUTH actually equals 3
{
    do stuff here
}


So the possible moves are...

NORTH+SOUTH+EAST+WEST == 15
SOUTH+EAST+WEST == 14
NORTH+WEST+EAST == 13
WEST+EAST == 12
NORTH+SOUTH+WEST == 11
SOUTH+WEST = 10
NORTH+WEST == 9
WEST == 8
NORTH+SOUTH+EAST == 7
SOUTH+EAST == 6
NORTH+EAST == 5
EAST == 4
NORTH+SOUTH == 3
SOUTH == 2
NORTH == 1

and technically, no move(0), which should be impossible in your game. With 15 combinations, each is represented by a number in an array, and no combination of possible moves matches any others.

From there, pick a random number from 1 to 4, and use that to decide to head NSEW, if its possible from that square. Otherwise, just pick another number.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Caaz Games » Wed Jul 25, 2007 9:47 pm

So,,, i need boxes in every place on the maze like this? Image except i need them all separate?
You are welcome to join my forum. 4 active members lol but it's a cool place. active... much talking :D it's fun!
http://caaz.freeforums.org/
User avatar
Caaz Games
 
Posts: 729
Joined: Wed Feb 14, 2007 9:09 am
Location: California....knows how to party!
Score: 25 Give a positive score

Postby Fuzzy » Wed Jul 25, 2007 10:20 pm

Thats right. You can fill in zero where ever the walls are in the maze. That will automatically tell the cops that they cannot step there. This is a good use for graph paper, if you have any.

Pencil in the walls, then in each remaining white square, figure out the combination of possible moves. From there, you can write in a number. You might be able to pull it off with straight to a text file too.

From there, transform it into a pre filled array.
Code: Select all
char CopMap[16][16] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
}

See? Notice that lack of the last comma.

Thats not tested code. The array might not be quite right. As far as actors go, you dont need one at all the locations. Draw the map as one large actor.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Caaz Games » Wed Jul 25, 2007 10:24 pm

Ok ill see if this works in a little bit... To Wallmart!xD
You are welcome to join my forum. 4 active members lol but it's a cool place. active... much talking :D it's fun!
http://caaz.freeforums.org/
User avatar
Caaz Games
 
Posts: 729
Joined: Wed Feb 14, 2007 9:09 am
Location: California....knows how to party!
Score: 25 Give a positive score

Postby Caaz Games » Wed Jul 25, 2007 10:47 pm

Ok i got it i think, where do i put the codes? Image
You are welcome to join my forum. 4 active members lol but it's a cool place. active... much talking :D it's fun!
http://caaz.freeforums.org/
User avatar
Caaz Games
 
Posts: 729
Joined: Wed Feb 14, 2007 9:09 am
Location: California....knows how to party!
Score: 25 Give a positive score

Postby DilloDude » Thu Jul 26, 2007 4:14 am

You need to have a 2 dimensional array with all those numbers stored in it. Once that's done, your cop actor needs to know where it is. That shouldn't be too hard, because you can update it every time you move, so you can keep track of your location in the array. If you know what the initial location is going to be, you can automatically set that on creation, otherwise, calculate it based on coordinates. Store the location in some actor variables: (xloc, yloc). Your cop actor will need a create actor event and a move finish event. They should be axactly the same:
Code: Select all
char movedir;
do
{
    movedir = rand(3.99999);
}while((CopMap[xloc][yloc] & pow(2, movedir)) == 0);
switch(movedir)
{
    case 0: //move north
    MoveTo("Event Actor", 0, -size, velocity, "Event Actor", "");
    //change animation
    break;
 
    case 1: //move south
    MoveTo("Event Actor", 0, size, velocity, "Event Actor", "");
    //change animation
    break;
 
    case  2: //move east
    MoveTo("Event Actor", size, 0, velocity, "Event Actor", "");
    //change animation
    break;
 
    case 3: //move west
    MoveTo("Event Actor", -size, 0, velocity, "Event Actor", "");
    //change animation
    break;
}

Replace 'size' with the distance from the middle of one squqre to the middle of the next. Replace 'velocity' with the speed you want the actor to move. Fill in the appropriarte change animation code.
Wow! I think that's the first time I've used a do...while statement!
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron