All pastes #570926 Raw Edit

FRB GameManager class for FRB Te

public text v1 · immutable
·published 2007-06-16 22:59 UTC
rendered paste body
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Windows.Forms
Imports FRB
Imports FRB.GUI
Imports FRB.Text
Imports FRB.Audio
Imports FRB.Collections
Imports FRB.Instructions
Imports Microsoft.DirectX.DirectInput

#Region "Changes"
'Changes: These are the problems I had running this 'as is' with the current FRB.dll in VS2K5
'
' "Found conflicts between different versions of same dependent assembly."
'  Fix: Visual Studio added binding redirect reccords in app.config.
'  Comment: I'm not exactly sure what this means.
'
'sprMan = New SpriteManager(sms, sr, Me) "Argument not specified for 'defaultTextLocation'
'  Fix: Added a path string ... again, I'm not totally sure how this works, but I have an idea, I'm guessing that
'       this is the default path for sprite image rescources.
'
'guiMan = New GuiManager(sprMan, textMan, inpMan, camera, "genGfx/guiTex.png")
'  The GuiResult paramater is missing, I don't know what it does, but the documatation says it's use is not reccomended
'  Fix: I'll use guiResult ... and hope it does whatever it's supposed to do.
'
'sms.numOfUnordered = 10
'  FRB doesn't seem to implement this property of the SpriteManagerSettings class anymore
'  Fix: I'll comment out the line, for now.
'
'guiMan.Control(guiResult)
'  This method of the GuiManager class doesn't take an argument anymore
'  Fix: I'll remove the guiResult refrence.
'
'guiMan.Draw(guiResult)
'  This method is now a private member of the GuiManager class ... I'm going to assume that this is due to
'  the fact that guiResult is no longer used as it used to
'  Fix: I'll comment out the line
'
'Conclusion: It runs now, I hope that I haven't missed anything that I didn't understand that will 
'end up biting me later.
'
' Thanks goes to whoever origially wrote this template for VB.net ... I did not write this,
'I just modifed a little bit of it so that it would work for me. --C4Cypher  c4cypher56@hotmail.com


#End Region




Namespace GameName

    Public Class GameForm
        Inherits Form
        Public Shared sprMan As SpriteManager
        Public Shared inpMan As InputManager
        Public Shared textMan As TextManager
        Public Shared guiMan As GuiManager
        Public Shared myCursor As FRB.Cursor
        Public Shared camera As Camera
        Public Shared random As Random = New Random
        Public Shared gameData As GameData
        Public Shared sms As SpriteManagerSettings
        Public Shared guiResult As GuiResult = New GuiResult

        Public Sub New(ByVal sms As SpriteManagerSettings)
            Dim sr As StreamWriter = New StreamWriter("initlog.txt")
            If File.Exists("settings/displaySettings.txt") Then
                Dim tr As TextReader = New StreamReader("settings/displaySettings.txt")
                Dim buffer As String = tr.ReadToEnd
                If CommonFunctions.GetCharAfter("Fullscreen: ", buffer) = "f"c Then
                    sms.fullScreen = True
                Else
                    sms.fullScreen = False
                End If
                If CommonFunctions.GetCharAfter("Filtering: ", buffer) = "p"c Then
                    sms.filtering = False
                Else
                    sms.filtering = True
                End If
                If sms.fullScreen AndAlso Not Single.IsNaN(CommonFunctions.GetFloatAfter("Height in pixels: ", buffer)) Then
                    sms.screenHeight = CType((CommonFunctions.GetFloatAfter("Height in pixels: ", buffer)), Integer)
                End If
                If sms.fullScreen AndAlso Not Single.IsNaN(CommonFunctions.GetFloatAfter("Width in pixels: ", buffer)) Then
                    sms.screenWidth = CType((CommonFunctions.GetFloatAfter("Width in pixels: ", buffer)), Integer)
                End If
            End If
            Dim tempSize As Size = SystemInformation.PrimaryMonitorSize
            If sms.screenHeight = 0 Then
                sms.screenHeight = tempSize.Height
            End If
            If sms.screenWidth = 0 Then
                sms.screenWidth = tempSize.Width
            End If
            Me.ClientSize = New System.Drawing.Size(sms.screenWidth, sms.screenHeight)
            System.Windows.Forms.Cursor.Hide()
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
            Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
            Me.Text = "FRB Template " + Application.ProductVersion
            TimeManager.Initialize()
            inpMan = New InputManager(Me, sr)
            sprMan = New SpriteManager(sms, sr, Me, "..\Media")
            textMan = sprMan.textMan
            camera = sprMan.ca(0)
            guiMan = New GuiManager(sprMan, textMan, inpMan, camera, "genGfx/guiTex.png", guiResult)
            myCursor = guiMan.cursor
            gameData = New GameData
            TimeManager.Update()
            gameData.Initialize(Me)
            gameData.guiData.Initialize(Me)
            gameData.guiData.messages.Initialize()
            sr.WriteLine("Everything seemed to initialize fine.  Starting the game.")
            sr.Close()
        End Sub

        Protected Overloads Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
            If (e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Escape)) Then
                ExitGame(Me)
            End If
        End Sub

        Protected Overloads Overrides Sub OnResize(ByVal e As System.EventArgs)
        End Sub

        Public Shared Sub ExitGame(ByVal form As GameForm)
            System.Windows.Forms.Cursor.Show()
            form.Dispose()
        End Sub

        Shared Sub Main()
            sms = New SpriteManagerSettings
            'sms.numOfUnordered = 10
            sms.maxNumOfParticles = 3000
            sms.fullScreen = False
            sms.filtering = True
            sms.animateUnorderedSprites = False
            sms.screenHeight = 0
            sms.screenWidth = 0
            Dim frm As GameForm = New GameForm(sms)
            frm.Show()
            While frm.Created
                TimeManager.Update()
                inpMan.GetInputState(guiResult)
                guiMan.Control()
                sprMan.ExecuteInstructions()
                sprMan.Move()
                textMan.Move()
                sprMan.Animate()
                guiMan.Animate(sprMan)
                gameData.Activity()
                sprMan.UpdateDependencies()
                textMan.UpdateDependencies()
                sprMan.CallCustomFunctions()
                sprMan.Sort()
                sprMan.BeginDrawing()
                sprMan.Draw(sprMan.ca(0))
                'guiMan.Draw(guiResult)
                gameData.AfterFrameActivity()
                sprMan.EndDrawing()
                Application.DoEvents()
            End While
        End Sub
    End Class
End Namespace