From 15cd1f3079f8e38643e4820e3927151f1e4b2bad Mon Sep 17 00:00:00 2001 From: CaptainSegis Date: Wed, 9 Aug 2017 14:12:51 -0500 Subject: [PATCH] Made the following changes related to Animated blocks: - Renamed AnimatedTile to AnimatedBlock, and added support for multiple animations. - Fixed bug related to start row and column in the Animation.vb class - Added intArr2D tag content type in LevelLoader --- 2.5DHero/2.5DHero/2.5DHero.vbproj | 2 +- 2.5DHero/2.5DHero/Entites/Entity.vb | 8 +- .../{AnimatedTile.vb => AnimatedBlock.vb} | 124 +++++++++++------- 2.5DHero/2.5DHero/HelperClasses/Animation.vb | 4 +- 2.5DHero/2.5DHero/World/LevelLoader.vb | 18 ++- 5 files changed, 101 insertions(+), 55 deletions(-) rename 2.5DHero/2.5DHero/Entites/Enviroment/{AnimatedTile.vb => AnimatedBlock.vb} (61%) diff --git a/2.5DHero/2.5DHero/2.5DHero.vbproj b/2.5DHero/2.5DHero/2.5DHero.vbproj index 7d4a633d9..9a52b2ddc 100644 --- a/2.5DHero/2.5DHero/2.5DHero.vbproj +++ b/2.5DHero/2.5DHero/2.5DHero.vbproj @@ -208,7 +208,7 @@ - + diff --git a/2.5DHero/2.5DHero/Entites/Entity.vb b/2.5DHero/2.5DHero/Entites/Entity.vb index 4d7caa05e..df8d2d450 100644 --- a/2.5DHero/2.5DHero/Entites/Entity.vb +++ b/2.5DHero/2.5DHero/Entites/Entity.vb @@ -122,7 +122,7 @@ Me.UpdateEntity() End Sub - Public Shared Function GetNewEntity(ByVal EntityID As String, ByVal Position As Vector3, ByVal Textures() As Texture2D, ByVal TextureIndex() As Integer, ByVal Collision As Boolean, ByVal Rotation As Vector3, ByVal Scale As Vector3, ByVal Model As BaseModel, ByVal ActionValue As Integer, ByVal AdditionalValue As String, ByVal Visible As Boolean, ByVal Shader As Vector3, ByVal ID As Integer, ByVal MapOrigin As String, ByVal SeasonColorTexture As String, ByVal Offset As Vector3, Optional ByVal Params() As Object = Nothing, Optional ByVal Opacity As Single = 1.0F, Optional ByVal AnimationData As List(Of Integer) = Nothing) As Entity + Public Shared Function GetNewEntity(ByVal EntityID As String, ByVal Position As Vector3, ByVal Textures() As Texture2D, ByVal TextureIndex() As Integer, ByVal Collision As Boolean, ByVal Rotation As Vector3, ByVal Scale As Vector3, ByVal Model As BaseModel, ByVal ActionValue As Integer, ByVal AdditionalValue As String, ByVal Visible As Boolean, ByVal Shader As Vector3, ByVal ID As Integer, ByVal MapOrigin As String, ByVal SeasonColorTexture As String, ByVal Offset As Vector3, Optional ByVal Params() As Object = Nothing, Optional ByVal Opacity As Single = 1.0F, Optional ByVal AnimationData As List(Of List(Of Integer)) = Nothing) As Entity Dim newEnt As New Entity() Dim propertiesEnt As New Entity() @@ -146,10 +146,10 @@ propertiesEnt.Offset = Offset Select Case EntityID.ToLower() - Case "animatedtile" - newEnt = New AnimatedTile() + Case "animatedblock" + newEnt = New AnimatedBlock() SetProperties(newEnt, propertiesEnt) - CType(newEnt, AnimatedTile).Initialize(AnimationData) + CType(newEnt, AnimatedBlock).Initialize(AnimationData) Case "wallblock" newEnt = New WallBlock() SetProperties(newEnt, propertiesEnt) diff --git a/2.5DHero/2.5DHero/Entites/Enviroment/AnimatedTile.vb b/2.5DHero/2.5DHero/Entites/Enviroment/AnimatedBlock.vb similarity index 61% rename from 2.5DHero/2.5DHero/Entites/Enviroment/AnimatedTile.vb rename to 2.5DHero/2.5DHero/Entites/Enviroment/AnimatedBlock.vb index cfbf5a710..18ab1d50a 100644 --- a/2.5DHero/2.5DHero/Entites/Enviroment/AnimatedTile.vb +++ b/2.5DHero/2.5DHero/Entites/Enviroment/AnimatedBlock.vb @@ -1,51 +1,80 @@ -Public Class AnimatedTile +Public Class AnimatedBlock Inherits Entity - Shared TileTexturesTemp As New Dictionary(Of String, Texture2D) - Dim TileTextureName As String = "" - - Dim tileAnimation As Animation - Dim currentRectangle As New Rectangle(0, 0, 0, 0) - - Dim rows, columns, animationSpeed, startRow, startColumn As Integer + Shared BlockTexturesTemp As New Dictionary(Of String, Texture2D) - Public Overloads Sub Initialize(ByVal AnimationData As List(Of Integer)) + Dim AnimationNames As List(Of String) + + Dim Animations As List(Of Animation) + Dim currentRectangle As List(Of Rectangle) + + Dim X, Y, width, height, rows, columns, animationSpeed, startRow, startColumn As List(Of Integer) + + Dim AnimCount As Integer = 0 + + + Sub New() + X = New List(Of Integer) + Y = New List(Of Integer) + width = New List(Of Integer) + height = New List(Of Integer) + rows = New List(Of Integer) + columns = New List(Of Integer) + animationSpeed = New List(Of Integer) + startRow = New List(Of Integer) + startColumn = New List(Of Integer) + + AnimationNames = New List(Of String) + currentRectangle = New List(Of Rectangle) + Animations = New List(Of Animation) + End Sub + + Public Overloads Sub Initialize(ByVal AnimationData As List(Of List(Of Integer))) + MyBase.Initialize() - rows = AnimationData(0) - columns = AnimationData(1) - animationSpeed = AnimationData(2) - startRow = AnimationData(3) - startColumn = AnimationData(4) + For i = 0 To AnimationData.Count - 1 + X.Add(AnimationData(i)(0)) + Y.Add(AnimationData(i)(1)) + width.Add(AnimationData(i)(2)) + height.Add(AnimationData(i)(3)) + rows.Add(AnimationData(i)(4)) + columns.Add(AnimationData(i)(5)) + animationSpeed.Add(AnimationData(i)(6)) + startRow.Add(AnimationData(i)(7)) + startColumn.Add(AnimationData(i)(8)) - tileAnimation = New Animation(TextureManager.GetTexture("Textures\Routes"), rows, columns, 16, 16, animationSpeed, startRow, startColumn) + AnimationNames.Add("") + currentRectangle.Add(New Rectangle(0, 0, 0, 0)) - CreateTileTextureTemp() + Animations.Add(New Animation(TextureManager.GetTexture("Textures\Routes"), rows(i), columns(i), 16, 16, animationSpeed(i), startRow(i), startColumn(i))) + + AnimCount += 1 + Next + + CreateBlockTextureTemp() End Sub Public Shared Sub ClearAnimationResources() - TileTexturesTemp.Clear() + BlockTexturesTemp.Clear() End Sub - Private Sub CreateTileTextureTemp() + Private Sub CreateBlockTextureTemp() 'If Core.GameOptions.GraphicStyle = 1 Then - Dim textureData As List(Of String) = Me.AdditionalValue.Split(CChar(",")).ToList() - If textureData.Count >= 5 Then - Dim r As New Rectangle(CInt(textureData(1)), CInt(textureData(2)), CInt(textureData(3)), CInt(textureData(4))) - Dim texturePath As String = textureData(0) - Me.TileTextureName = AdditionalValue - If AnimatedTile.TileTexturesTemp.ContainsKey(AdditionalValue & "_0") = False Then - For i = 0 To Me.rows - 1 - For j = 0 To Me.columns - 1 - AnimatedTile.TileTexturesTemp.Add(AdditionalValue & "_" & (j + columns * i).ToString, TextureManager.GetTexture(texturePath, New Rectangle(r.X + r.Width * j, r.Y + r.Height * i, r.Width, r.Height))) + + For n = 0 To Animations.Count - 1 + Dim r As New Rectangle(X(n), Y(n), width(n), height(n)) + Me.AnimationNames(n) = AdditionalValue & "," & X(n) & "," & Y(n) & "," & height(n) & "," & width(n) + If BlockTexturesTemp.ContainsKey(AnimationNames(n) & "_0") = False Then + For i = 0 To Me.rows(n) - 1 + For j = 0 To Me.columns(n) - 1 + BlockTexturesTemp.Add(AnimationNames(n) & "_" & (j + columns(n) * i).ToString, TextureManager.GetTexture(AdditionalValue, New Rectangle(r.X + r.Width * j, r.Y + r.Height * i, r.Width, r.Height))) Next Next End If - Else - Logger.Log(Logger.LogTypes.ErrorMessage, "AnimatedTile.vb: invalid AdditionalValue parameters") - End If - 'End If + Next + End Sub Public Overrides Sub ClickFunction() @@ -68,7 +97,7 @@ For Each Entity As Entity In Screen.Level.Entities If Entity.boundingBox.Contains(Screen.Camera.GetForwardMovedPosition()) = ContainmentType.Contains Then - If Entity.EntityID = "Water" Then + If Entity.ActionValue = 0 AndAlso (Entity.EntityID = "AnimatedBlock" OrElse Entity.EntityID = "Water") Then canSurf = True Else If Entity.Collision = True Then @@ -97,7 +126,7 @@ If Me.ActionValue = 0 Then For Each Entity As Entity In Screen.Level.Entities If Entity.boundingBox.Contains(Screen.Camera.GetForwardMovedPosition()) = ContainmentType.Contains Then - If Entity.EntityID = "Water" Then + If Entity.EntityID = "AnimatedBlock" Then If Core.Player.SurfPokemon > -1 Then canSurf = True End If @@ -132,27 +161,30 @@ End Function Public Overrides Sub UpdateEntity() - If Not tileAnimation Is Nothing Then - tileAnimation.Update(0.01) - If currentRectangle <> tileAnimation.TextureRectangle Then - ChangeTexture() + If Not Animations Is Nothing Then + For n = 0 To Animations.Count - 1 + Animations(n).Update(0.01) + If currentRectangle(n) <> Animations(n).TextureRectangle Then + ChangeTexture(n) - currentRectangle = tileAnimation.TextureRectangle - End If + currentRectangle(n) = Animations(n).TextureRectangle + End If + Next End If - MyBase.UpdateEntity() End Sub - Private Sub ChangeTexture() + Private Sub ChangeTexture(ByVal n As Integer) 'If Core.GameOptions.GraphicStyle = 1 Then - If TileTexturesTemp.Count = 0 Then + + If BlockTexturesTemp.Count = 0 Then ClearAnimationResources() - CreateTileTextureTemp() + CreateBlockTextureTemp() End If - Dim i = tileAnimation.CurrentRow - Dim j = tileAnimation.CurrentColumn - Me.Textures(0) = AnimatedTile.TileTexturesTemp(TileTextureName & "_" & (j + columns * i)) + Dim i = Animations(n).CurrentRow + Dim j = Animations(n).CurrentColumn + Me.Textures(n) = AnimatedBlock.BlockTexturesTemp(AnimationNames(n) & "_" & (j + columns(n) * i)) + 'End If End Sub diff --git a/2.5DHero/2.5DHero/HelperClasses/Animation.vb b/2.5DHero/2.5DHero/HelperClasses/Animation.vb index a0315ce6a..5f9aca0fb 100644 --- a/2.5DHero/2.5DHero/HelperClasses/Animation.vb +++ b/2.5DHero/2.5DHero/HelperClasses/Animation.vb @@ -144,10 +144,10 @@ Public Class Animation CurrentColumn += 1 If CurrentColumn >= Columns Then CurrentRow += 1 - CurrentColumn = StartColumn + CurrentColumn = 0 If CurrentRow >= Rows Then - CurrentRow = StartRow + CurrentRow = 0 End If End If End If diff --git a/2.5DHero/2.5DHero/World/LevelLoader.vb b/2.5DHero/2.5DHero/World/LevelLoader.vb index ca29297fb..afb39799e 100644 --- a/2.5DHero/2.5DHero/World/LevelLoader.vb +++ b/2.5DHero/2.5DHero/World/LevelLoader.vb @@ -320,6 +320,20 @@ arr.Add(CInt(value)) Next Dictionary.Add(TagName, arr) + Case "intarr2d" + Dim rows() As String = subTagValue.Split(CChar("]")) + Dim arr As New List(Of List(Of Integer)) + For Each row As String In rows + If row.Length > 0 Then + row = row.Remove(0, 1) + Dim list As New List(Of Integer) + For Each value In row.Split(CChar(",")) + list.Add(CInt(value)) + Next + arr.Add(list) + End If + Next + Dictionary.Add(TagName, arr) Case "rec" Dim content() As String = subTagValue.Split(CChar(",")) Dictionary.Add(TagName, New Rectangle(CInt(content(0)), CInt(content(1)), CInt(content(2)), CInt(content(3)))) @@ -806,9 +820,9 @@ AdditionalValue = CStr(GetTag(Tags, "AdditionalValue")) End If - Dim AnimationData As List(Of Integer) = Nothing + Dim AnimationData As List(Of List(Of Integer)) = Nothing If TagExists(Tags, "AnimationData") = True Then - AnimationData = CType(GetTag(Tags, "AnimationData"), List(Of Integer)) + AnimationData = CType(GetTag(Tags, "AnimationData"), List(Of List(Of Integer))) End If Dim Rotation As Vector3 = Entity.GetRotationFromInteger(CInt(GetTag(Tags, "Rotation")))