Dim Shared as Byte NextLevel Type WorldManager As Byte World(0 to 63, 0 to 63) As Player P = Player(1, 1) As Score S = Score (418 - 63, 10, 20, 15, 0) As Score Destroyed = Score (890, 10, 20, 15, 0) As Score CrystalMax = Score (418 + 63, 10, 20, 15, 0) As ANY PTR Background As ANY PTR crystal As ANY PTR earth As ANY PTR massive As ANY PTR Stone As ANY PTR StairDown As ANY PTR StairDownClosed As ANY PTR StairUp As ANY PTR Block As ANY PTR Pickaxe As ANY PTR BCrystal As ANY PTR CrystalEarth As ANY PTR BCrystalEarth As ANY PTR DeadEarth As ANY PTR Barrel As ANY PTR LeakG As ANY PTR TNT As ANY PTR TNTPlaced As Integer EntityMoveCounter(0 to 63) As Integer EntitySpeed = 25 As Integer LeakCounter As Integer LeakSpeed = 120 As Integer ExplosionCounter As Integer ExplosionSpeed = 180 As Integer CurrentWorld 'Sound Counter As Byte SCbreakstone As Byte SCdig As Byte SCpickup As Byte SCrollstone As Byte SCstonecoll As Byte SCstoneslideside As Byte SCfassroll As Byte SCLeak 'Flammen As FlameAnim Flame = FlameAnim() Declare Constructor () Declare Sub LoadWorld() Declare Sub Control() Declare Sub G() Declare Sub MoveEntities(a as Integer) Declare Sub MoveToSide (a as Integer, EntityID as Integer) Declare Sub Leak() Declare Sub Respawn() Declare Sub ResetTimer() Declare Sub SetSpawn() Declare Sub TNTControl() End Type Constructor WorldManager() P.SetWorld(World()) Background = LoadImgFile("res\map\background.bmp") crystal = LoadImgFile("res\map\crystal.bmp") earth = LoadImgFile("res\map\earth.bmp") massive = LoadImgFile("res\map\massive.bmp") Stone = LoadImgFile("res\map\stone.bmp") StairDown = LoadImgFile("res\map\stairdown.bmp") StairUp = LoadImgFile("res\map\stairup.bmp") StairDownClosed = LoadImgFile("res\map\stairdownclosed.bmp") Block = LoadImgFile("res\map\block.bmp") Pickaxe = LoadImgFile("res\map\pickaxe.bmp") BCrystal = LoadImgFile("res\map\bcrystal.bmp") CrystalEarth = LoadImgFile("res\map\crystalearth.bmp") BCrystalEarth = LoadImgFile("res\map\bcrystalearth.bmp") DeadEarth = LoadImgFile("res\map\deadearth.bmp") Barrel = LoadImgFile("res\map\barrel.bmp") LeakG = LoadImgFile("res\map\leak.bmp") TNT = LoadImgFile("res\map\tnt.bmp") TNTPlaced = LoadImgFile("res\map\tntplaced.bmp") End Constructor Sub WorldManager.LoadWorld() Dim as Integer File Dim as Integer a, b File = Freefile If Open("lvl\Level" & STR(CurrentWorld) & ".dat" For Input as #File) = 0 then For a = 0 to 63 For b = 0 to 63 Input #File, World(a, b) Next b Next a Close #File Else DEGUIError("ERROR", "Could not open file 'lvl\Level" & STR(CurrentWorld) & ".dat'") End 0 Endif CrystalMax.Score = 0 For a = 0 to 63 For b = 0 to 63 If World(a, b) = 3 then CrystalMax.Score += 1 If World(a, b) = 10 then CrystalMax.Score += 1 Next b Next a End Sub Sub WorldManager.Control() Dim as Integer a P.Control() If P.Dead = 0 then If World(P.XPos, P.YPos) = 0 then 'Sand wegbuddeln World(P.XPos, P.YPos) = 1 Destroyed.Score += 1 ResetTimer() If Sound = 1 then TiPlaySample("dig" & STR(SCdig)) SCdig += 1 If SCdig > 4 then SCdig = 0 Endif If World(P.XPos, P.YPos) = 3 Or World(P.XPos, P.YPos) = 9 then 'Kristall aufsammeln World(P.XPos, P.YPos) = 1 S.Score += 1 ResetTimer() If Sound = 1 then TiPlaySample("pickup" & STR(SCpickup)) SCpickup += 1 If SCpickup > 4 then SCpickup = 0 Endif If World(P.XPos, P.YPos) = 10 Or World(P.XPos, P.YPos) = 11 then 'Kristallerde aufsammeln World(P.XPos, P.YPos) = 1 S.Score += 1 ResetTimer() If Sound = 1 then TiPlaySample("pickup" & STR(SCpickup)) SCpickup += 1 If SCpickup > 4 then SCpickup = 0 If Sound = 1 then TiPlaySample("dig" & STR(SCpickup)) SCdig += 1 If SCdig > 4 then SCdig = 0 Endif If World(P.XPos, P.YPos) = 8 then 'Spitzhacke aufheben World(P.XPos, P.YPos) = 1 P.GotPickaxe = 1 ResetTimer() If Sound = 1 then TiPlaySample("pickup" & STR(SCpickup)) SCpickup += 1 If SCpickup > 4 then SCpickup = 0 Endif If World(P.XPos, P.YPos) = 14 then 'TNT aufheben If P.GotTNT = 0 then World(P.XPos, P.YPos) = 1 P.GotTNT = 1 ResetTimer() If Sound = 1 then TiPlaySample("pickup" & STR(SCpickup)) SCpickup += 1 If SCpickup > 4 then SCpickup = 0 Endif Endif If World(P.XPos, P.YPos) = 7 And P.GotPickaxe = 1 then 'Stein Weghaun World(P.XPos, P.YPos) = 1 Destroyed.Score += 1 ResetTimer() If Sound = 1 then TiPlaySample("breakstone" & STR(SCbreakstone)) SCbreakstone += 1 If SCbreakstone > 4 then SCbreakstone = 0 Endif If World(P.XPos, P.YPos) = 5 And S.Score >= CrystalMax.Score then 'Level beenden Dim as GUI NextLVLG Dim as LevelCodes LC NextLVLG.NewLabel(400 + 40, 350, "Levelcode: ") NextLVLG.NewTextField(495 + 40, 350, 6, STR(LC.Codes(CurrentWorld + 1))) NextLVLG.NewButton(512 - 96, 384 - 24, "res\menu\okup.bmp", "res\menu\okdown.bmp", "nextlvl", @Ev) If Sound = 1 then TiPlaySample("finish") While(NextLevel = 0) NextLVLG.Control() ScreenLock NextLVLG.G() ScreenUnlock Sleep 10 Wend NextLevel = 0 CurrentWorld += 1 Respawn() Endif If World(P.XPos, P.YPos) = 2 then P.Dead = 1 : If Sound = 1 then TiPlaySample("dead") If World(P.XPos, P.YPos) = 13 then P.Dead = 1 : If Sound = 1 then TiPlaySample("dead") If World(P.XPos, P.YPos) = 50 then P.Dead = 1 : If Sound = 1 then TiPlaySample("dead") If World(P.XPos, P.YPos) = 12 then World(P.XPos, P.YPos) = 1 Destroyed.Score += 1 ResetTimer() If Sound = 1 then TiPlaySample("dig" & STR(SCdig)) SCdig += 1 If SCdig > 4 then SCdig = 0 P.Dead = 1 If Sound = 1 then TiPlaySample("dead") Endif Flame.Control() TNTControl() Endif Leak() For a = 0 to 63 If EntityMoveCounter(a) <= 0 then EntityMoveCounter(a) = EntitySpeed MoveEntities(a) Endif EntityMoveCounter(a) -= 1 Next a End Sub Sub WorldManager.G() Dim as Integer a, b 'Hintergrund For a = 0 to 1024 - 64 Step 64 For b = 0 to 768 - 64 Step 64 Put(a, b), Background, PSet Next b Next a 'Vordergrund For a = 0 to 15 For b = 0 to 11 If P.XPos - 7 + a >= 0 And P.XPos - 7 + a <= 63 And _ P.YPos - 5 + b >= 0 And P.YPos - 5 + b <= 63 then If World(P.XPos - 7 + a, P.YPos - 5 + b) = 0 then Put(a * 64, b * 64), earth, PSet If World(P.XPos - 7 + a, P.YPos - 5 + b) = 2 then Put(a * 64, b * 64), Stone, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 3 then Put(a * 64, b * 64), Crystal, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 4 then Put(a * 64, b * 64), StairUp, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 6 then Put(a * 64, b * 64), massive, PSet If World(P.XPos - 7 + a, P.YPos - 5 + b) = 7 then Put(a * 64, b * 64), Block, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 8 then Put(a * 64, b * 64), Pickaxe, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 9 then Put(a * 64, b * 64), BCrystal, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 10 then Put(a * 64, b * 64), CrystalEarth, PSet If World(P.XPos - 7 + a, P.YPos - 5 + b) = 11 then Put(a * 64, b * 64), BCrystalEarth, PSet If World(P.XPos - 7 + a, P.YPos - 5 + b) = 12 then Put(a * 64, b * 64), DeadEarth, PSet If World(P.XPos - 7 + a, P.YPos - 5 + b) = 13 then Put(a * 64, b * 64), Barrel, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 14 then Put(a * 64, b * 64), TNT, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 50 then Put(a * 64, b * 64), LeakG, ALPHA, 255 If World(P.XPos - 7 + a, P.YPos - 5 + b) = 51 then Put(a * 64, b * 64), TNTPlaced, ALPHA, 255 If S.Score >= CrystalMax.Score then If World(P.XPos - 7 + a, P.YPos - 5 + b) = 5 then Put(a * 64, b * 64), StairDown, ALPHA, 255 Else If World(P.XPos - 7 + a, P.YPos - 5 + b) = 5 then Put(a * 64, b * 64), StairDownClosed, ALPHA, 255 Endif Else Put(a * 64, b * 64), massive, PSet Endif Next b Next a Flame.G() P.G() S.G() Destroyed.G() CrystalMax.G() End Sub Sub WorldManager.MoveEntities(a as Integer) Dim as Integer b Dim as Byte WorldNew(0 to 63, 0 to 63) MoveToSide(a, 2) MoveToSide(a, 3) MoveToSide(a, 9) MoveToSide(a, 13) For b = 0 to 63 WorldNew(a, b) = World(a, b) Next b For b = 0 to 63 'Steine If b < 63 then If World(a, b) = 2 And World(a, b + 1) = 1 then WorldNew(a, b) = 1 WorldNew(a, b + 1) = 2 If Sound = 1 then TiPlaySample("rollstone" & STR(SCrollstone)) SCrollstone += 1 If SCrollstone > 4 then SCrollstone = 0 Endif Endif 'Barrel If b < 63 then If World(a, b) = 13 And World(a, b + 1) = 1 then WorldNew(a, b) = 1 WorldNew(a, b + 1) = 13 If Sound = 1 then TiPlaySample("fassroll" & STR(SCrollstone)) SCfassroll += 1 If SCfassroll > 4 then SCfassroll = 0 Endif Endif 'Leak If b < 63 then If World(a, b) = 50 And World(a, b + 1) = 1 then WorldNew(a, b) = 1 WorldNew(a, b + 1) = 50 ElseIf World(a, b) = 50 And World(a, b + 1) = 0 then WorldNew(a, b) = 1 WorldNew(a, b + 1) = 12 ElseIf World(a, b) = 50 then WorldNew(a, b) = 1 Endif Endif 'Kristalle (Gruen) If b > 0 then If World(a, 63 - b) = 3 And World(a, 63 - b + 1) = 1 then WorldNew(a, 63 - b) = 1 WorldNew(a, 63 - b + 1) = 3 If Sound = 1 then TiPlaySample("stonecoll" & STR(SCstonecoll)) SCstonecoll += 1 If SCstonecoll > 4 then SCstonecoll = 0 Endif Endif 'Kristalle (Blau) If b > 0 then If World(a, 63 - b) = 9 And World(a, 63 - b + 1) = 1 then WorldNew(a, 63 - b) = 1 WorldNew(a, 63 - b + 1) = 9 If Sound = 1 then TiPlaySample("stonecoll" & STR(SCstonecoll)) SCstonecoll += 1 If SCstonecoll > 4 then SCstonecoll = 0 Endif Endif Next b For b = 0 to 63 World(a, b) = WorldNew(a, b) Next b End Sub Sub WorldManager.MoveToSide(a as Integer, EntityID as Integer) Dim as Integer b For b = 0 to 63 If World(a, 63 - b) = EntityID then Dim as Byte LFree, RFree If World(a, 63 - b + 1) <> 1 And World(a, 63 - b + 1) <> 0 _ And World(a, 63 - b + 1) <> 10 And World(a, 63 - b + 1) <> 11 And World(a, 63 - b + 1) <> 12 then If World(a + 1, 63 - b) = 1 And World(a + 1, 63 - b + 1) = 1 then RFree = 1 If a > 0 then If World(a - 1, 63 - b) = 1 And World(a - 1, 63 - b + 1) = 1 then LFree = 1 Endif If RFree = 1 And LFree = 1 then Select Case Int(RND * 2) Case 0 If a + 1 >= 0 And 63 - b <= 63 then World(a + 1, 63 - b) = EntityID World(a, 63 - b) = 1 Endif Case 1 If a - 1 >= 0 And 63 - b <= 63 then World(a - 1, 63 - b) = EntityID World(a, 63 - b) = 1 Endif End Select ElseIf RFree = 1 then If a + 1 >= 0 And 63 - b <= 63 then World(a + 1, 63 - b) = EntityID World(a, 63 - b) = 1 Endif ElseIf LFree = 1 then If a - 1 >= 0 And 63 - b <= 63 then World(a - 1, 63 - b) = EntityID World(a, 63 - b) = 1 Endif Endif Endif Endif Next b End Sub Sub WorldManager.Leak() Dim as Integer a, b If LeakCounter > LeakSpeed then LeakCounter = 0 For a = 0 to 63 For b = 0 to 62 If World(a, b) = 12 And World(a, b + 1) = 1 then World(a, b + 1) = 50 If Sound = 1 then TiPlaySample("leak" & STR(SCdig)) SCLeak += 1 If SCLeak > 4 then SCLeak = 0 Endif Next b Next a Endif LeakCounter += 1 End Sub Sub WorldManager.Respawn() LoadWorld() SetSpawn() P.Dead = 0 S.Score = 0 P.GotPickaxe = 0 P.GotTNT = 0 Destroyed.Score = 0 For a as Integer = 0 to 8 Flame.AnimCounter(a) = -1 Next a End Sub Sub WorldManager.ResetTimer() If P.XPos > 0 And P.XPos < 63 And P.YPos > 0 then If World(P.XPos, P.YPos - 1) = 2 then EntityMoveCounter(P.XPos) = EntitySpeed If World(P.XPos - 1, P.YPos) = 2 Or World(P.XPos - 1, P.YPos - 1) = 2 then EntityMoveCounter(P.XPos - 1) = EntitySpeed If World(P.XPos + 1, P.YPos) = 2 Or World(P.XPos + 1, P.YPos - 1) = 2 then EntityMoveCounter(P.XPos + 1) = EntitySpeed If World(P.XPos, P.YPos - 1) = 13 then EntityMoveCounter(P.XPos) = EntitySpeed If World(P.XPos - 1, P.YPos) = 13 Or World(P.XPos - 1, P.YPos - 1) = 13 then EntityMoveCounter(P.XPos - 1) = EntitySpeed If World(P.XPos + 1, P.YPos) = 13 Or World(P.XPos + 1, P.YPos - 1) = 13 then EntityMoveCounter(P.XPos + 1) = EntitySpeed Endif End Sub Sub WorldManager.SetSpawn() Dim as Integer a, b Dim as Byte HasSpawn For a = 0 to 63 For b = 0 to 63 If World(a, b) = 4 then P.XPos = a P.YPos = b HasSpawn = 1 Endif Next b Next a If HasSpawn = 0 then P.XPos = 1 P.YPos = 1 Endif End Sub Sub WorldManager.TNTControl() If P.GotTNT = 1 And Multikey(&h39) then 'Space If ExplosionCounter < 1 And World(P.XPos, P.YPos) = 1 then World(P.XPos, P.YPos) = 51 ExplosionCounter = ExplosionSpeed P.GotTNT = 0 Endif Endif If ExplosionCounter = 1 then Dim as Integer a, b, i, j TiPlaySample("explosion") For a = 0 to 63 For b = 0 to 63 If World(a, b) = 51 then For i = -1 to 1 For j = -1 to 1 If a + i >= 0 And a + i <= 63 And b + j >= 0 And b + j <= 63 then World(a + i, b + j) = 1 Flame.MakeFlame(7 + i + (a - P.XPos), 5 + j + (b - P.YPos)) If P.XPos = a + i And P.YPos = b + j then P.Dead = 1 : If Sound = 1 then TiPlaySample("dead") Endif Next j Next i Endif Next b Next a Endif ExplosionCounter -= 1 If ExplosionCounter < 0 then ExplosionCounter = 0 End Sub