From 57bd4fbbaec5c5b48921d54d62ab7257b52a5062 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sun, 21 Aug 2011 21:05:34 +0200 Subject: [PATCH] Digging/noise wave --- src/Draw.pbi | 5 +++++ src/Events.pbi | 5 ++++- src/Functions.pbi | 2 +- src/Globals.pbi | 8 +++++++- src/Structs.pbi | 6 ++++++ src/mapcheck.txt | 2 +- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Draw.pbi b/src/Draw.pbi index 359d319..5e5c821 100644 --- a/src/Draw.pbi +++ b/src/Draw.pbi @@ -37,6 +37,11 @@ EndProcedure Procedure DrawRunningGame() DrawMap() + ; FIXME: This does not work quite well ... + ;StartDrawing(ScreenOutput()) + ;DrawPlayerNoise() + ;StopDrawing() + CalculateShadow() DrawShadow() diff --git a/src/Events.pbi b/src/Events.pbi index b9b5521..9055c1e 100644 --- a/src/Events.pbi +++ b/src/Events.pbi @@ -134,7 +134,10 @@ Procedure HandleEventRunningGame() TileMap(TargetX, TargetY)\TileNumber = #TILESET_TYPE_FLOOR EndIf - DrawNoiseWave(TargetX, TargetY) + *PlayerNoise\X = TargetX + *PlayerNoise\Y = TargetY + *PlayerNoise\Size = 10 + CreateThread(@CalculateNoiseWave(), *PlayerNoise) EndIf EndIf EndProcedure \ No newline at end of file diff --git a/src/Functions.pbi b/src/Functions.pbi index 08ff1d8..8386b7c 100644 --- a/src/Functions.pbi +++ b/src/Functions.pbi @@ -1 +1 @@ -; This file holds all the functions If it gets too big, ; we can split it in categories ; ***************************************************************************** ; * Tileset Procedure InitGraphics() GFXLogo = LoadSprite(#PB_Any, "../data/gfx/logo.bmp") GFXTileset = LoadSprite(#PB_Any, "../data/gfx/tileset01.bmp") EndProcedure ; TODO: Make this dynamic Procedure InitTileset() Define i.i, j.i, count.i count = 0 For i=0 To 5 For j=0 To 5 Tileset(count)\ID = CopySprite(GFXTileset, #PB_Any) ClipSprite(Tileset(count)\ID, #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE) Tileset(count)\Type = #TILESET_TYPE_FLOOR Select count Case 0 Tileset(count)\Type = #TILESET_TYPE_PLAYER Case 2 Tileset(count)\Type = #TILESET_TYPE_WALL Case 3 Tileset(count)\Type = #TILESET_TYPE_SOLID Case 4 Tileset(count)\Type = #TILESET_TYPE_GRASS EndSelect count+1 Next Next EndProcedure Procedure LoadMap(Filename.s) ; Extract the map data from the XML file If LoadXML(0, Filename) And XMLStatus(0) = #PB_XML_Success Define *Node.i = XMLNodeFromPath(MainXMLNode(0), "/map/layer/data") Define MapData.s = GetXMLNodeText(*Node) If CreateRegularExpression(0, "\d{1,2},?") Dim Tiles.s(0) Define NumFound.i = ExtractRegularExpression(0, MapData, Tiles()) Define i.i, X.i, Y.i X = 0 Y = 0 CreateFile(0, "mapcheck.txt") ; File stuff for checking the map loader For i=0 To NumFound-1 TileMap(X, Y)\TileNumber = Val(RTrim(Tiles(i), ","))-1 TileMap(X, Y)\X = X TileMap(X, Y)\Y = Y ; Walls get 4 health If TileMap(X, Y)\TileNumber = 2 TileMap(X, Y)\Health = 4 EndIf WriteString(0, StrU(TileMap(X, Y)\TileNumber+1)+",") If X = #MAP_WIDTH-1 X = 0 Y+1 WriteStringN(0, "") ; do new line Else X+1 EndIf Next CloseFile(0) EndIf EndIf EndProcedure ; Shadowmap Procedure CalculateShadow() Define X.i, Y.i Define MapX.i, MapY.i, Strength.i, Centercheck.i, CentercheckX.i, CentercheckY.i For X.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2 For Y.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2 MapX = Player\X + X MapY = Player\Y + Y CentercheckX = X If CentercheckX < 0 CentercheckX * -1 EndIf CentercheckY = Y If CentercheckY < 0 CentercheckY * -1 EndIf If CentercheckX > CentercheckY Centercheck = CentercheckX Else Centercheck = CentercheckY EndIf Centercheck = #SHADOW_RADIUS - Centercheck; Strength = (255 / #SHADOW_RADIUS) * (Centercheck) If MapX >= 0 And MapY >= 0 If ShadowMap(MapX, MapY)\Strength < Strength ShadowMap(MapX, MapY)\Strength = Strength EndIf EndIf Next Next EndProcedure Procedure DrawShadowtile(strength.i, x.i, y.i) Box(#TILE_SIZE*x, #TILE_SIZE*y, #TILE_SIZE, #TILE_SIZE, RGBA(0, 0, 0, 255-strength)) EndProcedure Procedure GenerateShadowLayer() Define X.i ,Y.i CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux ShadowOfDarkness = CreateImage(#PB_Any, 800, 600, 32|#PB_Image_Transparent) StartDrawing(ImageOutput(ShadowOfDarkness)) CompilerDefault StartDrawing(ScreenOutput()) CompilerEndSelect DrawingMode(#PB_2DDrawing_AlphaBlend) For X.i=0 To Cam\Width For Y.i=0 To Cam\Height DrawShadowtile(ShadowMap(X+Cam\X, Y+Cam\Y)\Strength, X, Y) Next Next StopDrawing() EndProcedure Procedure DrawShadow() CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux StartDrawing(ScreenOutput()) DrawImage(ImageID(ShadowOfDarkness), 0, 0) StopDrawing() CompilerDefault GenerateShadowLayer() CompilerEndSelect EndProcedure ; Map itself Procedure DrawTile(number.i, x.i, y.i) Define id.i If number = #TILESET_TYPE_WALL And TileMap(x, y)\Health < 4 id = (17+4)-TileMap(x, y)\Health Else id = number EndIf DisplaySprite(Tileset(id)\ID, #TILE_SIZE*x, #TILE_SIZE*y) EndProcedure Procedure DrawMap() Define X.i ,Y.i For X.i=0 To Cam\Width For Y.i=0 To Cam\Height DrawTile(TileMap(X+Cam\X, Y+Cam\Y)\TileNumber, X, Y) Next Next EndProcedure Procedure TileIsType(type.i, X.i, Y.i) Define istype.b istype = #False If Tileset(TileMap(X, Y)\TileNumber)\Type = type istype = #True EndIf ProcedureReturn istype EndProcedure ; The player Procedure DrawPlayer() DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y) EndProcedure ; We need a HUD, hell yeah! Procedure DrawHUD() EndProcedure ; If the player starts diffin, some noise wave will be generated Procedure DrawNoiseWave(X.i, Y.i) EndProcedure ; ***************************************************************************** ; * Menu Procedure Menu_GotoCurrent() If *ActiveMenu\Entries()\Selected <> #True FirstElement(*ActiveMenu\Entries()) ForEach *ActiveMenu\Entries() If *ActiveMenu\Entries()\Selected = #True Break EndIf Next EndIf EndProcedure \ No newline at end of file +; This file holds all the functions If it gets too big, ; we can split it in categories ; ***************************************************************************** ; * Tileset Procedure InitGraphics() GFXLogo = LoadSprite(#PB_Any, "../data/gfx/logo.bmp") GFXTileset = LoadSprite(#PB_Any, "../data/gfx/tileset01.bmp") EndProcedure ; TODO: Make this dynamic Procedure InitTileset() Define i.i, j.i, count.i count = 0 For i=0 To 5 For j=0 To 5 Tileset(count)\ID = CopySprite(GFXTileset, #PB_Any) ClipSprite(Tileset(count)\ID, #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE) Tileset(count)\Type = #TILESET_TYPE_FLOOR Select count Case 0 Tileset(count)\Type = #TILESET_TYPE_PLAYER Case 2 Tileset(count)\Type = #TILESET_TYPE_WALL Case 3 Tileset(count)\Type = #TILESET_TYPE_SOLID Case 4 Tileset(count)\Type = #TILESET_TYPE_GRASS EndSelect count+1 Next Next EndProcedure Procedure LoadMap(Filename.s) ; Extract the map data from the XML file If LoadXML(0, Filename) And XMLStatus(0) = #PB_XML_Success Define *Node.i = XMLNodeFromPath(MainXMLNode(0), "/map/layer/data") Define MapData.s = GetXMLNodeText(*Node) If CreateRegularExpression(0, "\d{1,2},?") Dim Tiles.s(0) Define NumFound.i = ExtractRegularExpression(0, MapData, Tiles()) Define i.i, X.i, Y.i X = 0 Y = 0 CreateFile(0, "mapcheck.txt") ; File stuff for checking the map loader For i=0 To NumFound-1 TileMap(X, Y)\TileNumber = Val(RTrim(Tiles(i), ","))-1 TileMap(X, Y)\X = X TileMap(X, Y)\Y = Y ; Walls get 4 health If TileMap(X, Y)\TileNumber = 2 TileMap(X, Y)\Health = 4 EndIf WriteString(0, StrU(TileMap(X, Y)\TileNumber+1)+",") If X = #MAP_WIDTH-1 X = 0 Y+1 WriteStringN(0, "") ; do new line Else X+1 EndIf Next CloseFile(0) EndIf EndIf EndProcedure ; Shadowmap Procedure CalculateShadow() Define X.i, Y.i Define MapX.i, MapY.i, Strength.i, Centercheck.i, CentercheckX.i, CentercheckY.i For X.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2 For Y.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2 MapX = Player\X + X MapY = Player\Y + Y CentercheckX = X If CentercheckX < 0 CentercheckX * -1 EndIf CentercheckY = Y If CentercheckY < 0 CentercheckY * -1 EndIf If CentercheckX > CentercheckY Centercheck = CentercheckX Else Centercheck = CentercheckY EndIf Centercheck = #SHADOW_RADIUS - Centercheck; Strength = (255 / #SHADOW_RADIUS) * (Centercheck) If MapX >= 0 And MapY >= 0 If ShadowMap(MapX, MapY)\Strength < Strength ShadowMap(MapX, MapY)\Strength = Strength EndIf EndIf Next Next EndProcedure Procedure DrawShadowtile(strength.i, x.i, y.i) Box(#TILE_SIZE*x, #TILE_SIZE*y, #TILE_SIZE, #TILE_SIZE, RGBA(0, 0, 0, 255-strength)) EndProcedure Procedure GenerateShadowLayer() Define X.i ,Y.i CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux ShadowOfDarkness = CreateImage(#PB_Any, 800, 600, 32|#PB_Image_Transparent) StartDrawing(ImageOutput(ShadowOfDarkness)) CompilerDefault StartDrawing(ScreenOutput()) CompilerEndSelect DrawingMode(#PB_2DDrawing_AlphaBlend) For X.i=0 To Cam\Width For Y.i=0 To Cam\Height DrawShadowtile(ShadowMap(X+Cam\X, Y+Cam\Y)\Strength, X, Y) Next Next StopDrawing() EndProcedure Procedure DrawShadow() CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux StartDrawing(ScreenOutput()) DrawImage(ImageID(ShadowOfDarkness), 0, 0) StopDrawing() CompilerDefault GenerateShadowLayer() CompilerEndSelect EndProcedure ; Map itself Procedure DrawTile(number.i, x.i, y.i) Define id.i If number = #TILESET_TYPE_WALL And TileMap(x, y)\Health < 4 id = (17+4)-TileMap(x, y)\Health Else id = number EndIf DisplaySprite(Tileset(id)\ID, #TILE_SIZE*x, #TILE_SIZE*y) EndProcedure Procedure DrawMap() Define X.i ,Y.i For X.i=0 To Cam\Width For Y.i=0 To Cam\Height DrawTile(TileMap(X+Cam\X, Y+Cam\Y)\TileNumber, X, Y) Next Next EndProcedure Procedure TileIsType(type.i, X.i, Y.i) Define istype.b istype = #False If Tileset(TileMap(X, Y)\TileNumber)\Type = type istype = #True EndIf ProcedureReturn istype EndProcedure ; The player Procedure DrawPlayer() DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y) EndProcedure ; We need a HUD, hell yeah! Procedure DrawHUD() EndProcedure ; If the player starts diffin, some noise wave will be generated Procedure CalculateNoiseWave(*Noise.NoiseWave) Define Size.i Define MaxSize.i = *Noise\Size For Size=0 To MaxSize *Noise\Size = Size Delay(30) Next *Noise\Size = 0 EndProcedure Procedure DrawPlayerNoise() Define Visibility.i = 255 Select *PlayerNoise\Size Case 1,2,3 Visibility = 80 Case 4,5,6 Visibility = 40 Case 7,8 Visibility = 20 Case 9 Visibility = 10 Case 10 Visibility = 0 EndSelect Ellipse(*PlayerNoise\X*#TILE_SIZE+10, *PlayerNoise\Y*#TILE_SIZE+10, *PlayerNoise\Size*10, *PlayerNoise\Size*10, RGBA(255, 0, 0, Visibility)) EndProcedure ; ***************************************************************************** ; * Menu Procedure Menu_GotoCurrent() If *ActiveMenu\Entries()\Selected <> #True FirstElement(*ActiveMenu\Entries()) ForEach *ActiveMenu\Entries() If *ActiveMenu\Entries()\Selected = #True Break EndIf Next EndIf EndProcedure \ No newline at end of file diff --git a/src/Globals.pbi b/src/Globals.pbi index 99833c5..8775246 100644 --- a/src/Globals.pbi +++ b/src/Globals.pbi @@ -62,4 +62,10 @@ LoadSound(2, #DATA_PATH + "sound/title_song.wav") ; Map Global Dim TileMap.Tile(#MAP_WIDTH, #MAP_HEIGHT) -Global Dim ShadowMap.Shadow(#MAP_WIDTH, #MAP_HEIGHT) \ No newline at end of file +Global Dim ShadowMap.Shadow(#MAP_WIDTH, #MAP_HEIGHT) + +; Addons +Global *PlayerNoise.NoiseWave = AllocateMemory(SizeOf(NoiseWave)) +*PlayerNoise\X = 0 +*PlayerNoise\Y = 0 +*PlayerNoise\Size = 0 diff --git a/src/Structs.pbi b/src/Structs.pbi index 679ab85..848e182 100644 --- a/src/Structs.pbi +++ b/src/Structs.pbi @@ -43,6 +43,12 @@ Structure Tile Health.i EndStructure +Structure NoiseWave + X.i + Y.i + Size.i +EndStructure + Structure Player X.i Y.i diff --git a/src/mapcheck.txt b/src/mapcheck.txt index 908f800..96db6f1 100644 --- a/src/mapcheck.txt +++ b/src/mapcheck.txt @@ -1,7 +1,7 @@ 8,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,8, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,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