|
|
|
Star Parent Script
Added on 6/28/2000
|
Used to create a dynamic 3d Starfield
Download PC Source Download Mac Source
----------------------------------------
--3D stars parent script
-- Barry Swan, 28/06/2000
-- gerbil@theburrow.co.uk
-- http://www.theburrow.co.uk
-- All rights reserved
----------------------------------------
property pSN
property pX, pY, pZ
property pSpeed
property pCenterX, pCenterY
property pMaxX, pMaxY
property pScale
on new me, tSN
-- Create a new star
pSN = tSN
-- Store some info about the stage size
pCenterX = (the stageRight - the stageLeft) / 2
pCenterY = (the stageBottom - the stageTop) / 2
pMaxX = the stageRight
pMaxY = the stageBottom
-- Set up the new star with random positions
me.Reset()
pZ = random(1000) + 1000
-- Return the new star object
return me
end
on updateStar me, tDX, tDY
-- Update the star position
pZ = pZ - pSpeed
if NOT voidP(tDX) then
pX = pX + tDX
pY = pY + tDY
end if
-- If star is too close then reset
if pZ < 20 then me.reset()
-- Find screen position of star
tX = (pX * pCenterX / pZ) + pCenterX
tY = (pY * pCenterY / pZ) + pCenterY
-- If star is outside the screen then reset
if tX < 0 OR tX > pMaxX OR tY < 0 OR tY > pMaxY then me.Reset()
-- Find scaling factor for size of star onscreen
tScale = pScale / pZ
-- Draw the star sprite
sprite(pSN).loc = point(tX, tY)
sprite(pSN).width = tScale
sprite(pSN).height = tScale
end
on Reset me
-- Create new parameters for star
pSpeed = random(5) + 5
pScale = random(5) * 2000
pX = random(3001) - 1501
pY = random(3001) - 1501
pZ = 2000
end
|
|