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

#1 2012-11-23 23:17:55

neelmm1234
New Scratcher
Registered: 2012-11-20
Posts: 8

A game i was making

I am making a game which is sort of like a maze. I just can't get how to make a script which will not let the player go through walls and off boundaries. The player moves with arrow keys. Can someone help on how to make a script which will not let the player go through walls and off boundaries?

Offline

 

#2 2012-11-23 23:49:53

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

Re: A game i was making

Make the boundry one single sprite, if the player touches the sprite, player can not go the direction they are currently going.

Offline

 

#3 2012-11-24 08:25:17

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: A game i was making

Here's a script that should help:  big_smile

(player script)

when gf clicked
forever
move//whatever movement script you have goes here
if <<touching [walls v]?> or <touching [edge/boundaries v]?>>
turn cw (180) degrees
move (10) steps
end

Last edited by powerpoint56 (2012-11-24 08:25:25)


http://i48.tinypic.com/2072ctw.gif

Offline

 

#4 2012-11-24 13:52:37

neelmm1234
New Scratcher
Registered: 2012-11-20
Posts: 8

Re: A game i was making

Thanks powerpoint56.  smile

Also, if anybody needs it to help me, this is how one of my arrow key movement scripts look like:

if <key [right arrow v] pressed ?>
point in direction [90 v]
move (5) steps

Offline

 

#5 2012-11-25 23:25:17

neelmm1234
New Scratcher
Registered: 2012-11-20
Posts: 8

Re: A game i was making

Powerpoint56, the script you gave me, it keeps glitching. Sometimes it lets the player go through the walls, and sometimes makes the controls all crazy.  Can someone help?

Offline

 

#6 2012-11-26 19:35:44

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: A game i was making

neelmm1234 wrote:

Powerpoint56, the script you gave me, it keeps glitching. Sometimes it lets the player go through the walls, and sometimes makes the controls all crazy.  Can someone help?

Maybe, try this. First, make two variables, "x" and "y". Replace your script with this:

when gf clicked
set [x v] to (0)
set [y v] to (0)
forever
if <key [left-arrow v] pressed?>
set [x v] to (-1) // or other negative number you want
else
set [x v] to (0)
end
if <key [right-arrow v] pressed?>
set [x v] to (1) // or other positive number you want
else
set [x v] to (0)
end
if <key [down-arrow v] pressed?>
set [y v] to (-1) // or other negative number you want
else
set [y v] to (0)
end
if <key [up-arrow v] pressed?>
set [y v] to (1) // or other positive number you want
else
set [y v] to (0)
end
if <<touching [wall v]?> or <touching [edge v]?>>
change [x v] by ((x)*(-2.5))
change [y v] by ((y)*(-2.5))
end
change x by (x)
change y by (y)
Hope this actually works.  smile

Last edited by powerpoint56 (2012-11-26 19:36:36)


http://i48.tinypic.com/2072ctw.gif

Offline

 

#7 2012-11-26 20:06:42

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: A game i was making

powerpoint56 wrote:

neelmm1234 wrote:

Powerpoint56, the script you gave me, it keeps glitching. Sometimes it lets the player go through the walls, and sometimes makes the controls all crazy.  Can someone help?

Maybe, try this. First, make two variables, "x" and "y". Replace your script with this:

when gf clicked
set [x v] to (0)
set [y v] to (0)
forever
if <key [left-arrow v] pressed?>
set [x v] to (-1) // or other negative number you want
else
if <key [right-arrow v] pressed?>
set [x v] to (1) // or other positive number you want
else
set [x v] to (0)
end
end
if <key [down-arrow v] pressed?>
set [y v] to (-1) // or other negative number you want
else
if <key [up-arrow v] pressed?>
set [y v] to (1) // or other positive number you want
else
set [y v] to (0)
end
end
if <<touching [wall v]?> or <touching [edge v]?>>
change [x v] by ((x)*(-2.5))
change [y v] by ((y)*(-2.5))
end
change x by (x)
change y by (y)
Hope this actually works.  smile

One problem I see with your script is if you hold down the left arrow key and not the right arrow key, you won't move left. Hopefully the changes I added above ^^ will get rid of that.


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-11-26 20:48:23

tree-hugger
Scratcher
Registered: 2011-11-19
Posts: 38

Re: A game i was making

I know this isn't exactly what you wanted but this might make your life easier. When your sprite touches a wall it will go back to the beginning, it's a much easier type of maze game to make heres the script for it:

when gf clicked
forever
  if <<touching [wall v]> or <touching [barrier v]>>
    glide to x: (start) and y: (start)
  end
end


http://oi48.tinypic.com/1y7tjr.jpghttp://oi50.tinypic.com/28tb34j.jpg                     http://oi50.tinypic.com/21c6v74.jpg                    ...ya, I'm weird... REAL weird...
BITBOT ALL THE WAY!!!     Only the WEIRDEST games!     (that's just  a Tree-Hugger thing)

Offline

 

#9 2012-11-26 21:26:41

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: A game i was making

tree-hugger wrote:

I know this isn't exactly what you wanted but this might make your life easier. When your sprite touches a wall it will go back to the beginning, it's a much easier type of maze game to make heres the script for it:

when gf clicked
forever
  if <(touching [wall v]?) or (touching [barrier v]?)>
   glide [some] secs to x: (start) y: (start)
 end

Fixed.

Last edited by ErnieParke (2012-11-26 21:28:25)


http://i46.tinypic.com/35ismmc.png

Offline

 

#10 2012-11-27 19:46:41

scratchyrocks
Scratcher
Registered: 2012-09-29
Posts: 19

Re: A game i was making

this should work


when gf clicked
forever
 if <<key [up arrow v] pressed?> and <touching color [color of wall]>>
change y by <[speed of sprite when up arrow pressed] * (-1)>
 end
 if <<key [down arrow v] pressed?> and <touching color [color of wall]>>
change y by <[speed of sprite when down arrow pressed] * (-1)>
 end
 if <<key [right arrow v] pressed?> and <touching color [color of wall]>>
change x by <[speed of sprite when right arrow pressed] * (-1)>
 end
 if <<key [left arrow v] pressed?> and <touching color [color of wall]>>
change x by <[speed of sprite when left arrow pressed] * (-1)>
 end

Offline

 

Board footer