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

#1 2008-09-19 15:07:56

Kingdaro
Scratcher
Registered: 2008-06-08
Posts: 100+

I need help with my project...

I'm making a game called Labyrinth where you are a red dot moving through a literally moving maze collecting treasures within 60 seconds. I am having trouble with rounding a piece's x and y position. Can someone give me a script that rounds the position to every 45 units starting at 22.5? As in make the position random and within 45 countings starting at 22.5 so that the board is 8 by 8 squares. The squares will shift when an arrow is clicked, and when they are out of frame make them go to the opposite side. If you didn't understand what I said then ask questions. It's okay to ask questions!

Offline

 

#2 2008-10-22 14:05:44

djmoomoo
Scratcher
Registered: 2007-08-31
Posts: 57

Re: I need help with my project...

You could use this:

X is the X/Y position.

use the following formula:

((X/45)rounded to the nearest whole number) * 45 = NewPosition

This works by using the "round" block's problem: It can only round to whole numbers.
So we divide X by 45, so then we round it, then * it by 45. There's probably an easier way, but there you go.


There are 0011 types of people, those that can count in binary and those that can't.

Offline

 

#3 2008-10-22 16:50:29

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: I need help with my project...

The above example rounds it to 45. but startoing at 0. It should be:

(( (( (( 45 <*> <round( (( (( x <-> 22.5 )) </> 45 )) )) <+> 22.5 ))

Last edited by deerel (2008-10-22 16:50:48)

Offline

 

Board footer