home *** CD-ROM | disk | FTP | other *** search
- property w, hk, ball, ballRB, course, courseRB, movingBits, movingBitsRB, sky, arrow, snowflake, bitsMember, courseMember, styleMember, startNull, finishNull, upkey, downkey, leftkey, rightkey, spacekey, ballStopCheck, arrowY, arrowYmax, blackFade, pShadow, dirList, pTeleA, pTeleB, pTeleAll, pTelePos, pSpinner, pStyle, pProtected, pStartTime, pBallPos, pSpeed, pSpeedVector, pheight, pGroundPos, pGroundNorm, pGroundSurf, pHorizLevel, pVertLevel, pLevelMax, pPowerFactor, pInertia, pBGRots, pPacks, pBgT, pTimeStr, pPacksCollected, _DEBUG, prevCamMode
- global playMode, holeNum, styleNum, cam, camMode, camStart, camBuffer, gScore, gLives, gNewLevel, gMode
-
- on beginSprite me
- _DEBUG = 0
- gNewLevel = 0
- member(2).resetWorld()
- bitsMember = member(29)
- bitsMember.resetWorld()
- styleMember = member(26 + (styleNum * 4))
- styleMember.resetWorld()
- if holeNum > 21 then
- courseMember = 36 + holeNum
- else
- courseMember = 29 + styleNum + holeNum
- end if
- sprite(2).memberNum = courseMember
- w = member(courseMember)
- w.resetWorld()
- w.directionalPreset = #bottomLeft
- hk = member(11)
- hk.Initialize(w, 1, 0.025)
- put "Got to camera mode with holeNum " & holeNum && "styleNum " & styleNum
- camMode = camStart[holeNum]
- styles = ["Garden", "Stately", "Hanger", "Sushi", "Sea", "Modern", "Mountains"]
- pStyle = styles[styleNum]
- put "STYLE = " & pStyle
- createObjects()
- initVars()
- end
-
- on createObjects me
- hk.gravity = vector(0, -200, 0)
- startNull = w.model("start")
- finishNull = w.model("finish")
- createBall()
- pShadow = w.cloneModelFromCastmember("BallShadow", "BallShadow", bitsMember)
- pShadow.scale(1.5, 1.5, 1.5)
- if holeNum < 10 then
- mn = "Level0" & holeNum
- else
- mn = "Level" & holeNum
- end if
- course = w.model(mn)
- id = (holeNum mod 8) + 1
- course.addModifier(#meshDeform)
- courseRB = hk.makeFixedRigidBody(course.name, 0)
- courseRB.friction = 0.80000000000000004
- pPacks = []
- m = w.cloneModelFromCastmember("Box1", "BoxRK", bitsMember)
- w.model("BoxRK").addChild(m, #preserveParent)
- pPacks.add(m)
- m = w.cloneModelFromCastmember("Box2", "BoxFrosties", bitsMember)
- w.model("BoxFrosties").addChild(m, #preserveParent)
- pPacks.add(m)
- m = w.cloneModelFromCastmember("Box3", "BoxLoops", bitsMember)
- w.model("BoxLoops").addChild(m, #preserveParent)
- pPacks.add(m)
- m = w.cloneModelFromCastmember("Box4", "BoxRicicles", bitsMember)
- w.model("BoxRicicles").addChild(m, #preserveParent)
- pPacks.add(m)
- m = w.cloneModelFromCastmember("Box5", "BoxCoco", bitsMember)
- w.model("BoxCoco").addChild(m, #preserveParent)
- pPacks.add(m)
- m = w.cloneModelFromCastmember("Box6", "BoxCornflakes", bitsMember)
- w.model("BoxCornflakes").addChild(m, #preserveParent)
- pPacks.add(m)
- arrow = w.cloneModelFromCastmember("Arrow", "Arrow", bitsMember)
- arrow.transform = finishNull.getWorldTransform()
- arrow.translate(0, 500, 0)
- sky = w.cloneModelFromCastmember("SkyBoxBG", "SkyBox" & pStyle, styleMember)
- sky.scale(50.0)
- sky.translate(0, -10000, 0)
- pBgT = sky.getWorldTransform()
- if pStyle = "Snowy" then
- snowflake = []
- snowflake.add(w.cloneModelFromCastmember("SnowFlake", "SnowFlake", styleMember))
- tn = transform()
- tn.position = course.worldPosition
- snowflake[1].transform = tn
- cm = camStart[holeNum]
- if cm <> 1 then
- repeat with i = cm to 4
- snowflake[1].rotate(course.worldPosition, vector(0, 1, 0), -90, #world)
- end repeat
- end if
- repeat with i = 2 to 256
- snowflake.add(w.model("SnowFlake").clone("SnowFlake" & i))
- end repeat
- num = 1
- repeat with i = 1 to 8
- repeat with j = 1 to 8
- repeat with k = 1 to 4
- ran = 160 - random(320)
- xm = ((j * 200) - 600) * i
- ym = ((k * 200) - 200) * i
- zm = (i * -500) + 1600
- snowflake[num].translate(xm + ran, ym + ran, zm + ran)
- num = num + 1
- end repeat
- end repeat
- end repeat
- w.texture("SnowFlake").renderFormat = #rgba4444
- end if
- bf = w.newTexture("BlackFade", #fromCastMember, member("black"))
- w.camera[1].addOverlay(bf, point(0, 0), 0)
- w.camera[1].overlay[1].scale = 600
- w.camera[1].overlay[1].blend = 100
- blackFade = 100
- pTeleA = []
- pTeleB = []
- pTeleAll = []
- pSpinner = []
- c = w.model.count
- repeat with i = 1 to c
- m = w.model[i]
- if chars(m.name, 1, 7) = "Spinner" then
- if pSpinner.count = 0 then
- pSpinner.add(w.cloneModelFromCastmember("Spinner0", "Spinner", bitsMember))
- else
- pSpinner.add(pSpinner[1].clone("Spinner" & pSpinner.count))
- end if
- m.addChild(pSpinner[pSpinner.count], #preserveParent)
- next repeat
- end if
- if chars(m.name, 1, 8) = "Teleport" then
- if pTeleAll.count = 0 then
- tp = w.cloneModelFromCastmember("Teleport0", "Teleport", bitsMember)
- else
- tp = w.model("Teleport0").clone("Teleport" & pTeleAll.count)
- end if
- pTeleAll.add(m)
- m.addChild(tp, #preserveParent)
- if chars(m.name, 9, 9) = "G" then
- pTeleA.add(m)
- next repeat
- end if
- pTeleB.add(m)
- end if
- end repeat
- repeat with i = 1 to w.shader.count
- s = w.shader[i]
- sn = chars(s.name, 1, 3)
- if (sn = "Sky") and (s.texture[1] <> VOID) then
- s.diffuse = rgb(255, 255, 255)
- s.texture[1].renderFormat = #rgba8880
- s.textureRepeatList[1] = 0
- end if
- end repeat
- w.shader("ShadowShader").blend = 50
- w.texture("ShadowCol").renderFormat = #rgba4444
- if pStyle = "Space" then
- w.shader("CubeShader").blend = 23
- end if
- if pTeleAll.count > 0 then
- w.shader("TeleportShader").texture[1].renderFormat = #rgba4444
- end if
- if (pSpinner.count > 0) and (pStyle = "Snowy") then
- w.shader("TreeTrunkShader").ambient = rgb(86, 47, 12)
- w.texture("Tree").renderFormat = #rgba4444
- end if
- t = w.newTexture("GlowEdges", #fromCastMember, member("Glow"))
- w.shader("EdgesShader").diffuse = color(255, 255, 255)
- w.shader("EdgesShader").emissive = color(255, 255, 255)
- w.shader("EdgesShader").textureList[1] = t
- w.shader("EdgesShader").textureModeList[1] = #wrapSpherical
- end
-
- on createBall
- ball = w.cloneModelFromCastmember("Ball", "Ball", bitsMember)
- ball.addModifier(#meshDeform)
- ballRB = hk.makeMovableRigidBody(ball.name, 1, 1, #sphere)
- ballRB.restitution = 2
- ballRB.friction = 0.80000000000000004
- tn = startNull.getWorldTransform()
- ballRB.linearVelocity = vector(0, 0, 0)
- ballRB.angularVelocity = vector(0, 0, 0)
- ballRB.attemptMoveTo(tn.position, [vector(0, 1, 0), 0])
- end
-
- on initVars
- ballStopCheck = 10
- arrowYmax = 20
- arrowY = -arrowYmax
- xa = course.transform.xAxis
- za = course.transform.zAxis
- dirList = [-za, za, -xa, xa, -xa, xa, za, -za, za, -za, xa, -xa, xa, -xa, -za, za]
- bgRot = 0.29999999999999999
- pBGRots = [vector(bgRot, 0, 0), vector(0, 0, -bgRot), vector(-bgRot, 0, 0), vector(0, 0, -bgRot), vector(0, 0, -bgRot), vector(-bgRot, 0, 0), vector(0, 0, bgRot), vector(bgRot, 0, 0)]
- pHorizLevel = 0
- pVertLevel = 0
- pLevelMax = 200
- pInertia = 2
- pPowerFactor = 10
- playMode = "START"
- if gMode.demo then
- n = gMode.id
- else
- n = holeNum
- end if
- info = "COURSE " & n
- setVariable(sprite(1), "info", info)
- sprite(1).setVariable("levelNum", string(n))
- sprite(1).packs = 0
- pPacksCollected = 0
- pProtected = [#mode: 0, #startTime: 0]
- prevCamMode = camMode
- end
-
- on setTime
- return
- timeGone = the timer - pStartTime
- ticksToGo = (2 * 60 * 60) - timeGone
- if ticksToGo < 0 then
- sprite(1).setVariable("info", "Whoops! You ran out of time on level " & holeNum)
- sprite(1).setVariable("scoreinfo", "You scored " & gScore)
- moveFlash("endgame")
- playMode = "ENDGAME"
- else
- ntSecs = integer(ticksToGo / 60.0)
- ntMins = integer(ntSecs / 60.0)
- ntSecs = integer(ntSecs - (ntMins * 60.0))
- if ntSecs < 0 then
- ntMins = ntMins - 1
- ntSecs = ntSecs + 60
- end if
- if ntMins < 10.0 then
- ntMins = "0" & string(ntMins)
- end if
- if ntSecs < 10.0 then
- ntSecs = "0" & string(ntSecs)
- end if
- pTimeStr = string(ntMins) & ":" & string(ntSecs)
- setVariable(sprite(1), "time", pTimeStr)
- end if
- end
-
- on enterFrame
- spinStuff()
- CP = cam.worldPosition
- CP.y = arrow.transform.position.y
- arrow.pointAt(CP, vector(0, 1, 0))
- arrowY = arrowY + 1
- if arrowY >= arrowYmax then
- arrowY = -arrowYmax
- end if
- if arrowY >= 0 then
- arrow.translate(0, 6, 0)
- else
- arrow.translate(0, -6, 0)
- end if
- skyRotV = 0
- skyRotH = 0
- if playMode = "ACTIVE" then
- checkKeys()
- c = (camMode - 1) * 4
- moved = 0
- if upkey then
- if pVertLevel < pLevelMax then
- skyRotV = 1
- pVertLevel = pVertLevel + pInertia
- end if
- p = ((pLevelMax * 0.5) + pVertLevel) / pPowerFactor
- hitV = dirList[c + 1] * p
- moved = 1
- else
- if downkey then
- if pVertLevel > -pLevelMax then
- skyRotV = -1
- pVertLevel = pVertLevel - pInertia
- end if
- p = ((pLevelMax * 0.5) - pVertLevel) / pPowerFactor
- hitV = dirList[c + 2] * p
- moved = 1
- else
- if leftkey then
- if pHorizLevel < pLevelMax then
- skyRotH = 1
- pHorizLevel = pHorizLevel + pInertia
- end if
- p = ((pLevelMax * 0.5) + pHorizLevel) / pPowerFactor
- hitV = dirList[c + 3] * p
- moved = 1
- else
- if rightkey then
- if pHorizLevel > -pLevelMax then
- skyRotH = -1
- pHorizLevel = pHorizLevel - pInertia
- end if
- p = ((pLevelMax * 0.5) - pHorizLevel) / pPowerFactor
- hitV = dirList[c + 4] * p
- moved = 1
- end if
- end if
- end if
- end if
- if moved then
- ballRB.applyImpulse(hitV)
- end if
- if skyRotV <> 0 then
- sky.rotate(pBGRots[camMode] * skyRotV)
- else
- if skyRotH <> 0 then
- sky.rotate(pBGRots[camMode + 4] * skyRotH)
- end if
- end if
- setTime()
- else
- if playMode = "TELE" then
- if pheight > 300 then
- ballRB.linearVelocity = vector(0, 0, 0)
- ballRB.angularVelocity = vector(0, 0, 0)
- ballRB.attemptMoveTo(pTelePos.position, [vector(0, 1, 0), 0])
- playMode = "ACTIVE"
- end if
- setTime()
- end if
- end if
- if playMode = "ENDGAME" then
- go("endgame")
- return
- end if
- getInfo()
- if (pSpeed < 70) and (playMode = "ACTIVE") then
- inHole = checkHole()
- if inHole then
- endHole()
- ballRB.active = 0
- if holeNum = 12 then
- movingBitsRB[1].active = 0
- movingBitsRB[2].active = 0
- end if
- end if
- end if
- p = ball.worldPosition
- dist = (p.x * p.x) + (p.y * p.y) + (p.z * p.z)
- if dist > 100000000 then
- gLives = gLives - 1
- if gLives = 0 then
- if gMode.demo then
- n = gMode.id
- else
- n = holeNum
- end if
- sprite(1).setVariable("info", "Whoops! You ran out of lives on level " & n)
- sprite(1).setVariable("scoreinfo", "You scored " & gScore)
- moveFlash("endgame")
- playMode = "ENDGAME"
- else
- tn = startNull.getWorldTransform()
- put tn.position
- ballRB.linearVelocity = vector(0, 0, 0)
- ballRB.angularVelocity = vector(0, 0, 0)
- Res = ballRB.attemptMoveTo(tn.position, [vector(0, 1, 0), 0])
- if not Res then
- ballRB.position = tn.position
- end if
- sprite(1).setVariable("lives", string(gLives))
- sky.transform = pBgT
- pHorizLevel = 0
- pVertLevel = 0
- end if
- end if
- if (playMode = "START") or (playMode = "HOLED") then
- fadeHole()
- end if
- hk.step()
- if playMode = "ACTIVE" then
- checkTeles()
- checkSpinners()
- checkPacks()
- end if
- setShadow()
- if pStyle = "Snowy" then
- moveSnow()
- end if
- if keyPressed("q") then
- end if
- end
-
- on checkPacks
- pos = ball.worldPosition
- repeat with i = 1 to pPacks.count
- m = pPacks[i]
- if m.visibility = #front then
- v = pos - m.worldPosition
- dist = (v.x * v.x) + (v.y * v.y) + (v.z * v.z)
- if dist < 10000 then
- boxname = m.parent.name
- if boxname = "BoxCornflakes" then
- sprite(1).setVariable("pack1", "found")
- gLives = gLives + 2
- sprite(1).lives = gLives
- m.visibility = #none
- soundFX("munch", 3, 255)
- next repeat
- end if
- if (boxname = "BoxFrosties") and (pProtected.mode = 0) then
- sprite(1).setVariable("pack2", "found")
- pProtected = [#mode: 1, #startTime: _system.milliSeconds, #shield: m]
- m.scale(0.59999999999999998)
- soundFX("munch", 3, 255)
- next repeat
- end if
- if boxname = "BoxCoco" then
- gLives = gLives + 1
- sprite(1).lives = gLives
- sprite(1).setVariable("pack3", "found")
- m.visibility = #none
- soundFX("munch", 3, 255)
- next repeat
- end if
- if boxname = "BoxRK" then
- pPacksCollected = pPacksCollected + 3
- packScore = pPacksCollected * 350 * holeNum
- sprite(1).setVariable("packs", string(packScore))
- sprite(1).setVariable("pack4", "found")
- m.visibility = #none
- soundFX("munch", 3, 255)
- next repeat
- end if
- if boxname = "BoxLoops" then
- pPacksCollected = pPacksCollected + 1
- packScore = pPacksCollected * 350 * holeNum
- sprite(1).setVariable("packs", string(packScore))
- sprite(1).setVariable("pack5", "found")
- m.visibility = #none
- soundFX("munch", 3, 255)
- next repeat
- end if
- if boxname = "BoxRicicles" then
- pPacksCollected = pPacksCollected + 2
- packScore = pPacksCollected * 350 * holeNum
- sprite(1).setVariable("packs", string(packScore))
- sprite(1).setVariable("pack6", "found")
- m.visibility = #none
- soundFX("munch", 3, 255)
- end if
- end if
- end if
- end repeat
- end
-
- on moveSnow
- rate = float(the timer) / 500.0
- repeat with i = 1 to 256
- row = integer(i / 20) * rate
- col = i mod 20 * rate
- xm = sin(row) * cos(col) * 3
- zm = sin(col) * cos(row) * 2
- snowflake[i].translate(xm, -3, zm)
- if snowflake[i].transform.position.y < -100 then
- snowflake[i].translate(0, 700, 0)
- end if
- if camMode <> prevCamMode then
- snowflake[i].rotate(course.worldPosition, vector(0, 1, 0), 90, #world)
- end if
- end repeat
- prevCamMode = camMode
- end
-
- on setShadow
- if pheight > 0 then
- pShadow.worldPosition = ball.worldPosition
- pShadow.translate(0, -pheight + 20, 0)
- else
- pShadow.transform.position = vector(0, -100000, 0)
- end if
- end
-
- on getInfo
- pSpeedVector = ballRB.linearVelocity
- pSpeed = pSpeedVector.magnitude
- pBallPos = ball.worldPosition
- pheight = 0
- wpoint = pBallPos
- wdown = vector(0, -1, 0)
- opts = [#maxDistance: 80, #levelOfDetail: #detailed, #modelList: [course]]
- idetails = w.modelsUnderRay(wpoint, wdown, opts)
- if idetails.count > 0 then
- repeat with i = 1 to idetails.count
- mn = idetails[i].model.name
- pheight = idetails[i].distance
- pGroundPos = idetails[i].isectPosition
- pGroundNorm = idetails[i].isectNormal
- pGroundSurf = idetails[i].meshID
- exit repeat
- end repeat
- end if
- end
-
- on endHole
- timeScore = 7200 - (the timer - pStartTime)
- timeScore = integer(timeScore * 0.5)
- if timeScore < 0 then
- timeScore = 10
- end if
- if gMode.demo then
- n = gMode.id
- else
- n = holeNum
- end if
- timeScore = timeScore * holeNum
- sprite(1).setVariable("timeinfo", "Time remaining: " & pTimeStr & " = " & timeScore & " points")
- packScore = pPacksCollected * 350 * holeNum
- sprite(1).setVariable("packinfo", "Bonuses collected: " & pPacksCollected & " = " & packScore & " points")
- levelScore = timeScore + packScore
- gScore = gScore + levelScore
- put "endHole gScore = " & gScore
- sprite(1).setVariable("scoreinfo", "Level " & n & " Score = " & levelScore & RETURN & " Total Score = " & gScore)
- soundFX("ground", 2, 255)
- playMode = "HOLED"
- end
-
- on checkHole
- dist = ball.worldPosition.distanceTo(finishNull.worldPosition)
- if dist < 150 then
- ballStopCheck = ballStopCheck - 1
- else
- ballStopCheck = 10
- end if
- if ballStopCheck <= 0 then
- return 1
- else
- return 0
- end if
- end
-
- on fadeHole
- if playMode = "HOLED" then
- blackFade = blackFade + 1
- if blackFade = 100 then
- playMode = "FINISH"
- go(the frame + 1)
- end if
- else
- blackFade = blackFade - 1
- if blackFade = 0 then
- pStartTime = the timer
- playMode = "ACTIVE"
- end if
- end if
- w.camera[1].overlay[1].blend = blackFade
- end
-
- on spinStuff
- repeat with i = 1 to pSpinner.count
- pSpinner[i].rotate(0, -20, 0)
- end repeat
- repeat with i = 1 to pTeleAll.count
- pTeleAll[i].rotate(0, 40, 0)
- end repeat
- w.shader("EdgesShader").textureTransformList[1].rotate(0, 0, 0.20000000000000001)
- end
-
- on checkTeles
- if pProtected.mode then
- return
- end if
- repeat with i = 1 to pTeleB.count
- v = pBallPos - pTeleB[i].worldPosition
- dist = (v.x * v.x) + (v.y * v.y) + (v.z * v.z)
- if dist < 20000 then
- pTelePos = pTeleA[1].getWorldTransform()
- pTelePos.position.y = pTelePos.position.y + 300
- ballRB.linearVelocity = ballRB.linearVelocity * 0.20000000000000001
- ballRB.applyImpulse(vector(0, 400, 0))
- playMode = "TELE"
- end if
- end repeat
- end
-
- on checkSpinners
- if pProtected.mode then
- tm = _system.milliSeconds - pProtected.startTime
- pProtected.shield.worldPosition = ball.worldPosition
- pProtected.shield.translate(0, 100, 0)
- if tm < 30000 then
- return
- end if
- pProtected.shield.visibility = #none
- pProtected.mode = 0
- end if
- repeat with i = 1 to pSpinner.count
- v = pBallPos - pSpinner[i].worldPosition
- dist = (v.x * v.x) + (v.y * v.y) + (v.z * v.z)
- if dist < 30000 then
- temp = v.x
- v.x = -v.z
- v.z = temp
- v.y = 0
- vm = (301 - dist) / 300
- v = v * vm
- ballRB.applyImpulse(v)
- end if
- end repeat
- end
-
- on checkKeys
- leftkey = 0
- rightkey = 0
- downkey = 0
- upkey = 0
- spacekey = 0
- if keyPressed(123) then
- leftkey = 1
- end if
- if keyPressed(124) then
- rightkey = 1
- end if
- if keyPressed(125) then
- downkey = 1
- end if
- if keyPressed(126) then
- upkey = 1
- end if
- if keyPressed(" ") then
- spacekey = 1
- end if
- if _DEBUG then
- if keyPressed("s") or keyPressed("S") then
- if soundBusy(1) then
- sound(1).stop()
- else
- sound(1).play(member("music"))
- end if
- end if
- if keyPressed("1") then
- gNewLevel = 1
- playMode = "HOLED"
- else
- if keyPressed("2") then
- gNewLevel = 4
- playMode = "HOLED"
- else
- if keyPressed("3") then
- gNewLevel = 7
- playMode = "HOLED"
- else
- if keyPressed("4") then
- gNewLevel = 10
- playMode = "HOLED"
- else
- if keyPressed("5") then
- gNewLevel = 13
- playMode = "HOLED"
- end if
- end if
- end if
- end if
- end if
- end if
- end
-
- on endSprite me
- hk.shutDown()
- w.resetWorld()
- end
-