alien_vs_hero.BlitzBasicSourceCode.c

00001 ; File = AvsH_SourceCode.bb
00002 ; written by Sebastian Roll, October 2003
00003 
00004 
00005 ;Constants 
00006 Const SCR_X = 800
00007 Const SCR_Y = 600
00008 Const MAX_SHOTS = 5
00009 Const MAX_LIVES = 3
00010 Const DIRECTION_LEFT = 1
00011 Const DIRECTION_RIGHT = 2
00012 
00013 
00014 ;Globals
00015 Global imgAlien1                ; Images
00016 Global imgAlien2
00017 Global imgAlien3
00018 Global imgAlienHead
00019 Global imgAlienHeadBase
00020 Global imgExplode1
00021 Global imgExplode2
00022 Global imgExplode3
00023 Global imgHero
00024 Global imgShot
00025 Global imgBomb
00026 Global imgMisile
00027 Global imgBonus
00028 Global imgBonusShip
00029 Global imgCruiser
00030 Global imgBubbleSmall
00031 Global imgBubbleMid
00032 Global imgBubbleBig
00033 Global imgSpider
00034 Global imgTitle
00035 Global imgBack1
00036 Global imgBack2
00037 Global imgBack3
00038 Global imgSnapShot
00039 Global sndExplode1              ; Sounds
00040 Global sndExplode2
00041 Global sndExplode3
00042 Global sndSpeed
00043 Global sndRapidFire
00044 Global sndMisile
00045 Global sndExtraLive
00046 Global sndPoints
00047 Global sndLoopNormal
00048 Global sndLoopWater
00049 Global chnLoop                  ; Channel for countinues playing a sound-loop
00050 Global fntStyleBig              ; Font to write on screen
00051 Global fntStyleSmall
00052 Global fntStyleMid
00053 Global fntStyleCourier
00054 Global nAliens                  ; Number of living Aliens
00055 Global heroInSaveMode   ; Set to True, if Hero can't be destroyed
00056 Global insertIndex              ; HiScore-Insert-Position
00057 Global waterShore               ; Border from Water to Space in Underwater-Levels
00058 Global demoTime                 ; Go into Demo-Mode after some time without User-Input
00059 Global backroundMusic   ; Different Levels -> Different Music
00060 
00061 
00062 
00063 ;TypeDefs
00064 Type Alien
00065         Field xPos = 0
00066         Field yPos = 0
00067         Field img = 0
00068         Field frame = 0
00069         Field direction = 0
00070         Field speed# = 0
00071         Field mode = 0
00072         Field freqX = 0
00073         Field freqY = 0
00074         Field angel# = 0
00075 End Type
00076 
00077 Type Hero
00078         Field xPos = 0
00079         Field yPos = 0
00080         Field img = 0
00081         Field frame = 0
00082         Field score = 0
00083         Field nShots = 0                        ; Maximum of Shots displayed on Screen
00084         Field shotTimeDelta = 0         ; Minimum of delay between two Shots
00085         Field nLives = 0
00086         Field haveBonusSpeed = 0
00087         Field haveBonusRapidFire = 0
00088         Field haveBonusMisile = 0
00089         Field haveBonusExtraLive = 0
00090 End Type
00091 
00092 Type Explode1
00093         Field xPos = 0
00094         Field yPos = 0
00095         Field img = 0
00096         Field Frame = 0
00097 End Type
00098 
00099 Type Explode2
00100         Field xPos# = 0.0
00101         Field yPos# = 0.0
00102         Field xs# = 0
00103         Field ys# = 0
00104         Field colorR = 0
00105         Field colorG = 0
00106         Field colorB = 0
00107 End Type
00108 
00109 Type Explode3
00110         Field xPos = 0
00111         Field yPos = 0
00112         Field img = 0
00113         Field Frame = 0
00114 End Type
00115 
00116 Type Shot
00117         Field xPos = 0
00118         Field yPos = 0
00119         Field img = 0
00120 End Type
00121 
00122 Type Bomb
00123         Field xPos# = 0
00124         Field yPos = 0
00125         Field img = 0
00126         Field speed = 0
00127         Field angel# = 0
00128 End Type
00129 
00130 Type Bonus
00131         Field xPos = 0
00132         Field yPos = 0
00133         Field img = 0
00134 End Type
00135 
00136 Type Misile
00137         Field xPos# = 0
00138         Field yPos = 0
00139         Field xDelta# = 0
00140         Field img = 0
00141         Field frame = 0
00142 End Type
00143 
00144 Type BonusShip
00145         Field xPos = 0
00146         Field yPos = 0
00147         Field img = 0
00148 End Type
00149 
00150 Type Cruiser
00151         Field xPos = 0
00152         Field yPos = 0
00153         Field img = 0
00154         Field frame = 0
00155 End Type
00156 
00157 Type BackroundStar
00158         Field xPos = 0
00159         Field yPos = 0
00160         Field colorR = 0
00161         Field colorG = 0
00162         Field colorB = 0
00163 End Type
00164 
00165 Type Bubble
00166         Field xPos = 0
00167         Field yPos = 0
00168         Field img = 0
00169         Field speed = 0
00170 End Type
00171 
00172 Type BunkerFragment
00173         Field xPos = 0
00174         Field yPos = 0
00175 End Type
00176 
00177 Type HiScore
00178         Field name$ = ""
00179         Field points = 0
00180         Field date$ = 0
00181 End Type
00182 
00183 Type InputName
00184         Field hiLightIndex = 0
00185         Field name$ = ""
00186         Field inTimeDelta = 0           ; Minimum of delay between two Inputs
00187 End Type
00188 
00189 Type Message
00190         Field Text$ = ""
00191         Field timeToDisplay = 0
00192 End Type
00193 
00194 Type Spider
00195         Field xPos = 0
00196         Field yPos# = 0
00197         Field swing1 = 0
00198         Field swing2# = 0
00199         Field destReached = 0
00200         Field img = 0
00201         Field hits = 0
00202         Field bombTime = 0
00203         Field bombAngelOffset# = 0.0
00204         Field bombTimeCount = 0
00205 End Type
00206 
00207 
00208 
00209 ;Init
00210 Graphics SCR_X, SCR_Y
00211 Text SCR_X/2, 280, "PREPARE ALIEN-DESASTER:", True
00212 imgTemp1 = LoadImage("screenshot3.jpg")
00213 If imgTemp1 <> 0
00214         DrawImage imgTemp1, 150, 320
00215 EndIf
00216 imgTemp2 = LoadImage("screenshot4.jpg")
00217 If imgTemp2 <> 0
00218         DrawImage imgTemp2, 450, 320
00219 EndIf
00220 SeedRnd MilliSecs()
00221 AppTitle "Aliens vs Hero"
00222 Text 0, 0, "Loading Sounds."
00223 If -1 = loadSounds() Then RuntimeError "Can't Load Sounds"
00224 Text 0, 20, "Loading Graphics."
00225 If -1 = loadGraphics() Then RuntimeError "Can't Load Graphics"
00226 SetBuffer BackBuffer() ; All Graphics will be Double-Buffered
00227 FlushKeys
00228 demoTime = MilliSecs()
00229 imgSnapShot = CreateImage(SCR_X, SCR_Y) ; Used by UnderWater-Effect
00230 FreeImage imgTemp1
00231 FreeImage imgTemp2
00232 
00233 
00234 ; Start Game
00235 doMainLoop()
00236 
00237 
00238 
00239 Function doMainLoop()
00240 
00241         Local gameState         = 0
00242         Local nLevel            = 1
00243         Local doBomb            = True
00244         Local frameTimer        = CreateTimer(50)
00245         Local soundIsOn         = True
00246         Local demoIsOn          = False
00247         
00248         Local oldTime           = 0 ; Sometimes we don't allow User-Input
00249         Local newTime           = 0
00250         Local dieTime           = 0
00251         
00252         Local startFreq         = 1 ; Used for UnderWaterEffect
00253         Local shoreFreq         = 1
00254                 
00255         Local uState            = 0     ; UnDokumented... :)
00256 
00257         ResumeChannel(chnLoop)
00258 
00259         ; Do all drawing. Watch exit and new Levels.
00260         Repeat
00261 
00262                 Cls
00263 
00264                 Select gameState
00265 
00266                         ; Initial State
00267                         Case 0
00268                                 
00269                                 drawTitleScreen()
00270                                 oldTime = MilliSecs()
00271 
00272                                 ; Don't draw Hero.
00273                                 heroInSaveMode  = True
00274                                 
00275                                 If KeyHit(57)
00276                                         initHero()
00277                                         nLevel = 1
00278                                         insertIndex = 1
00279                                         gameState = 1
00280                                 EndIf
00281                                 
00282                                 If (demoTime + 10000 < oldTime) And (demoIsOn = False)
00283                                         demoIsOn = True
00284                                         nLevel = 3
00285                                         initHero()
00286                                         gameState = 1
00287                                 EndIf
00288                         
00289                         ; Inform User abaut current Level, prepare it.
00290                         Case 1
00291 
00292                                 ; Don't draw Hero.
00293                                 heroInSaveMode  = True
00294                                 For h.Hero = Each Hero
00295                                         h\xPos = SCR_X / 2
00296                                 Next
00297 
00298                                 demoTime = MilliSecs()
00299                                 drawLevelChange(nLevel, soundIsOn)
00300                                 initLevel(nLevel)
00301                                 gameState = 2
00302                                 FlushKeys
00303                         
00304                         ; Normal Game-State
00305                         Case 2
00306 
00307                                 newTime = MilliSecs()
00308                                 
00309                                 b.Bomb = First Bomb
00310                                 If b = Null 
00311                                         If newTime > oldTime + 500
00312                                                 ; No more Bombs on Screen -> draw Hero
00313                                                 heroInSaveMode = False
00314                                         EndIf
00315                                 Else
00316                                         oldTime = MilliSecs()
00317                                 EndIf
00318                                 
00319                                 If nAliens = 10
00320                                         makeBonusShip()
00321                                 EndIf
00322                                 
00323                                 If nAliens <= 0
00324                                         gameState = 3
00325                                         oldTime = MilliSecs()
00326                                 ElseIf (nAliens = 1) And ((nLevel Mod 4) = 0)
00327                                         ; Each 4th Level a Spider as End-SuperAlien
00328                                         For a.Alien = Each Alien
00329                                                 explodeAlien(a)
00330                                         Next
00331                                         makeSpider()
00332                                 EndIf
00333 
00334         
00335                         ; Next Level reached
00336                         Case 3
00337                                 
00338                                 newTime = MilliSecs()
00339                                 If newTime > oldTime + 1000
00340                                         nLevel = nLevel + 1
00341                                         ; Each third Level is UnderWater
00342                                         If (nLevel Mod 3) = 0
00343                                                 Delete Each Message
00344                                                 msg.Message = New Message
00345                                                 msg\Text$ = "UNDERWATER STAGE"
00346                                                 msg\timeToDisplay = MilliSecs() + 5000
00347                                         EndIf
00348                                         gameState = 1
00349                                 EndIf
00350                         
00351                         ; Load HiScore-Table
00352                         Case 4
00353                         
00354                                 dieTime = MilliSecs()
00355                                 If oldTime + 500 < dieTime
00356                                         gameState = 5
00357                                         If readHiScore() < 0
00358                                                 ; No File found, so create new one.
00359                                                 If writeNewHiScore() < 0
00360                                                         ; Can't do any File-operations, so exit this HiScore-stuff.
00361                                                         gameState = 7
00362                                                 EndIf
00363                                         EndIf
00364                                         FlushKeys
00365                                 EndIf
00366                         
00367                         ; Show HiScore-Table
00368                         Case 5
00369                                 
00370                                 ; Is Score great enough to store it in HiScore-Table?
00371                                 h.Hero = First Hero
00372                                 For table.HiScore = Each HiScore
00373                                         If h\score < table\points
00374                                                 insertIndex = insertIndex + 1
00375                                         EndIf
00376                                 Next
00377                                 
00378                                 If insertIndex < 11
00379                                         in.InputName = New InputName
00380                                         in\hiLightIndex = 65
00381                                         in\name$                = ""
00382                                         in\inTimeDelta  = MilliSecs()
00383                                         FlushKeys
00384                                         gameState = 6
00385                                 Else
00386                                         ; Don't let User input his Name.
00387                                         FlushKeys
00388                                         gameState = 7
00389                                 EndIf
00390                         
00391                         ; Input new HiScore and save
00392                         Case 6
00393                         
00394                                 in.InputName = First InputName
00395 
00396                                 ; Be sure that Hero isn't drawn.
00397                                 h.Hero = First Hero
00398                                 h\xPos = -100                           
00399 
00400                                 If Len(in\name$) >= 3   ; User entered three Chars
00401 
00402                                         hs.HiScore = New HiScore
00403                                         hs\name$ = in\name$
00404                                         hs\points = h\score
00405                                         hs\date$ = CurrentDate$()
00406         
00407                                         For table.HiScore = Each HiScore
00408                                                 If h\score >= table\points 
00409                                                         Insert hs Before table
00410                                                         Exit
00411                                                 EndIf
00412                                         Next
00413                                                                 
00414                                         table.HiScore = Last HiScore
00415                                         Delete table
00416                         
00417                                         writeHiScore()
00418                                         insertIndex = 11
00419                                         gameState = 7
00420                                 EndIf
00421                         
00422                         ; Game Over. Prepare next start.
00423                         Case 7
00424                                 
00425                                 newTime = MilliSecs()
00426                                 If newTime > oldTime + 2000
00427                                         If KeyHit(57)
00428                                                 ; Clean up Memory
00429                                                 disposeObjects()        
00430                                                 h.Hero = First Hero
00431                                                 If h <> Null
00432                                                         Delete h
00433                                                 EndIf
00434                                                 demoTime = MilliSecs()
00435                                                 FlushKeys
00436                                                 gameState = 0
00437                                         EndIf
00438                                 EndIf
00439                                                 
00440                 End Select
00441 
00442                 For bs.BackroundStar = Each BackroundStar
00443                         drawBackroundStar(bs)
00444                 Next
00445 
00446                 For bu.Bubble = Each Bubble
00447                         drawBubble(bu)
00448                 Next
00449 
00450                 For sp.Spider = Each Spider
00451                         drawSpider(sp)
00452                 Next
00453 
00454                 For a.Alien = Each Alien
00455                         ; Should Alien drop a Bomb?
00456                         If heroInSaveMode = False And a\mode <> 2
00457                                 doBomb = Rnd(150/nLevel)
00458                                 If doBomb = 0
00459                                         makeBomb(a)
00460                                 EndIf
00461                         EndIf
00462                         drawAlien(a)
00463                 Next
00464 
00465                 For b.Bomb = Each Bomb
00466                         drawBomb(b)
00467                 Next
00468 
00469                 For e1.Explode1 = Each Explode1
00470                         drawExplode1(e1)
00471                 Next
00472                 
00473                 For e2.Explode2 = Each Explode2
00474                         drawExplode2(e2)
00475                 Next
00476 
00477                 For e3.Explode3 = Each Explode3
00478                         drawExplode3(e3)
00479                 Next
00480 
00481                 For s.Shot = Each Shot
00482                         drawShot(s)
00483                 Next
00484 
00485                 For m.Misile = Each Misile
00486                         drawMisile(m)
00487                 Next
00488 
00489                 For bos.BonusShip = Each BonusShip
00490                         drawBonusShip(bos)
00491                 Next
00492                                 
00493                 For bon.Bonus = Each Bonus
00494                         drawBonus(bon)
00495                 Next
00496                 
00497                 For bf.BunkerFragment= Each BunkerFragment
00498                         drawBunkerFragment(bf)
00499                 Next
00500 
00501                 For h.Hero = Each Hero
00502                         drawHero(h)
00503                         Color 255, 255, 0
00504                         SetFont(fntStyleSmall)
00505                         Text 0, 0, "Ships " + h\nLives
00506                         Text SCR_X - 120, 0, "Score " + h\score
00507                         If h\nLives <= 0 And gameState = 2
00508                                 gameState = 4
00509                                 oldTime = MilliSecs()
00510                         EndIf
00511                 Next
00512                 
00513                 ; UnderWater-Effect at each third Level
00514                 If (nLevel Mod 3) = 0 And gameState > 1
00515                         doUnderWaterEffect(startFreq, shoreFreq)
00516                         startFreq = (startFreq + 1) Mod 359
00517                         shoreFreq = (shoreFreq + 2) Mod 359
00518                         If nAliens = 6
00519                                 makeCruiser()
00520                         EndIf
00521                 EndIf
00522                 
00523                 For msg.Message = Each Message
00524                         drawMessage(msg)
00525                 Next
00526 
00527                 ; Handle Demo-State
00528                 If demoIsOn = True
00529                         For h.Hero = Each Hero
00530                                 Color 255, 255, 0
00531                                 SetFont(fntStyleBig)
00532                                 Text SCR_X/2, SCR_Y/2-80, "DEMO", True, True
00533                                 For a.Alien = Each Alien
00534                                         If (a\xPos > 350) And (a\xPos < 360) And (heroInSaveMode = False)
00535                                                 ; Do some stupid Shots
00536                                                 s.Shot = New Shot
00537                                                 s\xPos = h\xPos - 1
00538                                                 s\yPos = h\yPos - 37
00539                                                 s\img = imgShot
00540                                         EndIf
00541                                 Next            
00542                                 ; Watch for Demo-Exit
00543                                 If KeyHit(57) Or nAlien = 1 Or h\nLives <= 0
00544                                         demoIsOn = False
00545                                         disposeObjects()
00546                                         Delete Each Hero
00547                                         demoTime = MilliSecs()
00548                                         FlushKeys
00549                                         gameState = 0
00550                                 EndIf
00551                         Next
00552                 EndIf
00553                 
00554                 If gameState > 3
00555                         newTime = MilliSecs()
00556                         If newTime > oldTime + 1000
00557                                 Color 255, 255, 0
00558                                 SetFont(fntStyleBig)
00559                                 Text SCR_X/2, SCR_Y/4, "GAME OVER", True, True
00560                                 drawHiScore()
00561                         EndIf
00562                 EndIf
00563                 
00564                 For in.InputName = Each InputName
00565                         drawInputName(in)
00566                 Next
00567 
00568                 ; 'p' will pause and resume Game.
00569                 If KeyHit(25)
00570                         Delete Each Message
00571                         msg.Message = New Message
00572                         msg\Text$ = "PAUSE"
00573                         msg\timeToDisplay = MilliSecs() + 1000
00574                         drawMessage(msg)
00575                         Flip
00576                         While Not KeyHit(25)
00577                                 Delay(200)
00578                         Wend
00579                         FlushKeys
00580                 EndIf
00581 
00582 
00583                 ; Due To the Double-Buffering of Graphics, we have To Flip BackScreen To FrontScreen.
00584                 Flip
00585                 ; Now all Graphics will be drawn on a blank BackScreen. Until the next Flip.
00586 
00587 
00588                 ; 's' will toggle Sound on/off
00589                 If KeyHit(31)
00590                         soundIsOn = Not soundIsOn
00591                         If soundIsOn = True
00592                                 ResumeChannel(chnLoop)
00593                                 Delete Each Message
00594                                 msg.Message = New Message
00595                                 msg\Text$ = "SOUND ON"
00596                                 msg\timeToDisplay = MilliSecs() + 2000
00597                         Else
00598                                 PauseChannel(chnLoop)
00599                                 Delete Each Message
00600                                 msg.Message = New Message
00601                                 msg\Text$ = "SOUND OFF"
00602                                 msg\timeToDisplay = MilliSecs() + 2000
00603                         EndIf
00604                 EndIf
00605                 
00606                 ; 'F12' will save a ScreenShot to 'avshScreenShot.bmp'
00607                 If KeyHit(88)
00608                         GrabImage imgSnapShot, 0, 0
00609                         SaveImage(imgSnapShot, "avshScreenShot.bmp")
00610                 EndIf
00611                 
00612                 If KeyHit(48) And uState = 0 Then uState = 1
00613                 If uState > 0
00614                         If KeyHit(38) And uState = 1 Then uState = 2
00615                         If KeyHit(23) And uState = 2 Then uState = 3
00616                         If KeyHit(20) And uState = 3 Then uState = 4
00617                         If (KeyHit(44) Or KeyHit(21)) And uState = 4 Then uState = 5
00618                         If uState = 5
00619                                 SetFont(fntStyleBig)
00620                                 Color 255, 255, 0
00621                                 heroInSaveMode = False
00622                                 While Not KeyHit(57)
00623                                         Cls
00624                                         For a.Alien = Each Alien
00625                                                 drawAlien(a)
00626                                         Next
00627                                         initAliens(1, Rnd(2), Rnd(1,3))
00628                                         Text 180, 500, "ALIEN-COUNT: " + nAliens
00629                                         Flip
00630                                 Wend
00631                                 disposeObjects()
00632                                 FlushKeys
00633                                 heroInSaveMode = True
00634                                 uState = 0
00635                                 Delete Each Hero
00636                                 demoTime = MilliSecs()
00637                                 gameState = 0
00638                         EndIf                                                                                                                                   
00639                 EndIf
00640                 
00641                 ; Set FrameRate to 50 ms on every machine, running this application.
00642                 WaitTimer(frameTimer)
00643                 
00644         Until KeyHit(1)
00645 
00646         FreeTimer(frameTimer)
00647         disposeObjects()
00648 
00649 End Function
00650 
00651 
00652 
00653 Function doUnderWaterEffect(startFreq, shoreFreq)
00654 
00655         Local lineCount = 0
00656 
00657         ; Set global Border of WaterShore (WaterShore goes up and down).
00658         waterShore = 80 + Sin(shoreFreq) * 30
00659 
00660         ; Save SnapShot
00661         GrabImage imgSnapShot, 0, 0
00662 
00663         ; Clear Screen with WaterColor
00664         Color 0, 50, 120
00665         Rect 0, waterShore, SCR_X, SCR_Y, True
00666 
00667         ; Draw back SnapShot (up to WaterShore) Line for Line with Sinus-xPos-Offset.
00668         For lineCount = waterShore To SCR_Y-1
00669                 DrawImageRect imgSnapShot, Sin(lineCount + startFreq) * 20, lineCount, 0, lineCount, SCR_X-1, 1
00670         Next
00671 
00672         For cr.Cruiser = Each Cruiser
00673                 drawCruiser(cr, waterShore)
00674         Next
00675 
00676 End Function
00677 
00678 
00679 
00680 Function initLevel(level)
00681 
00682         disposeObjects()
00683 
00684         Select level
00685         
00686                 Case 1
00687                         initAliens(10, 1, 1)
00688                         initBackroundStars()
00689                 
00690                 Case 2
00691                         initAliens(10, 2, 1)
00692                         initBackroundStars()
00693                 
00694                 Case 3
00695                         initAliens(15, 0, 1)
00696                         initBubbles()
00697 
00698                 Case 4
00699                         initAliens(10, 1, 2)
00700                         initAliens(5, 1, 1)
00701                         initBackroundStars()
00702 
00703                 Case 5
00704                         initAliens(10, 2, 1)
00705                         initAliens(5, 2, 2)
00706                         initBackroundStars()
00707 
00708                 Case 6
00709                         initAliens(10, 0, 1)
00710                         initAliens(10, 2, 1)
00711                         initBubbles()
00712 
00713                 Case 7
00714                         initAliens(10, 0, 3)
00715                         initAliens(4, 2, 2)
00716                         initBackroundStars()
00717 
00718                 Case 8
00719                         initAliens(10, 1, 1)
00720                         initAliens(5, 2, 1)
00721                         initBackroundStars()
00722                 
00723                 Case 9
00724                         initAliens(40, 0, 1)
00725                         initBubbles()
00726 
00727                 Case 10
00728                         initAliens(10, 1, 2)
00729                         initAliens(10, 2, 2)
00730                         initBackroundStars()
00731 
00732                 Case 11
00733                         initAliens(20, 1, 1)
00734                         initAliens(10, 2, 1)
00735                         initBackroundStars()
00736 
00737                 Default
00738                         initAliens(10, 0, 1)
00739                         initAliens(10, 1, 1)
00740                         initAliens(5, 2, 2)
00741                         initBackroundStars()
00742         
00743         End Select
00744 
00745         initBunkerFragments()
00746 
00747 End Function
00748 
00749 
00750 
00751 Function initHero()
00752 
00753         h.Hero          = New Hero
00754         resetHero(h)
00755         h\score         = 0
00756         h\nLives        = MAX_LIVES
00757         h\nShots        = 0
00758         
00759 End Function
00760 
00761 
00762 
00763 Function initAliens(count, mode, speed)
00764         
00765         ; mode = 0      ->      AlienLeftRight
00766         ; mode = 1      ->      AlienSinus
00767         ; mode = 2      ->      AlienFalling
00768         
00769         For i=1 To count
00770 
00771                 a.Alien         = New Alien
00772 
00773                 a\xPos          = Rnd(50, SCR_X-50)
00774                 a\yPos          = Rnd(40, SCR_Y/4)
00775                 a\frame         = Rnd(5)
00776                 a\speed#        = speed
00777                 a\mode          = mode
00778                 a\angel#        = Rnd(178,182)
00779                 
00780                 If mode = 2
00781                         a\direction = DIRECTION_RIGHT
00782                         a\freqX         = Rnd(359)
00783                         a\freqY         = Rnd(SCR_Y/2)
00784                         a\img           = imgAlien3     
00785                 Else
00786                         a\direction = Rnd(0,1)
00787                         a\freqX         = Rnd(20)
00788                         a\freqY         = Rnd(20)
00789                         If mode = 1
00790                                 a\img   = imgAlien2
00791                         Else
00792                                 a\img   = imgAlien1
00793                         EndIf
00794                 EndIf
00795 
00796         Next
00797         
00798         nAliens = nAliens + count
00799         
00800 End Function
00801 
00802 
00803 
00804 Function initBackroundStars()
00805 
00806         ; Set x- and y-Pos and color per random
00807         For i=1 To 100
00808 
00809                 bs.BackroundStar= New BackroundStar
00810 
00811                 bs\xPos                 = Rnd(SCR_X)
00812                 bs\yPos                 = Rnd(SCR_Y)
00813                 bs\colorR               = Rnd(255)
00814                 bs\colorG               = Rnd(255)
00815                 bs\colorB               = Rnd(255)
00816 
00817         Next
00818                 
00819 End Function
00820 
00821 
00822 
00823 Function initBubbles()
00824 
00825         Local i = 0
00826 
00827         For i=1 To 50
00828                 bu.Bubble       = New Bubble
00829                 bu\xPos         = Rnd(SCR_X)
00830                 bu\yPos         = Rnd(SCR_Y)
00831                 bu\img          = imgBubbleSmall
00832                 bu\speed        = Rnd(3,4)
00833         Next            
00834 
00835         For i=1 To 30
00836                 bu.Bubble       = New Bubble
00837                 bu\xPos         = Rnd(SCR_X)
00838                 bu\yPos         = Rnd(SCR_Y)
00839                 bu\img          = imgBubbleMid
00840                 bu\speed        = Rnd(2,3)
00841         Next            
00842         
00843         For i=1 To 10
00844                 bu.Bubble       = New Bubble
00845                 bu\xPos         = Rnd(SCR_X)
00846                 bu\yPos         = Rnd(SCR_Y)
00847                 bu\img          = imgBubbleBig
00848                 bu\speed        = Rnd(1,2)
00849         Next            
00850                 
00851 End Function
00852 
00853 
00854 
00855 Function initBunkerFragments()
00856 
00857         ; Each BunkerFragment has a width and hight of 15 Pixel
00858         ; We want 3 bunkers
00859         For a=SCR_X/9 To SCR_X Step SCR_X/3
00860                 ; Each Bunker is 5 BunkerFragments width
00861                 For b=1 To 5*15 Step 15
00862                         ; Each Bunker is 5 BunkerFragments hight
00863                         For c=1 To 5*15 Step 15
00864         
00865                                 bf.BunkerFragment = New BunkerFragment
00866                 
00867                                 bf\xPos = a + b
00868                                 bf\yPos = SCR_Y - 155 + c
00869         
00870                         Next
00871                 Next
00872         Next
00873                 
00874 End Function
00875 
00876 
00877 
00878 Function resetHero(h.Hero)
00879         
00880         h\xPos                          = SCR_X / 2
00881         h\yPos                          = SCR_Y - 38
00882         h\img                           = imgHero
00883         h\frame                         = 0
00884         h\shotTimeDelta         = 0
00885         h\haveBonusSpeed        = False
00886         h\haveBonusRapidFire= False
00887         h\haveBonusMisile       = False
00888         h\haveBonusExtraLive= False
00889         
00890 End Function
00891 
00892 
00893 
00894 Function moveAlienLeftRight(a.Alien)
00895 
00896         If a\xPos > SCR_X - 50
00897                 a\direction = DIRECTION_LEFT
00898                 If a\yPos < SCR_Y - 220
00899                         a\yPos = a\yPos + 50
00900                 EndIf
00901         EndIf
00902         
00903         If a\xPos < 50
00904                 a\direction = DIRECTION_RIGHT
00905                 If a\yPos < SCR_Y - 220
00906                         a\yPos = a\yPos + 50
00907                 EndIf
00908         EndIf
00909         
00910         If a\direction = DIRECTION_LEFT
00911                 a\xPos = a\xPos - 3 * a\speed#
00912         Else
00913                 a\xPos = a\xPos + 3 * a\speed#
00914         EndIf
00915         
00916 End Function
00917 
00918 
00919 
00920 Function moveAlienSinus(a.Alien)
00921 
00922         Local centerX = SCR_X / 2 - 50
00923         Local centerY = SCR_Y / 2 - 150
00924         
00925         a\xPos = 50 + centerX + centerX * Sin(a\angel# * a\freqX)
00926         a\yPos = 50 + centerY + centerY * Sin(a\angel# * a\freqY + a\mode)
00927         
00928         a\angel# = (a\angel + 0.1 * a\speed#) Mod 360
00929         
00930 End Function
00931 
00932 
00933 
00934 Function moveAlienFalling(a.Alien)
00935 
00936         Local centerX = SCR_X / 2
00937         
00938         a\xPos = centerX + Sin(a\freqX) * (centerX-25)
00939         a\freqX = (a\freqX + a\speed) Mod 359
00940 
00941         For h.Hero = Each Hero
00942         
00943                 ; Alien out of Range?
00944                 If (a\yPos > SCR_Y) Or ((heroInSaveMode = True) And h\nLives > 0)
00945                         a\yPos = -20
00946                         a\direction = DIRECTION_RIGHT
00947                 EndIf
00948                 
00949                 ; Slightly scroll Alien into Screen.
00950                 If a\yPos <= a\freqY
00951                         a\yPos = a\yPos + a\speed
00952                 EndIf
00953 
00954                 ; Start falling
00955                 If (a\yPos >= a\freqY) 
00956                         a\yPos = a\yPos + 6 + a\speed
00957                 EndIf
00958 
00959         Next
00960 
00961 End Function
00962 
00963 
00964 
00965 Function drawHero(h.Hero)
00966 
00967         If heroInSaveMode = False
00968         
00969                 Local time = MilliSecs()
00970                 
00971                 ; User-Input    
00972                 If KeyDown(203) And h\xPos > 30
00973                         h\xPos = h\xPos - 3 - h\haveBonusSpeed * 3
00974                 EndIf
00975                 
00976                 If KeyDown(205) And h\xPos < SCR_X - 30
00977                         h\xPos = h\xPos + 3 + h\haveBonusSpeed * 3
00978                 EndIf
00979                 
00980                 ; Don't allow too many and too fast shootings
00981                 If h\haveBonusRapidFire = True
00982                         If KeyDown(57) And h\nShots < (3 * MAX_SHOTS) And h\shotTimeDelta < time - 200
00983                                 s.Shot = New Shot
00984                                 s\xPos = h\xPos - 1
00985                                 s\yPos = h\yPos - 37
00986                                 s\img = imgShot
00987                                 h\nShots = h\nShots + 1
00988                                 h\shotTimeDelta = time
00989                         EndIf
00990                 Else
00991                         If KeyDown(57) And h\nShots < MAX_SHOTS And h\shotTimeDelta < time - 80
00992                                 s.Shot = New Shot
00993                                 s\xPos = h\xPos - 1
00994                                 s\yPos = h\yPos - 37
00995                                 s\img = imgShot
00996                                 h\nShots = h\nShots + 1
00997                                 h\shotTimeDelta = time
00998                         EndIf
00999                 EndIf
01000                 
01001                 ; Drop Misile
01002                 If h\haveBonusMisile = True
01003                         If KeyDown(57)
01004                                 makeMisile(h)
01005                         EndIf
01006                 EndIf
01007                 
01008                 DrawImage h\img, h\xPos, h\yPos, h\frame / 10
01009                 h\frame = (h\frame + 1) Mod 39
01010                 
01011         EndIf
01012 
01013 End Function
01014 
01015 
01016 
01017 Function drawAlien(a.Alien)
01018         
01019         Select a\mode
01020         
01021                 Case 0
01022                         moveAlienLeftRight(a)
01023 
01024                 Case 1
01025                         moveAlienSinus(a)
01026                 
01027                 Case 2
01028                         moveAlienFalling(a)
01029                         
01030         End Select
01031 
01032         ; Alien hit Hero?
01033         For h.Hero = Each Hero
01034 
01035                 If ImagesOverlap(h\img, h\xPos, h\yPos, a\img, a\xPos, a\yPos) And (heroInSaveMode = False)
01036                         ; Throw a Bomb (outside the Screen) -> So Hero stays in Save-Mode. (obscure Quick-Hack). :(
01037                         b.Bomb = New Bomb
01038                         b\xPos = -30
01039                         b\yPos = SCR_Y - 50
01040                         b\img  = imgBomb
01041                         b\speed = 1
01042                         b\angel = 0
01043 
01044                         explodeAlien(a)
01045                         explodeHero(h)
01046                         Return
01047                 EndIf   
01048                 
01049         Next
01050                 
01051         DrawImage a\img, a\xPos, a\yPos, a\frame / 10
01052         a\frame = (a\frame + 1) Mod 49
01053         
01054 End Function
01055 
01056 
01057 
01058 Function drawShot(s.Shot)
01059 
01060         For h.Hero = Each Hero
01061 
01062                 ; Shot out of range?
01063                 If s\yPos < 0
01064                         Delete s
01065                         h\nShots = h\nShots - 1
01066                         Return
01067                 EndIf
01068         
01069                 For a.Alien = Each Alien
01070                         ; Shot hit Alien?
01071                         If ImagesOverlap(s\img, s\xPos, s\yPos, a\img, a\xPos, a\yPos)
01072                                 explodeAlien(a)
01073                                 h\nShots = h\nShots - 1
01074                                 Delete s
01075                                 Return
01076                         EndIf                                   
01077                 Next
01078                 
01079                 For bos.BonusShip = Each BonusShip
01080                         ; Shot hit BonusShip?
01081                         If ImagesOverlap(s\img, s\xPos, s\yPos, bos\img, bos\xPos, bos\yPos)
01082                                 explodeBonusShip(bos)
01083                                 h\nShots = h\nShots - 1
01084                                 Delete s
01085                                 Return
01086                         EndIf                                   
01087                 Next
01088 
01089         Next
01090 
01091         DrawImage s\img, s\xPos, s\yPos
01092         s\yPos = s\yPos - 10
01093 
01094 End Function
01095 
01096 
01097 
01098 Function drawBomb(b.Bomb)
01099 
01100         For h.Hero = Each Hero
01101 
01102                 ; Bomb out of range?
01103                 If (b\yPos > SCR_Y) Or (b\xPos > SCR_X) Or (b\xPos < 0)
01104                         Delete b
01105                         Return
01106                 EndIf
01107         
01108                 ; Bomb hit Hero?
01109                 If heroInSaveMode = False
01110                         If ImagesCollide(b\img, b\xPos, b\yPos, 0, h\img, h\xPos, h\yPos, 0)
01111                                 explodeHero(h)
01112                                 Delete b
01113                                 Return
01114                         EndIf                                   
01115                 EndIf
01116                         
01117         Next
01118 
01119         DrawImage b\img, b\xPos, b\yPos
01120 
01121         b\yPos = b\yPos + b\speed
01122         b\xPos = b\xPos + b\angel
01123 
01124 End Function
01125 
01126 
01127 
01128 Function drawMisile(m.Misile)
01129 
01130         Local xDelta
01131 
01132         ; Misile out of range? (The only way a Misile dies)
01133         If m\yPos < 0 Or m\xPos# < 0 Or m\xPos# > SCR_X
01134                 Delete m
01135                 Return
01136         EndIf
01137 
01138         For a.Alien = Each Alien        
01139                 ; Misile hit Alien?
01140                 If ImagesOverlap(m\img, m\xPos#, m\yPos, a\img, a\xPos, a\yPos)
01141                         explodeAlien(a)
01142                 EndIf
01143         Next
01144         
01145         For bos.BonusShip = Each BonusShip
01146                 ; Misile hit BonusShip?
01147                 If ImagesOverlap(m\img, m\xPos#, m\yPos, bos\img, bos\xPos, bos\yPos)
01148                         explodeBonusShip(bos)
01149                 EndIf
01150         Next                    
01151 
01152         DrawImage m\img, m\xPos#, m\yPos, m\frame
01153         m\yPos = m\yPos - 1
01154         m\xPos = m\xPos# + m\xDelta#
01155         m\frame = (m\frame + 1) Mod 5
01156 
01157 End Function
01158 
01159 
01160 
01161 Function drawBonus(bon.Bonus)
01162 
01163         For h.Hero = Each Hero
01164 
01165                 ; Bonus out of range?
01166                 If bon\yPos > SCR_Y
01167                         Delete bon
01168                         Return
01169                 EndIf
01170         
01171                 ; Bonus hit Hero?
01172                 If ImagesCollide(bon\img, bon\xPos, bon\yPos, 0, h\img, h\xPos, h\yPos, 0)
01173                         
01174                         Delete Each Message
01175 
01176                         ; Give Hero something usefull
01177                         If h\haveBonusSpeed = False
01178                                 h\haveBonusSpeed = True
01179                                 PlaySound(sndSpeed)
01180                                 msg.Message = New Message
01181                                 msg\Text$ = "SPEED"
01182                                 msg\timeToDisplay = MilliSecs() + 2000          
01183                         ElseIf h\haveBonusRapidFire = False
01184                                 h\haveBonusRapidFire = True
01185                                 PlaySound(sndRapidFire)
01186                                 msg.Message = New Message
01187                                 msg\Text$ = "RAPID FIRE"
01188                                 msg\timeToDisplay = MilliSecs() + 2000          
01189                         ElseIf h\haveBonusMisile = False
01190                                 h\haveBonusMisile = True
01191                                 PlaySound(sndMisile)
01192                                 msg.Message = New Message
01193                                 msg\Text$ = "MISILE"
01194                                 msg\timeToDisplay = MilliSecs() + 2000          
01195                         ElseIf h\haveBonusExtraLive = False
01196                                 h\haveBonusExtraLive = True
01197                                 h\nLives = h\nLives + 1
01198                                 PlaySound(sndExtraLive)
01199                                 msg.Message = New Message
01200                                 msg\Text$ = "EXTRA LIVE"
01201                                 msg\timeToDisplay = MilliSecs() + 2000
01202                         Else
01203                                 h\score = h\score + 1000
01204                                 PlaySound(sndPoints)
01205                                 msg.Message = New Message
01206                                 msg\Text$ = "+1000 Points"
01207                                 msg\timeToDisplay = MilliSecs() + 2000
01208                         EndIf
01209                         
01210                         Delete bon
01211                         Return
01212                 EndIf                                   
01213                         
01214         Next
01215 
01216         DrawImage bon\img, bon\xPos, bon\yPos
01217         bon\yPos = bon\yPos + 5
01218         bon\xPos = bon\xPos + Cos(bon\yPos Mod 360) * 3
01219         
01220 End Function
01221 
01222 
01223 
01224 Function drawBonusShip(bos.BonusShip)
01225 
01226         ; BonusShip out of range?
01227         If bos\xPos > SCR_X + 20
01228                 Delete bos
01229                 Return
01230         EndIf
01231         
01232         DrawImage bos\img, bos\xPos, bos\yPos
01233         bos\xPos = bos\xPos + 1
01234 
01235 End Function
01236 
01237 
01238 
01239 Function drawCruiser(cr.Cruiser, y)
01240 
01241         ; Cruiser out of range?
01242         If cr\xPos < -100
01243                 Delete cr
01244                 Return
01245         EndIf
01246         
01247         DrawImage cr\img, cr\xPos, y, cr\frame
01248         cr\xPos = cr\xPos -4
01249         cr\frame = (cr\frame + 1) Mod 4
01250 
01251         For h.Hero = Each Hero
01252                 ; Shot hit Cruiser?
01253                 For s.Shot = Each Shot
01254                         If ImagesOverlap(cr\img, cr\xPos, cr\yPos, s\img, s\xPos, s\yPos)
01255                                 h\nShots = h\nShots - 1
01256                                 h\score = h\Score + 2000                
01257                                 Delete s
01258                                 Delete cr
01259                                 msg.Message = New Message
01260                                 msg\Text$ = "+2000 Points"
01261                                 msg\timeToDisplay = MilliSecs() + 2000
01262                                 Return
01263                         EndIf
01264                 Next
01265         Next
01266                 
01267         ; Misile hit Cruiser?
01268         For m.Misile = Each Misile
01269                 If ImagesOverlap(cr\img, cr\xPos, cr\yPos, m\img, m\xPos, m\yPos)
01270                         h\score = h\Score + 2000                
01271                         Delete cr
01272                         msg.Message = New Message
01273                         msg\Text$ = "+2000 Points"
01274                         msg\timeToDisplay = MilliSecs() + 2000
01275                 EndIf
01276         Next
01277         
01278 End Function
01279 
01280 
01281 
01282 Function drawExplode1(e1.Explode1)
01283 
01284         If e1\frame > 32
01285                 Delete e1
01286                 Return
01287         EndIf
01288 
01289         DrawImage e1\img, e1\xPos, e1\yPos, e1\frame / 3
01290         e1\frame = e1\frame + 1
01291 
01292 End Function
01293 
01294 
01295 
01296 Function drawExplode2(e2.Explode2)
01297 
01298         e2\xPos = e2\xPos + e2\xs
01299         e2\yPos = e2\yPos + e2\ys
01300         e2\ys = e2\ys + 0.1
01301         
01302         ; Fragment out of range?
01303         If (e2\xPos < 0) Or (e2\xPos > SCR_X) Or (e2\yPos > SCR_Y)
01304                 Delete e2
01305                 Return
01306         ; Update Fragment-Colors
01307         Else If e2\colorB > 0
01308                 e2\colorB = e2\colorB - 5
01309         Else If e2\colorG > 0
01310                 e2\colorG = e2\colorG - 3
01311         Else If e2\colorR > 0
01312                 e2\colorR = e2\colorR - 1
01313                 If e2\colorR = 0
01314                         Delete e2
01315                         Return
01316                 EndIf
01317         EndIf
01318 
01319         Color e2\colorR, e2\colorG, e2\colorB
01320         Rect e2\xPos-1, e2\yPos-1, 3, 3
01321 
01322 End Function
01323 
01324 
01325 
01326 Function drawExplode3(e3.Explode3)
01327 
01328         If e3\frame > 4
01329                 Delete e3
01330                 Return
01331         EndIf
01332 
01333         DrawImage e3\img, e3\xPos, e3\yPos, e3\frame
01334         e3\frame = e3\frame + 1
01335 
01336 End Function
01337 
01338 
01339 
01340 Function drawBackroundStar(bs.BackroundStar)
01341 
01342         ; BackroundStar out of range?
01343         If bs\yPos > SCR_Y
01344                 bs\yPos = 0
01345         EndIf
01346         
01347         Color bs\colorR, bs\colorG, bs\colorB
01348         
01349         ; Should we draw a big BackroundStar?
01350         doBigStar = Rnd(500)
01351         If doBigStar = 0
01352                 Oval bs\xPos, bs\yPos, 5, 5, True
01353         Else
01354                 Plot bs\xPos, bs\yPos
01355         EndIf
01356 
01357         bs\yPos = bs\yPos + 1
01358         
01359 End Function
01360 
01361 
01362 
01363 Function drawBunkerFragment(bf.BunkerFragment)
01364         
01365         Local bfColor = ((bf\yPos - 50) Mod 255) * 2
01366 
01367         For h.Hero = Each Hero
01368                 For s.Shot = Each Shot
01369                         ; Shot hit BunkerFragment?
01370                         If ImageRectOverlap(s\img, s\xPos, s\yPos, bf\xPos, bf\yPos, 15, 15)
01371                                 Delete bf
01372                                 Delete s
01373                                 h\nShots = h\nShots - 1
01374                                 Return
01375                         EndIf                                   
01376                 Next
01377         Next
01378         
01379         For b.Bomb = Each Bomb
01380                 ; Bomb hit BunkerFragment?
01381                 If ImageRectOverlap(b\img, b\xPos, b\yPos, bf\xPos, bf\yPos, 15, 15)
01382                         Delete bf
01383                         Delete b
01384                         Return
01385                 EndIf                                   
01386         Next
01387         
01388         For m.Misile = Each Misile
01389                 ; Misile hit BunkerFragment?
01390                 If ImageRectOverlap(m\img, m\xPos, m\yPos, bf\xPos, bf\yPos, 15, 15)
01391                         Delete bf
01392                         Return
01393                 EndIf                                   
01394         Next
01395 
01396         Color bfColor, bfColor, bfColor
01397         Rect bf\xPos, bf\yPos, 14, 14, True
01398         
01399 End Function
01400 
01401 
01402 
01403 Function drawBubble(bu.Bubble)
01404 
01405         ; Bubble out of range?
01406         If bu\yPos < waterShore
01407                 makeExplode3(bu)
01408                 bu\yPos = SCR_Y + waterShore
01409         EndIf
01410 
01411         DrawImage bu\img, bu\xPos, bu\yPos
01412         bu\yPos = bu\yPos - bu\speed
01413 
01414 End Function
01415 
01416 
01417 
01418 Function drawHiScore()
01419 
01420         Local yOffset = SCR_Y / 20
01421         Local yPos = SCR_Y / 2 - 50
01422         Local index = 1
01423 
01424         Color 255, 255, 0
01425         SetFont(fntStyleMid)
01426                 
01427         For table.HiScore = Each HiScore
01428         
01429                 If index < 11
01430                         ; Leave new HiScore-Entry as blank line.
01431                         If insertIndex = index
01432                                 Text SCR_X/2 - 240, yPos, "" + index + ".", True, True
01433                                 yPos = yPos + yOffset
01434                                 index = index + 1
01435                         EndIf
01436         
01437                         Text SCR_X/2 - 240, yPos, "" + index + ".", True, True
01438                         Text SCR_X/2 - 140, yPos, table\name$, True, True
01439                         Text SCR_X/2 - 0, yPos, table\points, True, True
01440                         Text SCR_X/2 + 180, yPos, table\date, True, True
01441                         yPos = yPos + yOffset
01442                         index = index + 1
01443                 EndIf
01444         Next
01445         
01446 End Function
01447 
01448 
01449 
01450 Function drawInputName(in.InputName)
01451 
01452         Local index             = 1
01453         Local xPos              = SCR_X / 2 - 13 * 20
01454         Local time              = MilliSecs()
01455         Local yOffset   = SCR_Y / 20
01456         Local yPos              = (SCR_Y / 2 - 50) + ((insertIndex-1) * yOffset)
01457 
01458 
01459         If Len(in\name$) < 3
01460                 
01461                 ; Draw Input-Chars
01462                 For index=65 To 90
01463                         If index = in\hiLightIndex
01464                                 SetFont(fntStyleBig)
01465                                 Text xPos, 50, Chr$(index)
01466                         Else
01467                                 SetFont(fntStyleSmall)
01468                                 Text xPos, 50, Chr$(index)
01469                         EndIf
01470         
01471                         xPos = xPos + 20
01472                 Next
01473                 
01474                 
01475                 ; Get input
01476                 If in\inTimeDelta < time - 100
01477                 
01478                         If KeyDown(203) And in\hiLightIndex > 65
01479                                 in\hiLightIndex = in\hiLightIndex - 1
01480                         EndIf
01481                         
01482                         If KeyDown(205) And in\hiLightIndex < 90
01483                                 in\hiLightIndex = in\hiLightIndex + 1
01484                         EndIf
01485                         
01486                         If KeyHit(57)
01487                                 in\name$ = in\name$ + Chr$(in\hiLightIndex)
01488                         EndIf
01489                         
01490                         in\inTimeDelta = MilliSecs()
01491                         
01492                 EndIf
01493                 
01494                 ; Display Input, so far done.
01495                 SetFont(fntStyleMid)
01496                 Text SCR_X/2 - 140, yPos, in\name$, True, True
01497                 
01498         EndIf                   
01499 
01500 End Function
01501 
01502 
01503 
01504 Function drawLevelChange(newLevel, soundOn)
01505         
01506         Local imgIndex = newLevel Mod 4
01507         Local sndIndex = newLevel Mod 3
01508         Local alienHeadFrame = 0
01509         Local now = 0
01510         Local i# = 1.0
01511 
01512         Cls
01513 
01514         Select imgIndex
01515                 
01516                 Case 3
01517                         DrawImage imgBack1, SCR_X/2, SCR_Y/2
01518                 Case 2
01519                         DrawImage imgBack2, SCR_X/2, SCR_Y/2
01520                 Case 1
01521                         DrawImage imgBack3, SCR_X/2, SCR_Y/2
01522                 Case 0
01523                         ; Each 4th Level display AlienHead-Movie
01524                         FlushKeys
01525                         While Not KeyHit(57)
01526                                 Cls
01527                                 now = MilliSecs()
01528                                 DrawImage imgAlienHeadBase, SCR_X/2, SCR_Y/2
01529                                 DrawImage imgAlienHead, SCR_X/2 - 2, SCR_Y/2 + 58, alienHeadFrame
01530                                 alienHeadFrame = (alienHeadFrame + 1) Mod 13
01531                                 SetFont(fntStyleMid)
01532                                 Color 100, 100, 200                             
01533                                 Text SCR_X/2, 80, "W E    W I L L    W I N", True, True
01534                                 Flip
01535                                 If (now - 8000) > demoTime
01536                                         Exit
01537                                 EndIf
01538                                 
01539                                 ; Decrease Volume
01540                                 If (backroundMusic <> 1) And (i > 0.0) And (soundOn = True)
01541                                         i = i - 0.1
01542                                         ChannelVolume chnLoop, i
01543                                 EndIf
01544 
01545                                 ; Play new Music
01546                                 If (i >= 0.0) And (i < 0.1) And (soundOn = True)
01547                                         i = -1
01548                                         StopChannel(chnLoop)
01549                                         LoopSound sndLoopNormal
01550                                         ChannelVolume chnLoop, 1.0
01551                                         chnLoop = PlaySound(sndLoopNormal)
01552                                         backroundMusic = 1
01553                                 EndIf
01554                                 Delay(400 - alienHeadFrame * 20)
01555                         Wend
01556 
01557                         ; User canceled Alien-Movie? -> Play new Music
01558                         If (backroundMusic <> 1) And (i > -1)  And (soundOn = True)
01559                                 StopChannel(chnLoop)
01560                                 LoopSound sndLoopNormal
01561                                 ChannelVolume chnLoop, 1.0
01562                                 chnLoop = PlaySound(sndLoopNormal)
01563                                 backroundMusic = 1
01564                         EndIf
01565 
01566                         Return                  
01567         
01568         End Select
01569 
01570         SetFont(fntStyleBig)
01571         Color 255, 255, 0                               
01572         Text SCR_X/2, SCR_Y/2, "Level " + newLevel, True, True
01573         
01574         Flip
01575         
01576         If soundOn = True
01577                 If sndIndex = 0
01578                         ; Setup new LoopSound.
01579                         For i=1.0 To 0.0 Step -0.01
01580                                 ChannelVolume chnLoop, i
01581                                 Delay(10)
01582                         Next
01583                         StopChannel(chnLoop)
01584                         LoopSound sndLoopWater
01585                         ChannelVolume chnLoop, 1.0
01586                         chnLoop = PlaySound(sndLoopWater)
01587                         backroundMusic = 2
01588                 Else
01589                         If backroundMusic <> 1
01590                                 ; Setup new LoopSound.
01591                                 For i=1.0 To 0.0 Step -0.01
01592                                         ChannelVolume chnLoop, i
01593                                         Delay(10)
01594                                 Next
01595                                 StopChannel(chnLoop)
01596                                 LoopSound sndLoopNormal
01597                                 ChannelVolume chnLoop, 1.0
01598                                 chnLoop = PlaySound(sndLoopNormal)
01599                                 backroundMusic = 1
01600                         EndIf   
01601                 EndIf
01602         EndIf
01603 
01604         Delay(2000)
01605         
01606 End Function
01607 
01608 
01609 
01610 Function drawMessage(msg.Message)
01611         
01612         Local now = MilliSecs()
01613 
01614         ;Time to destroy this Message?
01615         If msg\timeToDisplay < now
01616                 Delete msg
01617                 Return
01618         EndIf
01619         
01620         SetFont(fntStyleSmall)
01621         Color 255, 255, 0
01622         Text SCR_X / 2, 0, msg\Text$, True
01623 
01624 End Function
01625 
01626 
01627 
01628 Function drawTitleScreen()
01629 
01630         DrawImage imgTitle, SCR_X/2, 220
01631         ;drawGfxDriverInfo()
01632         Color 255, 255, 255
01633         SetFont(fntStyleCourier)
01634         Text SCR_X / 2, 450, "[SPACE]        ->  Shot / Start", True
01635         Text SCR_X / 2, 465, "[LEFT][RIGHT]  ->  Move Hero   ", True
01636         Text SCR_X / 2, 480, "[ESC]          ->  Exit        ", True
01637         Text SCR_X / 2, 495, "[P]            ->  Pause       ", True
01638         Text SCR_X / 2, 510, "[S]            ->  Sound on/off", True
01639         Text SCR_X / 2, SCR_Y - 30, "written by s_roll . max respect to MosFAT-Crew . October 2003", True
01640 
01641 End Function
01642 
01643 
01644 
01645 Function drawGfxDriverInfo()
01646 
01647         Local nModes = 0
01648         Local i = 0
01649 
01650         SetFont(fntStyleSmall)
01651         Color 255, 255, 0
01652         
01653         nModes = CountGfxDrivers()
01654         
01655         For i=1 To nModes
01656                 Text 50, 400 + i*20, "" + i + "." + GfxDriverName$(i)
01657         Next
01658         
01659         i = i + 1
01660         Text 50, 400 + i*20, "Total Graphics-Memory: " + TotalVidMem()/1024 + " kBytes"
01661 
01662         i = i + 1
01663         Text 50, 400 + i*20, "Available Graphics-Memory: " + AvailVidMem()/1024 + " kBytes"
01664 
01665 End Function
01666 
01667 
01668 
01669 Function drawSpider(sp.Spider)
01670 
01671         Local now = MilliSecs()
01672         Local i = 0
01673         Local k = 0
01674 
01675         DrawImage sp\img, sp\xPos, sp\yPos
01676         Color 200, 200, 200
01677         Line sp\xPos + 35, 0, sp\xPos + 35, sp\yPos - 135
01678 
01679         ; Move Spider slightly into Screen
01680         sp\yPos = sp\yPos + Sin(sp\swing1) + Sin(sp\swing2)
01681         sp\swing1 = (sp\swing1 + 1) Mod 360
01682         sp\swing2 = (sp\swing2 + 0.3) Mod 360
01683 
01684         If (sp\yPos > 150)
01685                 sp\destReached = True
01686         EndIf
01687         
01688         If (sp\destReached = False)
01689                 sp\yPos = sp\yPos + 0.1
01690         Else
01691                 ; Make some Bombs (spreeding from his hand) as Spider-Weapon
01692                 If (now > sp\bombTime + 1500) And (heroInSaveMode = False)
01693                         If (sp\bombTimeCount = 0) And (sp\yPos > 25)
01694                                 For k=1 To 3
01695                                         For i = sp\xPos-200 To sp\xPos+200 Step 40
01696                                                 b.Bomb = New Bomb
01697                                                 b\xPos = i
01698                                                 b\yPos = sp\yPos + 100 + k*5
01699                                                 b\img  = imgBomb
01700                                                 b\speed = 2
01701                                                 b\angel = 0
01702                                         Next
01703                                 Next
01704                         Else
01705                                 For i = -5 To 5
01706                                         b.Bomb = New Bomb
01707                                         b\xPos = sp\xPos + 100
01708                                         b\yPos = sp\yPos + 25
01709                                         b\img  = imgBomb
01710                                         b\speed = 3
01711                                         b\angel = i + sp\bombAngelOffset
01712                                 Next
01713                         EndIf
01714                         sp\bombTime = now
01715                         sp\bombTimeCount = (sp\bombTimeCount + 1) Mod 3
01716                         ; Rotate Bomb-Spreed-Angel so Hero can't stay at fix Position
01717                         sp\bombAngelOffset = sp\bombAngelOffset + 0.3
01718                         If sp\bombAngelOffset >= 2
01719                                 sp\bombAngelOffset = 0.0
01720                         EndIf
01721                 EndIf
01722         EndIf
01723         
01724         For h.Hero = Each Hero
01725                 ; Shot hit Spider?
01726                 For s.Shot = Each Shot
01727                         If ImagesCollide(sp\img, sp\xPos, sp\yPos, 0, s\img, s\xPos, s\yPos, 0)
01728                                 If sp\destReached = True
01729                                         sp\hits = sp\hits + 2
01730                                 EndIf
01731                                 makeExplode2(s\xPos, s\yPos)    
01732                                 h\nShots = h\nShots - 1
01733                                 Delete s
01734                         EndIf
01735                 Next
01736         Next
01737                 
01738         ; Misile hit Spider?
01739         For m.Misile = Each Misile
01740                 If ImagesCollide(sp\img, sp\xPos, sp\yPos, 0, m\img, m\xPos, m\yPos, 0)
01741                         If sp\destReached = True
01742                                 sp\hits = sp\hits + 1
01743                         EndIf
01744                         makeExplode2(m\xPos, m\yPos)    
01745                 EndIf
01746         Next
01747         
01748         ; Draw Spider-PowerMeter
01749         Color 255, 255, 0
01750         For i=0 To 100-sp\hits Step 10
01751                 Rect (SCR_X / 2 - 60) + i, 0, 8, 20
01752         Next
01753 
01754         If sp\hits > 100
01755                 explodeSpider(sp)
01756         EndIf
01757 
01758 End Function
01759 
01760 
01761 
01762 Function explodeHero(h.Hero)
01763 
01764         If heroInSaveMode = False
01765         
01766                 PlaySound(sndExplode2)
01767                 
01768                 e.Explode1      = New Explode1
01769                 e\xPos          = h\xPos
01770                 e\yPos          = h\yPos
01771                 e\img           = imgExplode2
01772                 e\frame         = 0
01773                 
01774                 If h\nLives > 0
01775                         h\nLives = h\nLives - 1
01776                 EndIf
01777         
01778                 resetHero(h)
01779                 heroInSaveMode = True
01780                 
01781                 ; Give Hero all Bunkers again
01782                 Delete Each BunkerFragment
01783                 initBunkerFragments()
01784         EndIf
01785                         
01786 End Function
01787 
01788 
01789 
01790 Function explodeAlien(a.Alien)
01791 
01792         makeExplode1(a\xPos, a\yPos)
01793 
01794         nAliens = nAliens - 1
01795 
01796         h.Hero = First Hero
01797         If h <> Null
01798                 h\score = h\score + 100
01799         EndIf
01800 
01801         Delete a
01802         
01803 End Function
01804 
01805 
01806 
01807 Function explodeBonusShip(bos.BonusShip)
01808 
01809         makeExplode1(bos\xPos, bos\yPos)
01810         
01811         makeBonus(bos)
01812 
01813         h.Hero = First Hero
01814         If h <> Null
01815                 h\score = h\score + 200
01816         EndIf           
01817 
01818         Delete bos
01819 
01820 End Function
01821 
01822 
01823 
01824 Function explodeSpider(sp.Spider)
01825 
01826         Local i = 0
01827 
01828         makeExplode1(sp\xPos, sp\yPos)
01829         
01830         For i = 1 To 10
01831                 makeExplode2(sp\xPos-Rnd(10*i), sp\yPos-Rnd(10*i))
01832                 makeExplode2(sp\xPos-Rnd(10*i), sp\yPos-Rnd(10*i))
01833         Next
01834         
01835         h.Hero = First Hero
01836         If h <> Null
01837                 h\score = h\score + 500
01838         EndIf           
01839 
01840         Delete sp
01841         nAliens = nAliens - 1
01842 
01843 End Function
01844 
01845 
01846 
01847 Function makeBonus(bos.BonusShip)
01848 
01849         bon.Bonus       = New Bonus
01850         bon\xPos        = bos\xPos
01851         bon\yPos        = bos\yPos
01852         bon\img         = imgBonus
01853 
01854 End Function
01855 
01856 
01857 
01858 Function makeBomb(a.Alien)
01859 
01860         For h.Hero = Each Hero
01861         
01862                 If a\xPos - 100 < h\xPos And a\xPos + 100 > h\xPos
01863         
01864                         b.Bomb = New Bomb
01865                         b\xPos = a\xPos
01866                         b\yPos = a\yPos + 10
01867                         b\img  = imgBomb
01868                         b\speed = Rnd(4, 8)
01869                         b\angel = 0
01870                         
01871                 EndIf
01872                 
01873         Next
01874         
01875 End Function
01876 
01877 
01878 
01879 Function makeMisile(h.Hero)
01880 
01881         ; Allow only one Misile on Screen (Singelton)
01882         temp.Misile = First Misile
01883         If temp = Null
01884         
01885                 m.Misile = New Misile
01886                 m\xPos# = h\xPos
01887                 m\yPos = h\yPos + 18
01888                 m\img  = imgMisile
01889                 m\xDelta# = Rnd(-30,30) / 100
01890                 m\frame = 0
01891                         
01892         EndIf
01893         
01894 End Function
01895 
01896 
01897 
01898 Function makeBonusShip()
01899         
01900         ; Allow only one BonusShip on Screen (Singelton)
01901         bos.BonusShip = First BonusShip
01902         If bos = Null
01903                 bs.BonusShip = New BonusShip
01904                 bs\xPos = -20
01905                 bs\yPos = 30
01906                 bs\img  = imgBonusShip
01907         EndIf
01908         
01909 End Function
01910 
01911 
01912 
01913 Function makeCruiser()
01914         
01915         ; Allow only one Cruiser on Screen (Singelton)
01916         cr.Cruiser = First Cruiser
01917         If cr = Null
01918                 cr.Cruiser      = New Cruiser
01919                 cr\xPos         = SCR_X + 20
01920                 cr\yPos         = 95
01921                 cr\img          = imgCruiser
01922                 cr\frame        = 0
01923         EndIf
01924         
01925 End Function
01926 
01927 
01928 
01929 Function makeSpider()
01930         
01931         ; Allow only one Spider on Screen (Singelton)
01932         sp.Spider = First Spider
01933         If sp = Null
01934                 sp.Spider                       = New Spider
01935                 sp\xPos                         = Rnd(124, SCR_X - 124)
01936                 sp\yPos                         = -135
01937                 sp\swing1                       = 0
01938                 sp\swing2                       = 70
01939                 sp\destReached          = False
01940                 sp\img                          = imgSpider
01941                 sp\hits                         = 0
01942                 sp\bombTime                     = MilliSecs()
01943                 sp\bombAngelOffset      = 0.0
01944                 sp\bombTimeCount        = 0
01945                 
01946                 nAliens = nAliens + 1
01947         EndIf
01948         
01949 End Function
01950 
01951 
01952 
01953 Function makeExplode1(x, y)
01954 
01955         PlaySound(sndExplode1)
01956 
01957         e1.Explode1     = New Explode1
01958         e1\xPos         = x
01959         e1\yPos         = y
01960         e1\img          = imgExplode1
01961         e1\frame        = 0
01962 
01963 End Function
01964 
01965 
01966 
01967 Function makeExplode2(x, y)
01968 
01969         Local fragCount = 0
01970         Local anstep# = 0.0
01971         Local an# = 0.0
01972         Local i = 0
01973         Local intensity = 20
01974         
01975         PlaySound(sndExplode3)
01976 
01977         fragCount = Rnd(intensity) + intensity
01978         anstep = 360.0 / fragCount
01979         an = Rnd(anstep)
01980         
01981         For i=1 To fragCount
01982                 e2.Explode2 = New Explode2
01983                 e2\xPos         = x
01984                 e2\yPos         = y
01985                 e2\xs           = Cos(an) * Rnd(3, 4)
01986                 e2\ys           = Sin(an) * Rnd(3, 4)
01987                 e2\colorR       = 255
01988                 e2\colorG       = 255
01989                 e2\colorB       = 255
01990 
01991                 an = an + anstep
01992         Next
01993 
01994         
01995 End Function
01996 
01997 
01998 
01999 Function makeExplode3(bu.Bubble)
02000 
02001         e3.Explode3     = New Explode3
02002         e3\xPos         = bu\xPos
02003         e3\yPos         = bu\yPos
02004         e3\img          = imgExplode3
02005         e3\frame        = 0
02006         
02007 End Function
02008 
02009 
02010 
02011 Function loadGraphics()
02012         
02013         ; Set Handles of Images to their center
02014         AutoMidHandle True
02015         
02016         imgAlien1 = LoadAnimImage("alien1.png", 20, 17, 0, 5)
02017         If imgAlien1 = 0 Then Return -1
02018 
02019         imgAlien2 = LoadAnimImage("alien2.png", 10, 14, 0, 5)
02020         If imgAlien2 = 0 Then Return -1
02021 
02022         imgAlien3 = LoadAnimImage("alien3.png", 14, 15, 0, 5)
02023         If imgAlien3 = 0 Then Return -1
02024 
02025         imgExplode1 = LoadAnimImage("explode1.png",20, 20, 0, 11)
02026         If imgExplode1 = 0 Then Return -1
02027 
02028         imgExplode2 = LoadAnimImage("explode2.png",18, 20, 0, 11)
02029         If imgExplode2 = 0 Then Return -1
02030 
02031         imgExplode3 = LoadAnimImage("explode3.png",10, 10, 0, 5)
02032         If imgExplode3 = 0 Then Return -1
02033 
02034         imgHero = LoadAnimImage("hero.png", 18, 20, 0, 4)
02035         If imgHero = 0 Then Return -1
02036 
02037         imgShot = LoadImage("shot.png")
02038         If imgShot = 0 Then Return -1
02039         
02040         imgBomb = LoadImage("bomb.png")
02041         If imgBomb = 0 Then Return -1
02042 
02043         imgMisile = LoadAnimImage("misile.png", 9, 9, 0, 5)
02044         If imgMisile = 0 Then Return -1
02045 
02046         imgBonus = LoadImage("bonus.png")
02047         If imgBonus = 0 Then Return -1
02048 
02049         imgBonusShip = LoadImage("bonusship.png")
02050         If imgBonusShip = 0 Then Return -1
02051 
02052         imgCruiser = LoadAnimImage("cruiser.png", 11, 15, 0, 4)
02053         If imgCruiser = 0 Then Return -1
02054 
02055         imgBubbleSmall = LoadImage("bubblesmall.png")
02056         If imgBubbleSmall = 0 Then Return -1
02057 
02058         imgBubbleMid = LoadImage("bubblemid.png")
02059         If imgBubbleMid = 0 Then Return -1
02060 
02061         imgBubbleBig = LoadImage("bubblebig.png")
02062         If imgBubbleBig = 0 Then Return -1
02063         
02064         imgTitle = LoadImage("title.png")
02065         If imgTitle = 0 Then Return -1
02066         
02067         imgBack1 = LoadImage("back1.png")
02068         If imgBack1 = 0 Then Return -1
02069         
02070         imgBack2 = LoadImage("back2.png")
02071         If imgBack2 = 0 Then Return -1
02072 
02073         imgBack3 = LoadImage("back3.png")
02074         If imgBack3 = 0 Then Return -1
02075         
02076         imgAlienHeadBase = LoadImage("headbase.png")
02077         If imgAlienHeadBase = 0 Then Return -1
02078 
02079         imgAlienHead = LoadAnimImage("heads.png", 75, 70, 0, 13)
02080         If imgAlienHead = 0 Then Return -1
02081 
02082         imgSpider = LoadImage("spider.png")
02083         If imgSpider = 0 Then Return -1
02084 
02085         fntStyleBig = LoadFont("Arial Black", 50, True, False, False)
02086         If fntStyleBig = 0 Then Return -1
02087 
02088         fntStyleMid = LoadFont("Arial Black", 30, True, False, False)
02089         If fntStyleMid = 0 Then Return -1
02090 
02091         fntStyleSmall = LoadFont("Arial Black", 18, True, False, False)
02092         If fntStyleSmall = 0 Then Return -1
02093         
02094         fntStyleCourier = LoadFont("Courier", 10, False, False, False)
02095         If fntStyleSmall = 0 Then Return -1
02096 
02097         Text 0, 40, "Rescaling Graphics."
02098 
02099         ScaleImage imgAlien1, 2.0, 2.0
02100         ScaleImage imgAlien2, 3.0, 3.0
02101         ScaleImage imgAlien3, 3.0, 3.0
02102         ScaleImage imgExplode1, 3.0, 3.0        
02103         ScaleImage imgExplode2, 3.0, 3.0        
02104         ScaleImage imgHero, 3.0, 3.0
02105         ScaleImage imgShot, 2.0, 2.0
02106         ScaleImage imgBomb, 2.0, 2.0
02107         ScaleImage imgMisile, 2.0, 2.0
02108         ScaleImage imgBonusShip, 2.0, 2.0
02109         ScaleImage imgCruiser, 3.0, 3.0
02110         ScaleImage imgAlienHeadBase, 2.0, 2.0
02111         ScaleImage imgAlienHead, 2.0, 2.0
02112         ResizeImage imgTitle, SCR_X, SCR_Y
02113         ResizeImage imgBack1, SCR_X, SCR_Y
02114         Text 0, 60, "Done."
02115         ResizeImage imgBack2, SCR_X, SCR_Y
02116         Text 0, 80, "Starting mainLoop()."
02117         ResizeImage imgBack3, SCR_X, SCR_Y
02118 
02119         AutoMidHandle False
02120 
02121         Return 0
02122         
02123 End Function
02124 
02125 
02126 
02127 Function loadSounds()
02128 
02129         ; Get a Sound. Playing when Alien explode.
02130         sndExplode1 = LoadSound("explode1.wav")
02131         If sndExplode1 = 0 Then Return -1
02132 
02133         ; Get a Sound. Playing when Hero explode.
02134         sndExplode2 = LoadSound("explode2.wav")
02135         If sndExplode2 = 0 Then Return -1
02136 
02137         ; Get a Sound. Playing when Spider is hit.
02138         sndExplode3 = LoadSound("explode3.wav")
02139         If sndExplode3 = 0 Then Return -1
02140 
02141         ; Get a Sound. Playing when Hero get Bonus-Speed.
02142         sndSpeed = LoadSound("speed.wav")
02143         If sndSpeed = 0 Then Return -1
02144 
02145         ; Get a Sound. Playing when Hero get Bonus-RapidFire.
02146         sndRapidFire = LoadSound("rapidfire2.wav")
02147         If sndRapidFire = 0 Then Return -1
02148 
02149         ; Get a Sound. Playing when Hero get Bonus-Misile.
02150         sndMisile = LoadSound("misile.wav")
02151         If sndMisile = 0 Then Return -1
02152 
02153         ; Get a Sound. Playing when Hero get Bonus-ExtraLive.
02154         sndExtraLive = LoadSound("extralive.wav")
02155         If sndExtraLive = 0 Then Return -1
02156 
02157         ; Get a Sound. Playing when Hero get Bonus-Points.
02158         sndPoints = LoadSound("points.wav")
02159         If sndPoints = 0 Then Return -1
02160 
02161         ; Get a LoopSound. Playing at backround.
02162         sndLoopNormal = LoadSound("loop.mp3")
02163         If sndLoopNormal = 0 Then Return -1
02164         
02165         ; Get a LoopSound. Playing at backround in UnderWater-Level.
02166         sndLoopWater = LoadSound("loopwater.mp3")
02167         If sndLoopWater = 0 Then Return -1
02168         
02169         ; Setup LoopSound.
02170         LoopSound sndLoopNormal
02171         chnLoop = PlaySound(sndLoopNormal)
02172         backroundMusic = 1
02173         PauseChannel(chnLoop)
02174         
02175         Return 0
02176         
02177 End Function
02178 
02179 
02180 
02181 Function disposeObjects()
02182 
02183         For h.Hero = Each Hero
02184                 h\nShots = 0
02185         Next
02186         
02187         nAliens = 0
02188         
02189         Delete Each Alien
02190         Delete Each Shot
02191         Delete Each Bomb
02192         Delete Each Misile
02193         Delete Each Bonus
02194         Delete Each BonusShip
02195         Delete Each Cruiser
02196         Delete Each Explode1
02197         Delete Each Explode2
02198         Delete Each Explode3
02199         Delete Each BackroundStar
02200         Delete Each Bubble
02201         Delete Each Spider
02202         Delete Each BunkerFragment
02203         Delete Each InputName
02204         Delete Each HiScore
02205         
02206 End Function
02207 
02208 
02209 
02210 Function readHiScore()
02211 
02212         Local fHandle = 0
02213 
02214         fHandle = ReadFile("avshscore.txt")
02215         If fHandle <= 0
02216                 Return -1       
02217         Else
02218         
02219                 SeekFile(fHandle, 0)
02220                 
02221                 For i=1 To 10
02222                         table.HiScore = New HiScore
02223                         table\name$ = ReadString$(fHandle)
02224                         table\points = ReadInt(fHandle)
02225                         table\date$ = ReadString$(fHandle)
02226                 Next
02227 
02228         EndIf
02229         
02230         CloseFile(fHandle)
02231         
02232         Return 0
02233         
02234 End Function
02235 
02236 
02237 
02238 Function writeHiScore()
02239 
02240         Local fHandle = 0
02241 
02242         fHandle = WriteFile("avshscore.txt")
02243         If fHandle <= 0
02244                 Return -1       
02245         Else
02246         
02247                 SeekFile(fHandle, 0)
02248         
02249                 For table.HiScore = Each HiScore
02250                         WriteString(fHandle, table\name)
02251                         WriteInt(fHandle, table\points)
02252                         WriteString(fHandle, table\date)
02253                 Next
02254 
02255         EndIf
02256         
02257         CloseFile(fHandle)
02258         
02259         Return 0
02260         
02261 End Function
02262 
02263 
02264 
02265 Function writeNewHiScore()
02266 
02267         Local fHandle = 0
02268 
02269         fHandle = WriteFile("avshscore.txt")
02270         If fHandle <= 0
02271                 Return -1
02272         Else
02273 
02274                 SeekFile(fHandle, 0)
02275         
02276                 ; Ensure only 10 entries.
02277                 For table.HiScore = Each HiScore
02278                         Delete table
02279                 Next
02280 
02281                 For i=1 To 10
02282                         table.HiScore = New HiScore
02283                         table\name$ = "FAT"
02284                         table\points = 10000 - i*800
02285                         table\date$ = "18 May 1974"
02286                 Next
02287 
02288                 For table.HiScore = Each HiScore
02289                         WriteString(fHandle, table\name$)
02290                         WriteInt(fHandle, table\points)
02291                         WriteString(fHandle, table\date$)
02292                 Next
02293                         
02294         EndIf
02295         
02296         Return 0
02297 
02298 End Function
02299 
02300 
02301 
02302 End

Generated on Tue Dec 4 20:21:29 2007 for AlienVSHero by  doxygen 1.5.4