top of script window
petals around the rose code snippet | show it | return |
property  spriteNum, rollAngle, rollNum, rollsLeft

global gSpot, gSpot45, gSpot45half

on new me, spr
  set spriteNum = spr
  set the constraint of sprite spriteNum = spriteNum + 5
  reset
  return me
end

on reset me
  set rollsLeft = 15 + random(40)
  set the loc of sprite spriteNum = point( random(the left of sprite (spriteNum + 5)¬
       + the width of sprite (spriteNum + 5)), ¬
       random(the top of sprite (spriteNum + 5) + ¬
       the height of sprite (spriteNum + 5)))
end

on roll me
  
  set rollsLeft = rollsLeft - 1
  if rollsLeft > 0 then
    set rollAngle = random(4)    
    if rollAngle < 3 then
      set the memberNum of sprite spriteNum = 1
    else
      set the memberNum of sprite spriteNum = 2
    end if
    
    set newLoc = the loc of sprite spriteNum + ¬
       point(8 - random(17), 8 - random(17))
       
    set the loc of sprite spriteNum = newLoc   
    set rollNum = random(6)
    setSpots 
  end if
end

on noBumpSprites me
  repeat with i = 1 to 5
    if i = spriteNum then next repeat
    if sprite spriteNum intersects 1 then return 0
  end repeat
  return 1
end


on setSpots me
  
  set baseSprite = 5 + (spriteNum * 6)
  set dSpriteLoc = the loc of sprite spriteNum
  
  case rollNum of       
    1: 
      set the loc of sprite baseSprite = dSpriteLoc
      
      repeat with i = 1 to 5
        set the loch of sprite (baseSprite + i) = - 50
      end repeat
            
    2:
      case rollAngle of
        1:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot, gSpot)
          
        2:
          set the loc of sprite baseSprite  = dSpriteLoc + point( gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point( - gSpot, gSpot)
          
        3:
          set the loc of sprite baseSprite  = dSpriteLoc + point(  0, gSpot45)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  0, -gSpot45)
        4:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point( gSpot45, 0)
          
      end case
      
      repeat with i = 2 to 5
        set the loch of sprite (baseSprite + i) = - 50
      end repeat
           
    3: 
      case rollAngle of
        1:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot, gSpot)
          
        2:
          set the loc of sprite baseSprite  = dSpriteLoc + point( gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point( - gSpot, gSpot)
          
        3:
          set the loc of sprite baseSprite  = dSpriteLoc + point(  0, gSpot45)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  0, -gSpot45)
        4:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point( gSpot45, 0)
          
      end case
      set the loc of sprite baseSprite + 2 = dSpriteLoc
      
      repeat with i = 3 to 5
        set the loch of sprite (baseSprite + i) = - 50
      end repeat
           
    4:              
      if rollAngle < 3 then
        set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
        set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot, -gSpot)
        set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  gSpot, gSpot)
        set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  -gSpot,  gSpot)       
      else
        set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
        set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot45, 0)
        set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  0, gSpot45)
        set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  0, -gSpot45)
      end if
      
      repeat with i = 4 to 5
        set the loch of sprite (baseSprite + i) = - 50
      end repeat
      
    5:
      if rollAngle < 3 then
        set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
        set the loc of sprite baseSprite + 1 = dSpriteLoc + point(   gSpot, -gSpot)
        set the loc of sprite baseSprite + 2 = dSpriteLoc + point(   gSpot, gSpot)
        set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  -gSpot,  gSpot)     
      else
        set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
        set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot45, 0)
        set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  0,  gSpot45)
        set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  0, -gSpot45)
      end if
      
      set the loc of sprite baseSprite + 4 = dSpriteLoc
      set the loch of sprite baseSprite + 5 = - 50
      
      
    6: 
      case rollAngle of
        1:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot, -gSpot)
          set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  gSpot, gSpot)
          set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  -gSpot,  gSpot)
          set the loc of sprite baseSprite + 4 = dSpriteLoc + point(  -gSpot,  0)
          set the loc of sprite baseSprite + 5 = dSpriteLoc + point(  gSpot,  0)
        2:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot, -gSpot)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot, -gSpot)
          set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  gSpot, gSpot)
          set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  -gSpot,  gSpot)
          set the loc of sprite baseSprite + 4 = dSpriteLoc + point(  0,  gSpot)
          set the loc of sprite baseSprite + 5 = dSpriteLoc + point(  0,   - gSpot)
          
        3:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot45, 0)
          set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  0, gSpot45)
          set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  0, -gSpot45)
          set the loc of sprite baseSprite + 4 = dSpriteLoc + point( gSpot / 2,  gSpot45Half)
          set the loc of sprite baseSprite + 5 = dSpriteLoc + point(  -gSpot / 2, - gSpot45Half)
          
        4:
          set the loc of sprite baseSprite  = dSpriteLoc + point( -gSpot45, 0)
          set the loc of sprite baseSprite + 1 = dSpriteLoc + point(  gSpot45, 0)
          set the loc of sprite baseSprite + 2 = dSpriteLoc + point(  0, gSpot45)
          set the loc of sprite baseSprite + 3 = dSpriteLoc + point(  0, -gSpot45)
          set the loc of sprite baseSprite + 4 = dSpriteLoc + point( gSpot45Half, gSpot / 2)
          set the loc of sprite baseSprite + 5 = dSpriteLoc + point(  - gSpot45Half, - gSpot / 2 ) 
          
      end case   
  end case
  updateStage
end
This parent script provides the functionality for each die created. A basic die is a simple graphic of the shap of the die, and then the dots are added as single sprites for each dot. The positions of the dots are recalcuated depending on the rotation of the die and its screen position.

lingo era = v5 Not so clear to see how, but it works!