home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / Cubed.dxr / 00114.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  4.4 KB  |  137 lines

  1. on findDistance pointA, pointB
  2.   hDistance = pointA[1] - pointB[1]
  3.   vDistance = pointA[2] - pointB[2]
  4.   finalDistance = sqrt((hDistance * hDistance) + (vDistance * vDistance))
  5.   return finalDistance
  6. end
  7.  
  8. on findAngle pointA, pointB
  9.   global watchThisAngle
  10.   xDist = pointB[1] - pointA[1]
  11.   yDist = pointB[2] - pointA[2]
  12.   if xDist <> 0 then
  13.     watchThisAngle = atan(1.0 * yDist / xDist) * 180 / PI
  14.     theAngle = atan(1.0 * yDist / xDist) * 180 / PI
  15.     if xDist > 0 then
  16.       theAngle = theAngle + 90
  17.     else
  18.       if xDist < 0 then
  19.         theAngle = theAngle - 90
  20.       else
  21.         if yDist < 0 then
  22.           theAngle = 0
  23.         else
  24.           if yDist > 0 then
  25.             theAngle = 180
  26.           end if
  27.         end if
  28.       end if
  29.     end if
  30.   else
  31.     if yDist < 0 then
  32.       theAngle = 0
  33.     else
  34.       if yDist > 0 then
  35.         theAngle = 180
  36.       end if
  37.     end if
  38.   end if
  39.   return theAngle
  40. end
  41.  
  42. on translateVector spriteLoc, spriteDepth
  43.   global fieldRotation, fieldOffset
  44.   swivelAim1 = fieldRotation + 90
  45.   if swivelAim1 > 360 then
  46.     swivelAim1 = swivelAim1 - 360
  47.   end if
  48.   swivelAim2 = fieldRotation
  49.   locY = cos(fieldRotation * PI / 180) * 1.5
  50.   locX = sin(fieldRotation * PI / 180) * -1.5
  51.   BGLocX = spriteLoc[1] + locX
  52.   BGLocY = spriteLoc[2] + locY
  53.   locY1 = cos(swivelAim1 * PI / 180) * -BGLocX
  54.   locX1 = sin(swivelAim1 * PI / 180) * BGLocX
  55.   locY2 = cos(swivelAim2 * PI / 180) * -BGLocY
  56.   locX2 = sin(swivelAim2 * PI / 180) * BGLocY
  57.   maxLoc = point(locX1, locY1) + point(locX2, locY2)
  58.   minLoc = maxLoc / 10
  59.   vectorDistance = findDistance(maxLoc, minLoc)
  60.   vectorAngle = findAngle(maxLoc, minLoc)
  61.   extrapolatedDist = vectorDistance * 100 / spriteDepth
  62.   finalY = cos(vectorAngle * PI / 180) * -extrapolatedDist
  63.   finalX = sin(vectorAngle * PI / 180) * extrapolatedDist
  64.   return point(finalX, finalY)
  65. end
  66.  
  67. on initializeStarField
  68.   global starfieldData, starReset, fieldRotation, SF_maxStars, SF_SO
  69.   starfieldData = []
  70.   starReset = 0
  71.   repeat with whichStar = 1 to SF_maxStars
  72.     whichSprite = SF_SO + whichStar - 1
  73.     starlength = random(20)
  74.     set the height of sprite whichSprite to starlength * starlength
  75.     set the width of sprite whichSprite to 5
  76.     sprite(whichSprite).rotation = random(360)
  77.     sprite(whichSprite).locZ = 10
  78.     set the locH of sprite whichSprite to 1000
  79.     set the foreColor of sprite whichSprite to random(255)
  80.     add(starfieldData, [0, 50 + random(50), 5, point(0, 0)])
  81.   end repeat
  82. end
  83.  
  84. on moveStarField
  85.   global starfieldData, starReset, fieldRotation, SF_maxStars, SF_SO, SF_starSpeed, SF_fieldRotation, SF_starSpread, starPaceLevel
  86.   starPaceLevel = starPaceLevel + SF_starSpread
  87.   if starPaceLevel > 100 then
  88.     starPaceLevel = starPaceLevel mod 100
  89.     starReset = starReset + 1
  90.   end if
  91.   if starReset > SF_maxStars then
  92.     starReset = 1
  93.   end if
  94.   repeat with wStar = 1 to SF_maxStars
  95.     wSprite = wStar + SF_SO - 1
  96.     if wStar = starReset then
  97.       starfieldData[wStar][3] = 5
  98.     end if
  99.     starfieldData[wStar][3] = starfieldData[wStar][3] - SF_starSpeed
  100.     if starfieldData[wStar][3] < 5 then
  101.       starfieldData[wStar][3] = 5
  102.     end if
  103.     if starfieldData[wStar][3] >= 10 then
  104.       locY = cos(starfieldData[wStar][1] * PI / 180) * -starfieldData[wStar][2]
  105.       locX = sin(starfieldData[wStar][1] * PI / 180) * starfieldData[wStar][2]
  106.       oldDrawPoint = starfieldData[wStar][4]
  107.       newDrawPoint = translateVector(point(locX, locY), starfieldData[wStar][3])
  108.       starfieldData[wStar][4] = newDrawPoint
  109.       streakLength = findDistance(oldDrawPoint, newDrawPoint)
  110.       streakAim = findAngle(oldDrawPoint, newDrawPoint)
  111.       visState = 1
  112.     else
  113.       starfieldData[wStar] = [random(360), random(150) + 250, 400, point(290, 220)]
  114.       locY = cos(starfieldData[wStar][1] * PI / 180) * -starfieldData[wStar][2]
  115.       locX = sin(starfieldData[wStar][1] * PI / 180) * starfieldData[wStar][2]
  116.       oldDrawPoint = point(-600, -600)
  117.       newDrawPoint = point(-600, -600)
  118.       streakLength = 1
  119.       streakAim = 1
  120.       visState = 1
  121.     end if
  122.     if streakLength > 100 then
  123.       streakLength = 100
  124.     end if
  125.     set the height of sprite wSprite to streakLength
  126.     if the timer > 10 then
  127.       set the blend of sprite wSprite to streakLength + 10
  128.     else
  129.       set the blend of sprite wSprite to 0
  130.     end if
  131.     set the width of sprite wSprite to streakLength - 20
  132.     sprite(wSprite).rotation = streakAim + 1
  133.     set the loc of sprite wSprite to oldDrawPoint + point(290, 220)
  134.     sprite(wSprite).visible = visState
  135.   end repeat
  136. end
  137.