I notice now it's kind a jittery as the value of change is the exact value of the difference between the x values of being shifted.
I think a line with a higher fidelity would give smoother results.
Script in the card script, there's a button to take you there. But why not show it here?
Code: Select all
local lastSeconds --// used for getting more randomseed values than the seconds supplies
local mountainPoints   --// holds the mountain points from InitMountainPoints to carry over to CreateMountainLine
local flyDir --// will carry our checkbox choice over to the card script and inform PointShift of travel direction
Code: Select all
on CheckShift tDir
   if tDir is not empty then put tDir into flyDir
   if the hilite of button flyDir is true then
      pointsShift flyDir
      send checkShift to card (the currentCard of this stack) in 30 milliseconds
   end if
end CheckShiftCode: Select all
--// more mountain variation while quickly pressing Create button with changes to randomSeeD
on InitSeed
   if the seconds is lastSeconds then
      add random(2) to lastSeconds
   else
      put the seconds into  lastSeconds
   end if
   set the randomSeed to lastSeconds
end InitSeedCode: Select all
on ResetMountain
   set the points of graphic "mountain" to the ogPoints of of graphic "mountain"
   set the loc of graphic "mountain" to the loc of graphic "mountainFrame"
end ResetMountainCode: Select all
--// create  mountain range points across the width of the screen+200
on InitMountainPoints
   put the width of this stack into W
   put the height of this stack into H
   put H/2 into centerY
   put 0,centerY into mountainPoints
   put 0 into x
   put the height of this stack/2 into y
   repeat with i = 1 to 100
      add i+ random(50) to x
      put centerY+random(5)-random(5) into y
      put cr  & x  & comma & y after mountainPoints
      add 10+random(150) to x
      put cr  & x  & comma & y after mountainPoints
   end repeat
end InitMountainPointsCode: Select all
on CreateMountainLine tName
   if exists (graphic tName) then delete graphic tName
   InitSeed
   InitMountainPoints
   create graphic 
   set the style of the last graphic to "line"
   set the points of the last graphic to mountainPoints
   set the width of the last graphic to the width of graphic "mountainFrame"+200
   set the loc of the last graphic to the loc of graphic "mountainFrame"
   set the height of the last graphic to 25+random(60)
   set the OGPoints of the last graphic to mountainPoints
   set the ogLoc of the last graphic to the loc of the last graphic
   set the ogBottom of the last graphic to the bottom of the last graphic
   set the name of the last graphic to tName
end CreateMountainLineCode: Select all
on ArrowKey tKey
   switch tKey
      case "left"
         PointsShift tKey
         break
      case "right"
         PointsShift tKey
         break
   end switch
end ArrowKeyThe apparent motion is the inverse of the direction we are traveling, or the arrow key we pressed or checkbox selected
Code: Select all
on PointsShift tDir
   put the points of graphic "mountain" into tPOints
   put the loc of graphic "Mountain" into mmxy
   switch tDir
      case "left"
         if item 1 of line -1 of tPoints  > the right of graphic "MountainFrame" then
            put item 1 of line -1 of tPoints -item 1 of line -2 of tPoints into xdif
            put item 2 of line -1 of tPoints -item 2 of line -2 of tPoints into ydif
            put item 1 of line 1 of tpoints - xDif into newX
            put item 2 of line 1 of tpoints - yDif into newY
            put line 1 to -2 of tPoints into newPoints
            put newx & comma & newY & cr before newPoints
         end if
         break
      case "right"
         if item 1 of line 1 of tPoints  < the left of graphic "MountainFrame" then
            put item 1 of line 1 of tPoints -item 1 of line 2 of tPoints into xdif
            put item 2 of line 1 of tPoints -item 2 of line 2of tPoints into ydif
            put item 1 of line -1 of tpoints - xDif into newX
            put item 2 of line -1 of tpoints - yDif into newY
            put line 2 to -1 of tPoints into newPoints
            put cr & newx & comma & newY  after  newPoints
         end if
         break
   end switch
   lock screen
   set the points of graphic "mountain" to newPoints
   set the loc of graphic "Mountain" to the ogLoc of graphic "Mountain"
   set the bottom of graphic "Mountain" to the ogBottom of graphic "Mountain"
   unlock screen
end PointsShiftCode: Select all
on mouseUp
   set the hilite of button "Right" to false
   if the hilite of me is true then CheckShift (the short Name of me)
end mouseUp