i am currently wrighting a pacman program, but am stuck at the ghosts. i have posted my current progress on my profile and will update if there is any developments
Offline
What do you need help with in the ghosts? If it's the movement I can help you
when gf clicked forever move [2] steps //you can do it faster if you want
when gf clicked forever if <touching [wall v]?> //make it the color of the wall repeat until <not<touching [wall v]?>> //color of the wall again turn cw [90] degrees end endIt's pretty basic but it would get the job done if the walls are at 90 degree angles.
Offline
[scratchblocks]
when gf clicked
repeat forever
if (colour grey is touching blue)
set wall to pick random 1-4
then:
if wall=1, point in direction 90
if wall=2, point in direction 180
if wall=3, point in direction -90
if wall=4, point in direction 0
this way the ghost is constantly moving and cant get stuck on the walls.
the ghost has a grey dot in front of it at all times, and if it touches the wall in front of it the ghost turns.
the problem is to get the ghost to chase the pacman when he gets near. i have tried many things but none have worked. any suggestions?
Offline
when gf clicked repeat forever if (colour grey is touching blue) set wall to pick random 1-4
Offline
for pacman ghosts, it's a bit trickier than pacman himself.
when gf clicked //background script forever set [wall v] to [0] wait (1) secs set [wall v] to [1] wait (1) secs end
when gf clicked //now for the ghosts if <color [(color of sensor) v] touching [(color of wall) v]> //whatever color the wall is if <(wall v) = [1]> turn cw (90) degrees else turn ccw (90) degrees end endhope this helps!
Last edited by ty44 (2012-04-02 14:24:52)
Offline
clever, but that's not what I'm having trouble with. its getting the ghost to navigate its way through the maze towards the pacman when he gets close.
Offline
If you feel like you're up for the challenge, you could try implementing the A* search algorithm. It calculates the shortest path between the ghost and Pacman. You may have to modify your current game setup so that all the walls are aligned to a grid (and stored somehow in an array). If you really want to try this, I could write a longer post describing it in more detail.
EDIT: Note, this algorithm is recursive, which means it will eat up processing time for Scratch. The game might have to run in Turbo.
Last edited by amcerbu (2012-05-10 21:13:42)
Offline
architect416 wrote:
when gf clicked repeat forever if (colour grey is touching blue) set wall to pick random 1-4then:if wall=1, point in direction 90 if wall=2, point in direction 180 if wall=3, point in direction -90 if wall=4, point in direction 0this way the ghost is constantly moving and cant get stuck on the walls.
the ghost has a grey dot in front of it at all times, and if it touches the wall in front of it the ghost turns.
the problem is to get the ghost to chase the pacman when he gets near. i have tried many things but none have worked. any suggestions?
Fixed.
Offline
thanks guys. i will take all above advice into account, but becsa, this meant the ghost will get stuck in a wall. A* search algorithim......interesting
Offline
If you want a more detailed description of pathfinding, check out this link (it's a pretty good one):
http://theory.stanford.edu/~amitp/GameProgramming/
Offline