C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Programming 'Eaters' in Pacman Posted by coder_man on 17 May 2006 at 4:48 AM
Hello Everybody!
I have loggged on after a very looooooong time ...so please cooperate!

I am making a game of PacMan (in 2D graphics) for my school project.
Its almost complete but i am stuck in one place.
I CAN'T DEVISE A STRATEGY TO PROGRAM THE 'EATERS'(i hope you know 'eaters' in Pacman) ....i.e.
How they Chase Them????How They Move Automatically on their own to chase pacman????
How I program its AI??
Please help me out before this vacation ends.....
If you require some useful part of my code ..please reply...
THANK YOU (atleast for 'READING!')



Report
Re: Programming 'Eaters' in Pacman Posted by Faz on 17 May 2006 at 5:36 AM
This sounds like fun.
If I remember right, the eaters only change direction when they get to certain points, i.e. they don't change direction at any position on the screen. They get to these points and when they do, a function is called to determine which directions are available, up, down, left or right. Out of these possible directions, it will decide which will reach you the quickest.

A basic AI is to use this as if you were stationary and find the shortest path from the eaters position to you.

A more complex function is to assume that PacMan is going to be heading in the same direction he is now. i.e. PacMan is travelling upwards, whenever the AI function is called, take this in and then decide which is the shortest path on the assumption that PacMan is heading up at a constant speed.

I'll be really interested to know how you're able to create these images in C++. People keep linking me to sample code but it just doesn't seem to work on my computer. (I'm using C++ BuilderX)


If you're confused by my description, imagine you're chasing someone in a car and you know where they are. When you arrive at a junction in the road, you want to take the shortest route to catch the target.

Hope that helps.
Report
Re: Programming 'Eaters' in Pacman Posted by Lundin on 17 May 2006 at 5:38 AM
: Hello Everybody!
: I have loggged on after a very looooooong time ...so please cooperate!
:
: I am making a game of PacMan (in 2D graphics) for my school project.
: Its almost complete but i am stuck in one place.
: I CAN'T DEVISE A STRATEGY TO PROGRAM THE 'EATERS'(i hope you know 'eaters' in Pacman) ....i.e.
: How they Chase Them????How They Move Automatically on their own to chase pacman????
: How I program its AI??
: Please help me out before this vacation ends.....
: If you require some useful part of my code ..please reply...
: THANK YOU (atleast for 'READING!')
:


I would let each one of them use a shortest-path algorithm (shouldn't be hard to find the source for one on the net) to calculate the fastest way to move between themself and pacman. But they would be too smart if they used that algorithm all the time, the player wouldn't have a chance. So you need to add somekind of random behaviour to them. Perhaps if they are close to pacman, they will turn smarter and chase him, but if they are far from him they just fool around.

The easier alternative is to make them move around randomly all the time - have them move in one direction and let them make a new decision at every intersection they come to in the maze.

Report
Re: Programming 'Eaters' in Pacman Posted by IDK on 17 May 2006 at 6:59 AM
: Hello Everybody!
: I have loggged on after a very looooooong time ...so please cooperate!
:
: I am making a game of PacMan (in 2D graphics) for my school project.
: Its almost complete but i am stuck in one place.
: I CAN'T DEVISE A STRATEGY TO PROGRAM THE 'EATERS'(i hope you know 'eaters' in Pacman) ....i.e.
: How they Chase Them????How They Move Automatically on their own to chase pacman????
: How I program its AI??
: Please help me out before this vacation ends.....
: If you require some useful part of my code ..please reply...
: THANK YOU (atleast for 'READING!')
:
:
:
:

This is how I would do it:

When an eater get to an intersection:
if pacman has higher x value and it's possible to go right
set dx to 1
if pacman has lower x value and it's possible to go left
set dx to -1
if pacman has higher y value and it's possible to go down
set dy to 1
if pacman has lower y value and it's possible to go up
set dy to -1

Where x, y is the pos of eater. dx,dy is the movement of an eater.


Happy coding wishes
the one and only
Niklas Ulvinge aka IDK

Report
Re: Programming 'Eaters' in Pacman Posted by digitalrana on 19 May 2006 at 5:06 AM
hey this is a really interesting project...are u going to put the final code up anywhere? i would be interested in viewing it...

about ur problem...i think u shud program the eaters to move around the screen randomly then if they get within a certain distance of pacman, they begin to chase him...
if they are constantly chasing him it would get too hard because they would constantly hone in on his position...imagine the situation while ur playing the game...if all the eaters jus keep moving to u...

it myt also be interesting if u program them to do the reverse...when he's powered up (as in when he can eat them) , and they are nearby, they could run away from him...

hope that helps...n hope to c ur code in the future ;)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.