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

#1 2012-04-26 09:43:29

COASTERBOY246
New Scratcher
Registered: 2012-03-06
Posts: 3

How do i make 5 sprites (one being the player) rebound off walls.

I need the enemys to track the player in a maze, and the player shoots them. they need to regen. also, they must "bounce" off the maze made in stage.

really need help, as this is my school project for game design!

Offline

 

#2 2012-04-26 10:12:28

COASTERBOY246
New Scratcher
Registered: 2012-03-06
Posts: 3

Re: How do i make 5 sprites (one being the player) rebound off walls.

Please Help!!!

Offline

 

#3 2012-04-26 14:19:50

Tbtemplex97
Scratcher
Registered: 2011-11-12
Posts: 100+

Re: How do i make 5 sprites (one being the player) rebound off walls.

There is not block for bouncing but the best way to script it is by:

You must Set the colour of your walls depending on what direction the wall is facing, in my example I will use:

Red - Facing up
Blue - Facing Down
Green - Facing Left
Yellow - Facing Right

Forever
IF <Touching Colour>["red"]
Change Y By [1]
IF <Touching Colour>["blue"]
Change Y By [-1]
IF <Touching Colour>["green"]
Change X By [-1]
IF <Touching Colour>[yellow"]
Change X By [1]

This Should make the sprite its on bounce of the right walls,

You MUST make the walls the right colour
They must all face in a perfect direction

Hoped that helped..


Online Status: http://blocks.scratchr.org/API.php?action=onlineStatus&amp;user=Tbtemplex97
Darkspace Coming Soon!, Try the Singleplayer Demo

Offline

 

#4 2012-04-28 14:49:37

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: How do i make 5 sprites (one being the player) rebound off walls.

Like the above post said, make each wall a different color. However, with this formula you only need to make horizontal walls one color and vertical walls another:

when gf clicked
set [speed v] to (5)
forever
set [speed x v] to ([sin v] of ((direction) * (speed)))
set [speed y v] to ([cos v] of ((direction) * (speed)))
change x by (speed x)
if <touching color [#000000]?>
 set [speed x v] to ((speed x) * (-1))
end
change y by (speed y)
if <touching color [#ffffff]?>
 set [speed y v] to ((speed y) * (-1))
end
point in direction ([atan v] of ((speed x) / (speed y)))
if <(speed y) < (0)>
 turn cw (180) degrees
end
Keep in mind the colors can be any color but each other  smile

Last edited by chanmanpartyman (2012-04-28 14:52:00)

Offline

 

#5 2012-04-28 22:16:21

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How do i make 5 sprites (one being the player) rebound off walls.

@chanmanpartyman- I think you have sine and cosine reversed.  sin = y, cos = x.

Offline

 

Board footer