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
Make the boundry one single sprite, if the player touches the sprite, player can not go the direction they are currently going.
Offline
Here's a script that should help:
(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)
Offline
Thanks powerpoint56.
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
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
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.
Last edited by powerpoint56 (2012-11-26 19:36:36)
Offline
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.
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.
Offline
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
Offline
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)
Offline
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