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

#1 2010-07-15 14:24:04

codeblue
New Scratcher
Registered: 2010-07-13
Posts: 11

Detecting location of an object from script

I have started on a pacman type game and I would like for the ghosts to detect pacmans location, but right now all i can do is have the ghost moving randomly is there a way to go about detection the coordinates of something within the script?

Offline

 

#2 2010-07-15 14:33:06

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: Detecting location of an object from script

Try going into "sensing", and find the block like this:

http://wiki.scratch.mit.edu/images/%28%29_of_%28%29_%28Sensing%29.png

You can use it so that the ghosts can detect pacman's location, and react to it. It's explained a little better here: http://wiki.scratch.mit.edu/wiki/()_of_ … ing_block)


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#3 2010-07-17 09:30:50

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Detecting location of an object from script

That's a pretty good idea. In a pacman I used to be working on, I made a sprite that did two things forever. It went to Blinky, and it pointed towards Pacman. Then I made a list for Blinky. If the pointer was pointing mostly up, item #1 on the list would be Up. If the pointer was also pointing slightly to the right, item #2 would be Right. Basically, it was a list of which direction Blinky wanted to go. If blinky wanted to go up, but couldn't (because of a wall) he would just use the next item on the list. Hope this helps. (I do concede that it took a lot of script just to get Blinky moving on "Chase mode", I never finished scatter mode).


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2010-07-17 09:33:51

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Detecting location of an object from script

It's also worth pointing out (if you don't already know it) that each ghost has a "personality". Blinky always (when in "Chase mode" wants to take the shortest route to get to pacman, Pinky wants to get to two squares ahead of pacman, Inky is kind of strange... I don't really understand him. Clyde always (when in "Chase mode") is trying to move towards pacman, but once he gets close, moves back to his corner.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2010-07-17 12:43:42

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Detecting location of an object from script

More than you want to know and ALMOST everything you need to know...

The Pac-Man Dossier!


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer