Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Enemy movement on a maze (like pacman)  (Read 2812 times)
0 Members and 1 Guest are viewing this topic.
Offline Graziano Mesina

Senior Newbie

« Posted 2006-05-02 14:35:44 »

Hi, I would know what's the best way, for an enemy sprite, to search the path on a maze??
(Like pacMan)

I will appreciate code's examples

-Montanelli-: Ma lei evadeva quasi sempre, no? <br /><br />-Mesina-: Sì, ho la fortuna di avere i polsi più grossi delle mani...
Offline Ask_Hjorth_Larsen

Junior Devvie

Java games rock!

« Reply #1 - Posted 2006-05-02 17:49:21 »

Search for the A* (A star) algorithm or more generally "pathfinding". It's pretty easy if you just have a pacman-style maze. If you have a continuous world it's somewhat more complicated. I think there's something in the Shared code forum you might benefit from. Just a few pointers...
Offline fletchergames

Senior Devvie

« Reply #2 - Posted 2006-05-03 03:33:17 »

A* is good for pathfinding.

However, in pacman games, the ghosts probably aren't using A*.  What they do is the following:

if there's a possible turn {
   depending upon this ghost'
s type of ai, decide which way to turn
} else {
   keep going straight

That's alot simpler than A*.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline woogley
« Reply #3 - Posted 2006-05-03 03:43:28 »

I did a pacman clone once. basically I had my ghosts run around randomly, and at each intersection, they looked all four ways. if they caught a glimpse of pacman, they'd head in that direction without question until 1) they hit a wall or 2) they see pacman again

not the best AI scheme, but it is easier than A*
Offline Graziano Mesina

Senior Newbie

« Reply #4 - Posted 2006-05-03 09:04:20 »

I did a pacman clone once. basically I had my ghosts run around randomly, and at each intersection, they looked all four ways.

I use a TileMap.. so at any time I've to look if the tiles around the enemy are blocked or not? that is not expensive??

-Montanelli-: Ma lei evadeva quasi sempre, no? <br /><br />-Mesina-: Sì, ho la fortuna di avere i polsi più grossi delle mani...
Offline woogley
« Reply #5 - Posted 2006-05-03 13:30:49 »

yeah I used a tilemap too (not an 'official' TileMap, just one I hacked up real fast), it isn't very expensive at all to do that. you can optimize it in a variety of ways.

for example... don't forget that technically your ghosts can "know" where pacman is at any time during gameplay, because the variables are all in the same scope. with this in mind, you do a quick check of where he is. so if my ghost hits an intersection, and pacman's position is higher than the ghost, I wouldn't bother looking DOWN for pacman.

my pacman clone was a 400x400 game, which used a 25x25 tilemap (each tile being 16x16). a grid of that size is cake when it comes to scanning around the tilemap for stuff - no performance issues at all for me Wink
Offline SmittyTheSmit

Senior Newbie

« Reply #6 - Posted 2006-05-05 13:27:31 »

I have just implemented the ghost AI on my pac-man game and this is what I did .

test the position of the ghost with the position of the player.

if ghost is not moving . pick one of the 2 directions that will take it towards the player.

if ghost is moving but it has not moved the distance of one tile square, keep moving

if the ghost has moved the distance of 1 tile square, check the 2 possible directions the player may be, if not blocked, choose one, if blocked, continue the way it was already going.

I found that this worked very well, especially when i added a little check that if a ghost got stuck unable to move towards the player, it would keep picking a random direction until it got moving again.

hope that helps

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (37 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (44 views)
2015-07-27 16:38:00

Riven (24 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (40 views)
2015-07-25 00:14:37

BurntPizza (48 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53

NoxInc (40 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!