Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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 2416 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 Duke




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 Duke





« 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:

1  
2  
3  
4  
5  
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (19 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!