This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-30 20:21:42

architect416
New Scratcher
Registered: 2012-03-30
Posts: 8

pacman

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

 

#2 2012-03-30 20:26:38

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: pacman

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
end
It's pretty basic but it would get the job done if the walls are at 90 degree angles.

BTW welcome to Scratch!

Offline

 

#3 2012-04-01 17:06:20

architect416
New Scratcher
Registered: 2012-03-30
Posts: 8

Re: pacman

[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

 

#4 2012-04-02 01:01:55

architect416
New Scratcher
Registered: 2012-03-30
Posts: 8

Re: pacman

when gf clicked
repeat forever
     if (colour grey is touching blue)
     set wall to pick random 1-4

Offline

 

#5 2012-04-02 14:22:57

ty44
Scratcher
Registered: 2011-02-05
Posts: 57

Re: pacman

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
end
hope this helps!

Last edited by ty44 (2012-04-02 14:24:52)


http://t3ak.roblox.com/07ffa69f8ced34c7220abf1a8008c1d1 Mario Kart OBSESSION!

Offline

 

#6 2012-04-05 02:56:33

architect416
New Scratcher
Registered: 2012-03-30
Posts: 8

Re: pacman

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

 

#7 2012-04-06 09:56:00

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: pacman

architect416 wrote:

when gf clicked
forever if <color [#ADA6A9] is touching [#5149EB]>
set [wall v] to (pick random (1) to (4))

That should be better  wink


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#8 2012-05-10 16:07:49

becsa
New Scratcher
Registered: 2012-05-10
Posts: 2

Re: pacman

To get the ghosts to move towards pacman do..

[ scratchblocks ]
when gf clicked
if < distance to ( pacman ) < [ 1000 ]
point towards pacman


thats the best iv got

Offline

 

#9 2012-05-10 21:11:28

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: pacman

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

 

#10 2012-05-12 11:22:48

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: pacman

architect416 wrote:

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?

Fixed.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#11 2012-05-13 04:52:45

architect416
New Scratcher
Registered: 2012-03-30
Posts: 8

Re: pacman

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

 

#12 2012-05-13 11:27:34

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: pacman

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

 

#13 2012-05-13 11:34:26

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Offline

 

Board footer