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

#1 2011-04-24 15:01:22

Ratchetclan4
New Scratcher
Registered: 2011-04-23
Posts: 5

I get stuck in my walls using x and y

Ok so i've got the wall blocking all set up, theres just one problem
once you've touched the wall your stuck in it how do i combat this?
(the x and y use -numbers if you going to the right and use positive if you going to the left)

Example (going right x would say -500)  ( going left it would say 500)


http://dl.dropbox.com/u/25078942/scratchmario.PNG


- by the way that 360 second post restriction happens just for having the new scratchers not allowed img tags alert

Offline

 

#2 2011-04-24 15:28:50

Ratchetclan4
New Scratcher
Registered: 2011-04-23
Posts: 5

Re: I get stuck in my walls using x and y

Nevermind i have fixed this
i used a If not touching color

Offline

 

#3 2011-04-24 17:20:38

Ratchetclan4
New Scratcher
Registered: 2011-04-23
Posts: 5

Re: I get stuck in my walls using x and y

Ratchetclan4 wrote:

Nevermind i have fixed this
i used a If not touching color

Ignore what i said above


The problem is still there, what can i do to correct it?

Offline

 

#4 2011-04-24 20:38:49

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: I get stuck in my walls using x and y

Your problem is that you have told the sprite not to move at all if it's touching the color at... you can see where this is going.  tongue  To fix this, you should make a sensor sprite that is invisible (set the ghost effect to 100). The sprite will have four different colored sides, to determine which side is hitting something. For example, this is the code for the right 'bumper', assuming it's blue:
(Note this is general code, since I'm not entirely sure how yours works based on that screenshot. You'll have to modify it a bit to make it work with your project.)

Code:

When green flag clicked
forever
    if color [blue] is touching color [red]
        set right_test to 1
    else
        set right_test to 0
    end_if
    [code for other 3 bumpers]
end_forever

"right_test_ is a variable that tells the player sprite if is touching a wall to the right. If it is equal to one, it can't move right.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#5 2011-04-24 21:26:38

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

Re: I get stuck in my walls using x and y

Or if it is from a bird's eye point of view, either look at this

or
<when green flag clicked>
<forever>
    <if><key[ Up Arrow ]pressed?>
        <change y by( 3 )>
        <if><touching color[ ColorOfWall ]>
            <change y by( -3 )>
        <end>
    <end>
<end>

repeat for all directions (you can put them all in the same script, just use another if statement.

Last edited by MoreGamesNow (2011-04-24 21:27:21)


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

Offline

 

Board footer