#3 2011-03-16 15:54:34

YourLocalBlockLib
Scratcher
Registered: 2011-03-10
Posts: 100+

Re: ITopic: Welcome to your local block library!

Motion
/img/tinypic/29wri81.jpg
/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/googleusercontent/make%20move.gif Shared by MarioBlender

Blockspec:

('make %m move %n steps' #- #move:forward:)

Code:

move: sprite forward: distance
    sprite forward: distance

What this block does:
Lets a sprite move another sprite without having to use a broadcast!

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/838603304.gif Shared by MathWizz

Blockspec:

('if touching %m bounce' #- #bounceOffSprite:)

Code:

bounceOffSprite: aName
    | sprite oldDir |
    sprite _ self coerceSpriteArg: aName.
    (self touching: sprite)
        ifFalse: [^ self].
    oldDir _ self heading.
    self pointTowards: sprite.
    self turnRight: self heading - oldDir + 180.
    [self touching: sprite]
        whileTrue: [self forward: 1]

What this block does:
Causes the sprite to bounce off the selected sprite if touching it. (Assumes the sprite is a circle.)

/img/dropbox/BlockLibDiv2.png

/img/weebly/8212093.gif Shared by jslomba
Blockspec:

('if %b bounce' #- #bounceIfBoolean:)

Code:

bnceIfBoolean: condition
     condition ifTrue: [self turnRight: 180]

What this block does:
Causes the sprite to bounce if the condition is true.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/774534017.gif Shared by Pecola1

Blockspec:

('set rotation style to %r' #- #rotationStyle:)

Code:
No code needed

Scratch objects> ScratchSpriteMorph>motion ops

rotationStyleChanger
    ^ #('normal' 'leftRight' 'none' )

Scratch-Blocks> CommandBlockMorph>> -- all -- > uncoleredArgMorphFor:
add the strip...

$r = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #rotationStyleChanger;
         choice: 'normal'].

What this block does:
Allows you to change the rotation style of a sprite.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/746685631.gif Shared by Pecola1

Blockspec:

('rotation style' #r #rotationStyle)

Code:

rotationStyle
    ^ rotationStyle

What this block does:
Reports a sprite's rotation style.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/191261826.gif Shared by StrykerV

Blockspec:

('point at x:%n y:%n' #- #pointToX:y:)

Code:
No code needed
What this block does:
Points the sprite at the specified region of the stage.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/541806018.gif Shared by Hardmath123

Blockspec:

('go to random x-y position' #- #randxypos)

Code:

Code:

randxypos
    self gotoX: (self randomFrom: -240 to: 240)
        y: (self randomFrom: -180 to: 180)

/img/dropbox/BlockLibDiv2.png

/img/weebly/4636328.gif Shared by Hardmath123 and made with Scramble

Blockspec
('Arrow key move with speed %n ' #- #arrowMove:)

Code:

arrowMove: i1
"Made using Scramble by Hardmath123"
| t4 t3 t2 t1|

t1_ 'up arrow'.
t2_ 'down arrow'.
t3_ 'left arrow'.
t4_ 'right arrow'.

t1_ self keyPressed:t1.
t2_ self keyPressed:t2.
t3_ self keyPressed:t3.
t4_ self keyPressed:t4.

t1 ifTrue: [
self gotoX: self xpos y: (i1+ self ypos).
].

t2 ifTrue: [
t2_i1 * -1.
self gotoX: self xpos y: (t2+ self ypos).
].

t3 ifTrue: [
t3_i1 * -1.
self gotoX: (t3+self xpos) y: self ypos.
].

t4 ifTrue: [
self gotoX: (i1+self xpos) y: self ypos.
].

What this block does:
Move around using the arrow keys at the specified speed.

/img/dropbox/BlockLibDiv2.png

/img/weebly/7756782.gif Shared by SSSS
Blockspec:

('draggable?' #b #draggable)

Code:
no code needed
What this block does:
Reports whether or not the sprite is draggable.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/gopercenttoxy.gif Shared by Greenatic
Blockspec:

('go %n% of the way to x: %n y: %n' #- #Distance:X:Y:)

Code:

Distance: t1 X: t2 Y: t3
    | newX newY |
    newX _ t1 * 0.01 * (t2 - self xpos).
    newY _ t1 * 0.01 * (t3 - self ypos).
    self gotoX: newX + self xpos y: newY + self ypos

What this block does:
Moved a percentage of the distance to a spot.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/gopercenttosprite.gif Shared by Greenatic
Blockspec:

('go %n % of the way to %m' #- #Distance:Sprite:)

Code:

Distance: t1 Sprite: t2
| t3 t4 newX newY |
    t2 = #mouse
        ifTrue:
            [newX _ self mouseX * (t1 * 0.01).
            newY _ self mouseY * (t1 * 0.01).
            self gotoX: newX + self xpos y: newY + self ypos].
        ifFalse:
            [t3 _ self coerceSpriteArg: t2.
            t4 _ t3 referencePosition.
            newX _ t4 x * (t1 * 0.01).
            newY _ t4 y * (t1 * 0.01).
            self gotoX: newX + self xpos y: newY + self ypos]

What this block does:
Moved a percentage of the distance to a spot.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/goinbetween.gif Shared by Greenatic and jslomba
Blockspec:

Code:

('go in between x: %n y: %n and x: %n y: %n' #- #betweenX:Y:X:Y:)

Code:

betweenX: t1 Y: t2 X: t3 Y: t4
| newX newY |

newX_ (t1 + t3) / 2.
newY_ (t2 + t4) / 2.
self referencePosition: newX @ newY

What this block does:
Goes to the middle location between two specified locations.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/makedrag.gif Shared by Greenatic, improved by Scimonster
Blockspec:

('make %m draggable' #- #MakeDraggable:)

Code:

MakeDraggable: t1
    t1 draggable: false

What this block does:
Makes the sprite put in the dropdown menu draggable.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/makeundrag.gif Shared by Greenatic, improved by Scimonster
Blockspec:

('make %m undraggable' #- #MakeUndraggable:)

Code:

MakeUndraggable: t1
    t1 draggable: false

What this block does:
Makes the sprite put in the dropdown menu un-draggable.

For these 2 blocks, go to Scratch-Blocks >> SpriteArgMorph >> other >> presentMenu, and paste in the following code:

Code:

presentMenu
    | t1 t2 t3 t4 t5 |
    (t1 _ self ownerThatIsA: ScratchFrameMorph) ifNil: [^ self].
    (owner isKindOf: CommandBlockMorph)
        ifTrue: [t2 _ owner selector].
    t3 _ t1 scratchObjects.
    t3 sort: [:t6 :t7 | t6 objName asLowercase < t7 objName asLowercase].
    t4 _ CustomMenu new.
    t2 = #getAttribute:of:
        ifTrue: [t4 add: 'Stage' localized asUTF8 action: t1 workPane]
        ifFalse:
            [(t2 = #MakeUndraggable: | t2 = #MakeDraggable:)
                ifFalse:
                    [t4 add: 'mouse-pointer' localized asUTF8 action: #mouse.
                    t2 = #touching: ifTrue: [t4 add: 'edge' localized asUTF8 action: #edge].
                    t3 _ t3 copyWithout: owner receiver]].
    t3 size > 0 ifTrue: [t4 addLine].
    t3 do: [:t8 | t4 add: t8 objName action: t8].
    (t5 _ t4 startUp) ifNil: [^ self].
    morph _ t5.
    self fixGetAttribueBlock.
    self updateLabel

This removes "mouse-pointer" from the menu.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/makeselfdrag.gif Shared by Greenatic
Blockspec:

('make me draggable' #- #MakeDraggable)

Code:

MakeDraggable
    draggable _ true

What this block does:
Makes the sprite draggable.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/makeselfundrag.gif Shared by Greenatic
Blockspec:

('make me undraggable' #- #MakeUndraggable)

Code:

MakeUndraggable
    draggable _ false

What this block does:
Makes the sprite un-draggable.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/movetowards.gif Shared by Greenatic
Blockspec:

('move %n steps towards %m' #- #Move:Towards:)

Code:

Code:

Move: t1 Towards: t2 
    | t3 t4 t5 t6 t7 t8 t9 |
    t2 = #mouse ifFalse: [t3 _ t2 xpos @ t2 ypos - self referencePosition].
    t2 = #mouse ifTrue: [t3 _ self mouseX rounded @ self mouseY - self referencePosition].
    t4 _ t3 x abs < 0.001
                ifTrue: [t3 y < 0
                        ifTrue: [90]
                        ifFalse: [270]]
                ifFalse: [((t3 x >= 0
                        ifTrue: [0]
                        ifFalse: [180])
                        - ((t3 y / t3 x) arcTan * 57.2957795131)) rounded].
    t5 _ t4 degreesToRadians.
    t6 _ t5 cos @ t5 sin * t1.
    t7 _ self position + t6.
    t8 _ t7 x.
    t9 _ t7 y.
    t8 isNaN ifTrue: [t8 _ 0].
    t8 isInf ifTrue: [t8 _ t8 sign * 10000].
    t9 isNaN ifTrue: [t9 _ 0].
    t9 isInf ifTrue: [t9 _ t9 sign * 10000].
    self position: t8 @ t9.
    self keepOnScreen

What this block does:
Moves toward a sprite. An advantage over this script is that the direction can be used for something else.

/img/dropbox/BlockLibDiv2.png

^ Back to Scratch Blocks
^ Back to Contents
 

Last edited by YourLocalBlockLib (2011-09-09 05:14:11)


/img/dropbox/BlockLibraryTitle.png

Offline