00001
00002 Global levelName$, remainingTime, addLetterTime, levelIndex
00003 Global scroller, FPS, CurFPS
00004 Global blockX, blockY ; nr of blocks left-right / nr of blocks begin-finishline
00005 Global speedZ#, speedX#, gravity# ; player movement
00006 Global camera, light, sphere, sphereTex, shadow, hudCube, hudTexture, sky, skyTex, logoCube, logoTex, finishLine
00007 Global arrowRightTex, arrowLeftTex, titleInfo, titleInfoTex, speedMeter
00008 Global digit_1, digit_2, digit_3, tolleWurst1, tolleWurst2, timeOver
00009 Global upFlag, downFlag, oldTime, fSin, fZero2One#, doFinishFlag, logoF, scrollerAngle#
00010 Global sndDeath, sndStart, sndCollect, sndFallDown, soundPlayingFlag, sndBounceUp, sndBounceDown
00011 Global chnBackground, chnDeath, hasJoyStick
00012 Const state_isRunning=1, state_intro=2, state_levelFinish=3
00013 Const state_prepareNextLevel=4, state_death=5, state_pause=6
00014 Const TERRAIN_Z_SCALE = 5
00015 Global gameState = state_intro, musicIsPlaying = True
00016 Global START_LEVEL = 1, MAX_LEVEL = 5
00017
00018 Dim FPS_overTime(99)
00019 Dim terrain(1) ; two terrains
00020
00021 Type block
00022 Field col
00023 Field cube
00024 End Type
00025
00026 Type letter
00027 Field pivot
00028 Field mesh1
00029 Field mesh2
00030 Field char$
00031 Field collected
00032 Field freq
00033 End Type
00034
00035 Type wurst
00036 Field pivot
00037 End Type
00038
00039 DebugLog "prg start"
00040 AppTitle "Wurstritt"
00041
00042 Include "3DTextLib\GG_3D_Text_Library.bb"
00043
00044 Graphics3D 800, 600, 0, 3;1
00045 SetBuffer BackBuffer()
00046 FPS = CreateTimer(60)
00047
00048 loadMedia()
00049
00050 ; do we got a joystick?
00051 hasJoyStick = JoyType()
00052 If (hasJoyStick)
00053 DebugLog "joystick found. type = " + hasJoyStick
00054 Else
00055 DebugLog "no joystick found."
00056 EndIf
00057
00058 While Not KeyHit(1)
00059
00060 FPS_Start = MilliSecs()
00061
00062 ; DEBUG-------------------------------------------
00063 If (KeyHit(38)) ; l
00064 loadLevel(4)
00065 DebugLog "levelName: "+levelName
00066 DebugLog "remainingTime: "+remainingTime
00067 DebugLog "blockX: "+blockX
00068 DebugLog "blockY: "+blockY
00069 resetLevel()
00070 EndIf
00071
00072 If (KeyHit(19)) ; r
00073 resetlevel()
00074 EndIf
00075
00076 If (KeyHit(20)) ; t
00077 displayTitleScreen()
00078 EndIf
00079
00080 If (KeyDown(17)) ; w
00081 displayLevelFinish()
00082 EndIf
00083
00084
00085 If (False);MouseHit(1))
00086 pickE = CameraPick(camera, MouseX(), MouseY())
00087 If (pickE=0)
00088 DebugLog "cannot pick this"
00089 Else
00090 DebugLog "pick: "+EntityX(pickE)+" "+EntityY(pickE)+" "+EntityZ(pickE)
00091 EndIf
00092 EndIf
00093
00094 If (KeyHit(2)) ; "1"
00095 START_LEVEL = 1
00096 DebugLog "START_LEVEL = 1"
00097 EndIf
00098 If (KeyHit(3)) ; "2"
00099 START_LEVEL = 2
00100 DebugLog "START_LEVEL = 2"
00101 EndIf
00102 If (KeyHit(4)) ; "3"
00103 START_LEVEL = 3
00104 DebugLog "START_LEVEL = 3"
00105 EndIf
00106 ; END DEBUG-------------------------------------------
00107
00108 ; global numbers
00109 fSin = (fSin + 1) Mod 359
00110 fZero2One = fZero2One + 0.01
00111 If (fZero2One >= 1) Then fZero2One = 0
00112
00113 ; check user input
00114 ; keyboard
00115 inputLeft = KeyDown(203)
00116 inputRight = KeyDown(205)
00117 inputUp = KeyDown(200)
00118 inputDown = KeyDown(208)
00119 inputJump = KeyHit(29) ; ctrl left
00120 ; joystick
00121 If (hasJoyStick)
00122 Select JoyYDir(0)
00123 Case -1; up
00124 inputUp = True
00125 Case 1 ; down
00126 inputDown = True
00127 End Select
00128 Select JoyXDir(0)
00129 Case -1; left
00130 inputLeft = True
00131 Case 1 ; right
00132 inputRight = True
00133 End Select
00134 If ((JoyHit(1, 0)) Or (JoyHit(2, 0))) ; jump
00135 inputJump = True
00136 EndIf
00137 EndIf
00138
00139 If (KeyHit(31)) ; s (background sound on/off)
00140 If (musicIsPlaying)
00141 changeScroller("SOUND OFF")
00142 PauseChannel(chnBackground)
00143 musicIsPlaying = False
00144 Else
00145 Select chnTune
00146 Case 0
00147 changeScroller("NOW PLAYING: " + "DELTA")
00148 chnBackground = PlayMusic("sound\delta.mod")
00149 Case 1
00150 changeScroller("NOW PLAYING: " + "SANXION")
00151 chnBackground = PlayMusic("sound\SANXION.mod")
00152 Case 2
00153 changeScroller("NOW PLAYING: " + "AUF WIEDERSEHEN MONTY")
00154 chnBackground = PlayMusic("sound\aufweidersehnmonty.mod")
00155 Case 3
00156 changeScroller("NOW PLAYING: " + "BUBBLE BOBBLE")
00157 chnBackground = PlayMusic("sound\bubblebobble.mod")
00158 Case 4
00159 changeScroller("NOW PLAYING: " + "COMMANDO")
00160 chnBackground = PlayMusic("sound\commando.mod")
00161 End Select
00162 chnTune = (chnTune + 1) Mod 5
00163 musicIsPlaying = True
00164 ChannelVolume chnBackground, 0.1
00165 EndIf
00166 EndIf
00167
00168 ; main game state machine
00169 Select (gameState)
00170
00171 Case state_isRunning
00172 If (inputJump And upFlag=False)
00173 If (EntityCollided(sphere, 2))
00174 If (EntityY(sphere) > 0.4)
00175 ; jump up!
00176 upFlag = True
00177 PlaySound sndBounceUp
00178 EndIf
00179 EndIf
00180 EndIf
00181 If (upFlag=True And downFlag=False)
00182 If (EntityY(sphere) < 2)
00183 gravity = 0.1
00184 Else
00185 ; end of jump up
00186 downFlag = True
00187 EndIf
00188 EndIf
00189 If (downFlag=True)
00190 gravity = -0.06
00191 If (EntityY(sphere) < 0.5)
00192 If (EntityCollided(sphere, 2))
00193 ; touching ground
00194 upFlag = False
00195 downFlag = False
00196 PlaySound sndBounceDown
00197 upFlag2 = True
00198 EndIf
00199 EndIf
00200 EndIf
00201 If (upFlag2=True And downFlag2=False)
00202 If (EntityY(sphere) < 0.8)
00203 ; rebounce
00204 gravity = 0.08
00205 Else
00206 downFlag2 = True
00207 EndIf
00208 EndIf
00209 If (downFlag2=True)
00210 gravity = -0.06
00211 If (EntityY(sphere) < 0.5)
00212 ; touching ground second
00213 upFlag2 = False
00214 downFlag2 = False
00215 PlaySound sndBounceDown
00216 EndIf
00217 EndIf
00218
00219 If (inputUp) ; up
00220 If (speedZ < 0.2) Then speedZ = speedZ + 0.002
00221 EndIf
00222 If (inputDown) ; down
00223 If (speedz > 0) Then speedZ = speedZ - 0.002
00224 EndIf
00225 If (speedZ > 0)
00226 If (inputLeft) ; left
00227 If (speedZ > 0.2)
00228 speedX = speedX - 0.007
00229 Else
00230 speedX = speedX - 0.006
00231 EndIf
00232 EndIf
00233 If (inputRight) ; right
00234 If (speedZ > 0.2)
00235 speedX = speedX + 0.007
00236 Else
00237 speedX = speedX + 0.006
00238 EndIf
00239 EndIf
00240 Else
00241 speedX = 0
00242 EndIf
00243
00244 If (KeyHit(25)) ; p (pause)
00245 changeScroller("PRESS P TO CONTINUE")
00246 gameState = state_pause
00247 EndIf
00248
00249
00250 ; slow down left/right
00251 speedX = speedX * 0.9
00252
00253 ; move objects
00254 updateLevel()
00255 displayHUD()
00256 displayScroller()
00257
00258 ; check death
00259 If (remainingTime < 0)
00260 gameState = state_death
00261 EndIf
00262
00263 ; check finishline -> change game state
00264 If (EntityZ(sphere) > EntityZ(finishLine))
00265 gameState = state_levelFinish
00266 EndIf
00267
00268 Case state_pause
00269 displayScroller()
00270 If (KeyHit(25)) ; p (un-pause)
00271 gameState = state_isRunning
00272 EndIf
00273
00274 Case state_intro
00275 If (musicIsPlaying)
00276 ResumeChannel chnBackground
00277 ChannelVolume chnBackground, 0.3
00278 EndIf
00279 ShowEntity logoCube
00280 ShowEntity titleInfo
00281 HideEntity finishLine
00282 HideEntity sphere
00283 HideEntity sky
00284 HideEntity speedMeter
00285 deleteTypes()
00286 displayTitleScreen()
00287 displayScroller()
00288 ; hide HUD
00289 PositionEntity hudCube, EntityX(camera), EntityY(camera), EntityZ(camera)-10
00290 If (inputJump)
00291 levelIndex = START_LEVEL
00292 gameState = state_prepareNextLevel
00293 ChannelVolume chnBackground, 0.1
00294 HideEntity logoCube
00295 HideEntity titleInfo
00296 ShowEntity finishLine
00297 ShowEntity sphere
00298 ShowEntity sky
00299 ShowEntity speedMeter
00300 EndIf
00301
00302 Case state_levelFinish
00303 ; move objects and nice text
00304 displayLevelFinish()
00305 updateLevel()
00306 displayHUD()
00307 ; slow down player
00308 speedZ = speedZ * 0.97
00309 speedx = speedX = 0.9
00310 gravity = -0.06
00311 ; show at last 3 second nice text
00312 If (levelFinishedTimer = 0)
00313 levelFinishedTimer = MilliSecs()
00314 changeScroller("PRESS KEY TO CONTINUE")
00315 EndIf
00316 If (levelFinishedTimer + 2900 < MilliSecs())
00317 If (levelFinishedTimer + 3000 > MilliSecs())
00318 FlushKeys()
00319 endif
00320 endif
00321 If (levelFinishedTimer + 3000 < MilliSecs())
00322 displayScroller()
00323 If (0 <> GetKey() Or inputJump)
00324 gameState = state_prepareNextLevel
00325 levelFinishedTimer = 0
00326 EndIf
00327 EndIf
00328
00329 Case state_prepareNextLevel
00330 ; after intro or levelFinish load next level
00331 loadLevel(levelIndex)
00332 PlaySound(sndStart)
00333 resetLevel()
00334 ; 3..2..1
00335 countDown()
00336 changeScroller("LEVEL " + levelIndex + ": " + Upper(levelName))
00337 levelIndex = levelIndex + 1
00338 If (levelIndex = MAX_LEVEL) Then levelIndex = START_LEVEL
00339 gameState = state_isRunning
00340
00341 Case state_death
00342 ; listen to death-sound
00343 PauseChannel chnBackground
00344 If (Not ChannelPlaying(chnDeath))
00345 chnDeath = PlaySound(sndDeath)
00346 EndIf
00347 If (deathTimer = 0)
00348 deathTimer = MilliSecs()
00349 EndIf
00350 displayDeath()
00351 If (deathTimer + 7000 < MilliSecs())
00352 gameState = state_intro
00353 HideEntity timeOver
00354 deathTimer = 0
00355 EndIf
00356 End Select
00357
00358 UpdateWorld
00359 RenderWorld
00360 Color 255,255,255
00361 Text 20,80, "FPS: " + CurFPS
00362
00363 ; reset user input
00364 inputLeft = False
00365 inputRight = False
00366 inputUp = False
00367 inputDown = False
00368 inputJump = False
00369 Flip
00370 WaitTimer(FPS)
00371
00372 FPS_overTime(FPS_overTimeIndex) = 1000.0 / (MilliSecs() - FPS_Start)
00373 FPS_overTimeIndex = (FPS_overTimeIndex + 1) Mod 100
00374 For i=0 To 99
00375 FPS_overTimeSum = FPS_overTimeSum + FPS_overTime(i)
00376 next
00377 CurFPS = FPS_overTimeSum / 100
00378 FPS_overTimeSum = 0
00379 Wend
00380
00381 DebugLog "prg end"
00382 End
00383
00384 Function changeScroller(scrollerText$)
00385 Local myLen = Len(scrollerText)
00386 ShowEntity scroller
00387 scrollerAngle = 360
00388 ; init text
00389 GG_Change_Text(scroller, scrollerText)
00390 RotateEntity scroller, 0, -20, 0
00391 End Function
00392
00393 Function displayScroller()
00394 If (scrollerAngle <= 0)
00395 HideEntity scroller
00396 Else
00397 PositionEntity scroller, 2, 5, EntityZ(camera) + 26
00398 scrollerAngle = scrollerAngle - 0.8
00399 RotateEntity scroller, 0, scrollerAngle, 0
00400 EndIf
00401 End Function
00402
00403 Function displayDeath()
00404 ShowEntity timeOver
00405 PositionEntity timeOver, 2, 2, EntityZ(camera)+4
00406 End Function
00407
00408 Function displayHUD()
00409 ; time + wurst-letter + FPS
00410 PositionEntity hudCube, EntityX(camera), EntityY(camera)+1.42, EntityZ(camera)+2
00411 SetBuffer TextureBuffer(hudTexture)
00412 ClsColor 0, 0, 0
00413 Cls
00414 Color 255, 255, 255
00415 Text 0, 1, "TIME"
00416 Text 40, 1, remainingTime
00417 For l.letter = Each letter
00418 If (l\collected)
00419 Select l\char
00420 Case "w" Text 75, 1, "W"
00421 Case "u" Text 86, 1, "U"
00422 Case "r" Text 97, 1, "R"
00423 Case "s" Text 108, 1, "S"
00424 Case "t" Text 119, 1, "T"
00425 End Select
00426 EndIf
00427 Next
00428 SetBuffer BackBuffer()
00429 EntityTexture hudCube, hudTexture
00430 Color 0, 0, 0
00431 If (gameState = state_isRunning)
00432 If ((MilliSecs() - oldTime) > 1000)
00433 oldTime = MilliSecs()
00434 remainingTime = remainingTime - 1
00435 EndIf
00436 EndIf
00437 ; speedmeter
00438 ScaleSprite speedMeter, speedZ * 12.0 + 0.1, 0.2
00439 PositionEntity speedMeter, -3, 5.2, EntityZ(camera) + 5
00440 End Function
00441
00442 Function displayTitleScreen()
00443 PositionEntity camera, 0, 3, -6
00444 logoF = (logoF + 5) Mod 359
00445 MoveEntity logoCube, 0, 0, Sin(logoF)*0.1
00446 PositionEntity titleInfo, 0, 2.5, -3
00447 End Function
00448
00449 Function displayLevelFinish()
00450 ; display nice moving text
00451 ShowEntity tolleWurst1
00452 ShowEntity tolleWurst2
00453 PositionEntity tolleWurst1, 2.25, 3.3-Cos(fSin)/2, EntityZ(camera)+Cos(fSin)*6.3+10
00454 PositionEntity tolleWurst2, 2.1, 2-Cos(fSin)/3, EntityZ(camera)+Sin(fSin)*6.3+10
00455 End Function
00456
00457 Function countDown()
00458 updateLevel()
00459 c = CreateCube()
00460 ScaleEntity c, 0.5, 0.5, 0.01
00461 PositionEntity c, blockX/2, 2.5, -1
00462 EntityTexture c, digit_3
00463 t = MilliSecs()
00464 While (t+1000 > MilliSecs())
00465 RenderWorld
00466 Flip
00467 Wend
00468 EntityTexture c, digit_2
00469 t = MilliSecs()
00470 While (t+1000 > MilliSecs())
00471 RenderWorld
00472 Flip
00473 Wend
00474 EntityTexture c, digit_1
00475 t = MilliSecs()
00476 While (t+1000 > MilliSecs())
00477 RenderWorld
00478 Flip
00479 Wend
00480 FreeEntity c
00481 FreeTexture cTex
00482 End Function
00483
00484 Function updateLevel()
00485 ; move cam
00486 PositionEntity camera, blockX/2, 2, EntityZ(sphere)-3
00487 ; move player
00488 TranslateEntity sphere, speedX, gravity, speedZ
00489 TurnEntity sphere, speedZ*100, 0, -speedX*10
00490 ; turn sky
00491 TurnEntity sky, -0.05, 0 ,0
00492 PositionEntity sky, EntityX(camera), EntityY(camera), EntityZ(camera)
00493 ; move letters
00494 For l.letter = Each letter
00495 dif = EntityZ(l\pivot) - EntityZ(Camera)
00496 ; letter near enough?
00497 If (dif < 60)
00498 MoveEntity l\pivot, Sin(fSin+l\freq)/50, 0, 0
00499 TurnEntity l\mesh2, 0, 1, 0
00500 ; letter collected by player?
00501 If (div < 5)
00502 If (l\collected = False)
00503 If (MeshesIntersect(sphere, l\mesh1))
00504 ; yes
00505 HideEntity l\pivot
00506 l\collected = True
00507 PlaySound sndCollect
00508 remainingTime = remainingTime + addLetterTime
00509 changeScroller("TIME +" + addLetterTime)
00510 EndIf
00511 EndIf
00512 EndIf ;dif 5
00513 EndIf ;dif 60
00514 Next
00515 ; player fall down?
00516 If (EntityY(sphere) > 0.3)
00517 ; no, draw shadow
00518 ShowEntity shadow
00519 PositionEntity shadow, EntityX(sphere), 0.1, EntityZ(sphere)
00520 ScaleEntity shadow, 0.1*EntityY(sphere)+0.2, 0.1, 0.1*EntityY(sphere)+0.2
00521 Else
00522 ; yes, player felt down!
00523 If (soundPlayingFlag = False)
00524 PlaySound(sndFallDown)
00525 DebugLog "playsound"
00526 soundPlayingFlag = True
00527 EndIf
00528 HideEntity shadow
00529 speedX = 0
00530 speedZ = 0
00531 If (EntityY(sphere) < -5)
00532 ; reset player
00533 PositionEntity sphere, EntityX(sphere), 0.4, EntityZ(sphere)
00534 speedZ = 0.1
00535 upFlag=True
00536 downFlag=False
00537 soundPlayingFlag = False
00538 EndIf
00539 EndIf
00540
00541 ; manage texture-rotatoin of arrow-blocks
00542 PositionTexture arrowLeftTex, fZero2One, 0
00543 PositionTexture arrowRightTex, fZero2One, 0
00544
00545 ; only show next 60 blocks ahead
00546 For visible.block = Each block
00547 dif = EntityZ(visible\cube) - EntityZ(Camera)
00548 If (dif < 60)
00549 ShowEntity visible\cube
00550 If (dif < 5)
00551 ; enable collision
00552 EntityType visible\cube, 2
00553
00554 ; do player-drift, if player touch arrow-block
00555 If (visible\col = 8 Or visible\col = 9)
00556 colCount = CountCollisions(sphere)
00557 For i=1 To colCount
00558 If (visible\cube = CollisionEntity(sphere, i))
00559 ; check color of block
00560 Select visible\col
00561 Case 9
00562 ; drift left
00563 speedX = speedX - 0.004
00564 Case 8
00565 ; drift right
00566 speedX = speedX + 0.004
00567 End Select
00568 EndIf
00569 Next
00570 EndIf ; 8 or 9
00571
00572 ; Delete blocks out of sight
00573 If (dif < 0)
00574 FreeEntity visible\cube
00575 Delete visible
00576 EndIf
00577
00578 EndIf
00579 EndIf
00580 Next
00581
00582 ; also delete sprites behind player
00583 For w.wurst = Each wurst
00584 dif = EntityZ(w\pivot) - EntityZ(Camera)
00585 If (dif < 0)
00586 FreeEntity w\pivot
00587 Delete w
00588 EndIf
00589 Next
00590 End Function
00591
00592 Function resetLevel()
00593 DebugLog "resetLevel"
00594 ClearCollisions
00595 HideEntity tolleWurst1
00596 HideEntity tolleWurst2
00597 HideEntity scroller
00598 PositionEntity camera, blockX/2, 2, -5
00599 PositionEntity sphere, blockX/2, 2, 0
00600 RotateEntity sphere, 0, 0, 0
00601 EntityType sphere, 1
00602 ; For b.block = Each block
00603 ; EntityBox b\cube, -0.5, 0, -0.5, 1, 0.1, 1
00604 ; Next
00605 ScaleSprite speedMeter, speedZ * 12.0 + 0.1, 0.2
00606 PositionEntity speedMeter, -3, 5.2, EntityZ(camera) + 5
00607 Collisions 1, 2, 3, 2 ; sphere to cube
00608 speedZ = 0
00609 speedX = 0
00610 gravity = -0.06
00611 End Function
00612
00613 Function deleteTypes()
00614 For bb.block = Each block
00615 FreeEntity bb\cube
00616 Delete bb
00617 Next
00618 For ll.letter = Each letter
00619 FreeEntity ll\mesh1
00620 FreeEntity ll\mesh2
00621 FreeEntity ll\pivot
00622 Delete ll
00623 Next
00624 For ss.wurst = Each wurst
00625 FreeEntity ss\pivot
00626 Delete ss
00627 Next
00628 End Function
00629
00630 Function makeBlock(blockColor%, xPos%, zPos%)
00631 b.block = New block
00632 b\col = blockColor
00633 b\cube = CreateCube()
00634 PositionEntity b\cube, xPos, 0, zPos
00635 ScaleEntity b\cube, 0.5, 0.1, 0.5
00636 EntityBox b\cube, -0.5, 0, -0.5, 1, 0.1, 1
00637 ;EntityPickMode b\cube, 2 ; DEBUG
00638 Select blockColor
00639 Case 1
00640 EntityColor b\cube, 255, 0 ,0 ; red
00641 Case 2
00642 EntityColor b\cube, 0, 255 ,0 ; green
00643 Case 3
00644 EntityColor b\cube, 0, 0, 255 ; blue
00645 Case 4
00646 EntityColor b\cube, 255, 0, 255 ; purple
00647 Case 5
00648 EntityColor b\cube, 0, 255, 255 ; yellow
00649 Case 6
00650 EntityColor b\cube, 255, 255, 0 ; orange
00651 Case 7
00652 EntityColor b\cube, 200, 200, 200 ; lite gray
00653 Case 8
00654 EntityColor b\cube, 255, 255, 255 ; white, arrow_right (player will drift right)
00655 EntityTexture b\cube, arrowRightTex
00656 Case 9
00657 EntityColor b\cube, 100, 100, 100 ; dark gray, arrow_left (player will drift left)
00658 EntityTexture b\cube, arrowLeftTex
00659 Default
00660 DebugLog "makeBlock: unknown blockColor"
00661 End Select
00662 ; do not show cube (speed up rendering)
00663 HideEntity b\cube
00664 End Function
00665
00666 Function makeLetter(char$, zPos%)
00667 If (FileType("gfx\balloons.3ds") <> 1) Then loadMediaError("gfx\balloons.3ds")
00668 If (FileType("gfx\" + char + ".3ds") = 1) ; filename valid?
00669 l.letter = New letter
00670 l\pivot = CreatePivot()
00671 l\mesh1 = LoadMesh("gfx\" + char + ".3ds", l\pivot)
00672 l\mesh2 = LoadMesh("gfx\balloons.3ds", l\pivot)
00673 l\char = char
00674 l\collected = False
00675 l\freq = Rnd(0,359)
00676 EntityAlpha l\mesh1, 0.5
00677 PositionEntity l\pivot, 3, 1, zPos
00678 PositionEntity l\mesh1, 0, -0.6, 0
00679 ScaleMesh l\mesh1, 0.01, 0.01, 0.005
00680 PositionEntity l\mesh2, -0.1, 5, 0
00681 TurnEntity l\mesh2, 0, Rnd(0, 359), 0
00682 ScaleMesh l\mesh2, 0.01, 0.01, 0.01
00683 Else
00684 DebugLog "makeLetter: file not found " + "gfx\" + char + ".3ds"
00685 loadMediaError("gfx\" + char + ".3ds")
00686 EndIf
00687 End Function
00688
00689 Function makeSprite(file$, amount)
00690 file = "gfx\" + file
00691 If (FileType(file) = 1) ; filename valid?
00692 DebugLog "makeSprite: " + file + ", " + amount
00693 e = CreateCube()
00694 EntityTexture e, LoadTexture(file, 4)
00695 ScaleEntity e, 1, 1, 0.00001
00696 For i=1 To amount
00697 s.wurst = New wurst
00698 s\pivot = CopyEntity(e)
00699 PositionEntity s\pivot, Rnd(6, 20), Rnd(-2, 10), Rnd(1, blockY)
00700 s.wurst = New wurst
00701 s\pivot = CopyEntity(e)
00702 PositionEntity s\pivot, Rnd(-2, -16), Rnd(-2, 10), Rnd(1, blockY)
00703 Next
00704 FreeEntity e
00705 Else
00706 DebugLog "file not found: " + file
00707 loadMediaError(file)
00708 EndIf
00709 End Function
00710
00711 Function loadLevel(index)
00712 Local fname$ = "levels\level0"+index+".txt"
00713 Local i%, k%, tmpCol%, block50Col%
00714 Local myLine$, myLineLen%
00715
00716 DebugLog "loadLevel: "+fname
00717
00718 deleteTypes()
00719
00720 blockX = 5
00721 blockY = 0
00722
00723 If FileType(fname) = 1 ; filename valid?
00724 fin = ReadFile(fname)
00725 While Not Eof(fin)
00726 myLine = ReadLine(fin)
00727 If (Mid(myLine, 1, 11) = "level_name:")
00728 levelName = Mid(myLine, 12, 255)
00729 ElseIf (Mid(myLine, 1, 11) = "level_time:")
00730 remainingTime = Mid(myLine, 12, 255)
00731 ElseIf (Mid(myLine, 1, 16) = "add_letter_time:")
00732 addLetterTime = Mid(myLine, 17, 255)
00733 ElseIf (Mid(myLine, 1, 7) = "sprite:")
00734 makeSprite(Mid(myLine, 8, 255), 10)
00735 ElseIf (Mid(myLine, 1, 1) <> ";") ; delete comments
00736 myLineLen = Len(myLine)
00737 For k=1 To myLineLen
00738 tmpCol = Mid(myLine, k, 1) ; ascii to int
00739 If (tmpCol > 0 And tmpCol < 10) ; blockColor found
00740 makeBlock(tmpCol, k-1, blockY)
00741 ElseIf (Asc(Mid(myLine, k, 1)) >= Asc("r")) ; w/u/r/s/t letter found
00742 makeLetter(Mid(myLine, k, 1), blockY)
00743 EndIf
00744 Next
00745 blockY = blockY + 1
00746 EndIf
00747 Wend
00748 CloseFile(fin)
00749 Else
00750 DebugLog "loadLevel: file not found " + fname
00751 loadMediaError(fname)
00752 EndIf
00753
00754 PositionEntity finishLine, 3.3, 2.9, blockY-2
00755
00756 ; add 50 lines of blocks after finish-line
00757 For i=0 To 49
00758 For k=0 To 4
00759 block50Col = (block50Col + 1) Mod 2 ; toggle 0,1
00760 makeBlock(5 + block50Col, k, blockY + i-1)
00761 Next
00762 Next
00763 End Function
00764
00765 Function loadMedia()
00766
00767 chnBackground = PlayMusic("sound\commando.mod")
00768 ChannelVolume chnBackground, 0.3
00769 If (FileType("sound\commando.mod") <> 1) then loadMediaError("sound\commando.mod")
00770 sndCollect = LoadSound("sound\Sfx1.wav")
00771 If (0 = sndCollect) Then loadMediaError("sound\Sfx1.wav")
00772 sndDeath = LoadSound("sound\death.mp3")
00773 If (0 = sndDeath) Then loadMediaError("sound\death.mp3")
00774 sndStart = LoadSound("sound\start.mp3")
00775 If (0 = sndStart) Then loadMediaError("sound\start.mp3")
00776 sndFallDown = LoadSound("sound\hollowstatic.wav")
00777 If (0 = sndFallDown) Then loadMediaError("sound\hollowstatic.wav")
00778 sndBounceUp = LoadSound("sound\bounce1.wav")
00779 If (0 = sndBounceUp) Then loadMediaError("sound\bounce1.wav")
00780 sndBounceDown = LoadSound("sound\bounce2.wav")
00781 If (0 = sndBounceDown) Then loadMediaError("sound\bounce2.wav")
00782
00783 sphereTex = LoadTexture("gfx\earth.jpg", 1)
00784 If (0 = sphereTex) Then loadMediaError("gfx\earth.jpg")
00785 skyTex = LoadTexture("gfx\univers1024.jpg")
00786 If (0 = skyTex) Then loadMediaError("gfx\stars512.jpg")
00787 arrowLeftTex = LoadTexture("gfx\arrow512.jpg", 4)
00788 If (0 = arrowLeftTex) Then loadMediaError("gfx\arrow512.jpg")
00789 TextureBlend arrowLeftTex, 3
00790 RotateTexture arrowLeftTex, 180
00791
00792 arrowRightTex = LoadTexture("gfx\arrow512.jpg", 4)
00793 If (0 = arrowRightTex) Then loadMediaError("gfx\arrow512.jpg")
00794 TextureBlend arrowRightTex, 3
00795 logoTex = LoadTexture("gfx\logo501.jpg")
00796 If (0 = logoTex) Then loadMediaError("gfx\logo501.jpg")
00797 titleInfoTex = LoadTexture("gfx\titleInfoTex3.png", 4)
00798 If (0 = titleInfoTex) Then loadMediaError("gfx\titleInfoTex3.png")
00799
00800 finishLine = LoadMesh("gfx\finishline.3ds")
00801 If (0 = finishLine) Then loadMediaError("gfx\finishline.3ds")
00802 ScaleMesh finishLine, 0.033, 0.04, 0.03
00803
00804 digit_1 = LoadTexture("gfx\digit_1.png", 4)
00805 If (0 = digit_1) Then loadMediaError("gfx\digit_1.png")
00806 digit_2 = LoadTexture("gfx\digit_2.png", 4)
00807 If (0 = digit_2) Then loadMediaError("gfx\digit_2.png")
00808 digit_3 = LoadTexture("gfx\digit_3.png", 4)
00809 If (0 = digit_3) Then loadMediaError("gfx\digit_3.png")
00810
00811 tolleWurst1 = LoadSprite("gfx\tollewurst1Tex.png", 4)
00812 If (0 = tolleWurst1) Then loadMediaError("gfx\tollewurst1Tex.png")
00813 ScaleSprite tolleWurst1, 3, 1
00814 HideEntity tolleWurst1
00815 tolleWurst2 = LoadSprite("gfx\tollewurst2Tex.png", 4)
00816 If (0 = tolleWurst2) Then loadMediaError("gfx\tollewurst2Tex.png")
00817 ScaleSprite tolleWurst2, 3, 1
00818 HideEntity tolleWurst2
00819 timeOver = LoadSprite("gfx\timeOverTex.png")
00820 If (0 = timeOver) Then loadMediaError("gfx\timeOverTex.png")
00821 ScaleSprite timeOver, 3, 1
00822 HideEntity timeOver
00823 speedMeter = LoadSprite("gfx\speedmeter.jpg")
00824 If (0 = speedMeter) Then loadMediaError("gfx\speedMeter.jpg")
00825 HideEntity speedMeter
00826
00827 terrain(0) = LOADTERRAIN("gfx/heightmap.jpg")
00828 If (0 = terrain(0)) Then loadMediaError("gfx\heightmap.jpg")
00829 TerrainDetail terrain(0), 500, True
00830 ScaleEntity terrain(0), 1, 30, TERRAIN_Z_SCALE
00831 grass_tex = LOADTEXTURE("gfx\meadow512.jpg")
00832 If (0 = grass_tex) Then loadMediaError("gfx\meadow512.jpg")
00833 EntityTexture terrain(0), grass_tex, 0, 1
00834 PositionEntity terrain(0), -60, -10, 0
00835
00836 terrain(1) = LOADTERRAIN("gfx/heightmap.jpg")
00837 TerrainDetail terrain(1), 500, True
00838 ScaleEntity terrain(1), 1, 30, TERRAIN_Z_SCALE
00839 PositionEntity terrain(1), -60, -10, 128*TERRAIN_Z_SCALE
00840 EntityTexture terrain(1), grass_tex, 0, 1
00841
00842 GG_Load_Bitmap_Font("Wurst", "3dTextLib\Wurst5_32.ggfnt")
00843 scroller = GG_Create_Text_Arc(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?():+ ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?():+", 20, -45, 1, 3)
00844
00845 camera = CreateCamera()
00846 light=CreateLight(1, camera)
00847 CameraRange camera, 1, 100
00848
00849 sphere = CreateSphere(8)
00850 ScaleEntity sphere, 0.3, 0.3, 0.3
00851 EntityType sphere, 1
00852 EntityRadius sphere, 0.3
00853 EntityTexture sphere, sphereTex
00854
00855 shadow = CreateSphere(4)
00856 EntityColor shadow, 0, 0, 0
00857 EntityAlpha shadow, 0.5
00858
00859 hudCube = CreateCube()
00860 ScaleEntity hudCube, 2, 0.08, 0.0001
00861 hudTexture = CreateTexture(128, 128)
00862 ScaleTexture hudTexture, 1, 8
00863 PositionEntity hudCube, 0, 0 , -100 ; out of sight
00864
00865 sky = CreateSphere(8)
00866 ScaleEntity sky, 100, 100, 100
00867 RotateTexture skyTex, 180
00868 ScaleTexture skyTex, 0.3, 0.4
00869 EntityTexture sky, skyTex
00870 FlipMesh sky
00871
00872 logoCube = CreateCube()
00873 FitMesh logoCube, -5,5,0,10,2,0
00874 EntityTexture logoCube, logoTex
00875
00876 titleInfo = CreateCube()
00877 EntityTexture titleInfo, titleInfoTex
00878 ScaleEntity titleInfo, 1.5, 0.9, 1
00879 End Function
00880
00881 Function loadMediaError(file$)
00882 RuntimeError "Cannot load media: " + file + " - Please copy all media into the programs folder and run again."
00883 End
00884 End Function