Results 1 to 2 of 2

Thread: Collision array (two questions)

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    48

    Collision array (two questions)

    The first question is why when I try to do any sort of an array it makes the drawing go crazy (gives me an error image)? The second is will probily answer itself after the first one - but I'm trying to remember how to get my program to remember the locations of trees/water and check it against the location of the character.

    Code:
    Imports System.IO
    Imports System.Drawing
    Imports AxWMPLib
    
    Public Class Form1
    
        Dim myDrawing As Graphics
        Dim myBackBuffer As Graphics
        Dim objectDrawer As Graphics
        Dim objectBuffer As Graphics
        Dim sImage As Bitmap
        Dim imageBackBuffer As Bitmap
        Dim objectImage As Bitmap
        Dim sRect As Rectangle
        Dim dRect As Rectangle
        Dim osRect As Rectangle
        Dim odRect As Rectangle
        Dim myReader As New StreamReader("C:\game data\background\11.txt")
        Dim oReader As New StreamReader("C:\game data\background\o11.txt")
        Dim tLines As String
        Dim xLines As Integer
        Dim yLines As Integer
        Dim aLines() As String
        Dim lineChar As Char
        Dim otLines As String
        Dim oxLines As Integer
        Dim oyLines As Integer
        Dim oaLines() As String
        Dim oLineChar As Char
        Dim xWalls() As Integer
        Dim yWalls() As Integer
        Dim xCharacter As Integer = 0
        Dim yCharacter As Integer = 0
    
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    
            Select Case e.KeyCode
                Case Keys.Right
                    xCharacter += 64
                Case Keys.Left
                    xCharacter -= 64
                Case Keys.Up
                    yCharacter -= 64
                Case Keys.Down
                    yCharacter += 64
            End Select
    
            DrawAll()
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            wmpBackground.URL = "C:\game data\music\Lost Woods.mid"
            wmpBackground.settings.setMode("Loop", True)
            sImage = New Bitmap(picTemplate.Image)
            myDrawing = Me.CreateGraphics
            objectDrawer = Me.CreateGraphics
            imageBackBuffer = New Bitmap(448, 448)
            objectImage = New Bitmap(448, 448)
            tLines = myReader.ReadToEnd
            aLines = tLines.Split(New String() {ControlChars.NewLine.ToCharArray}, StringSplitOptions.None)
            xLines = aLines(0).Length
            yLines = aLines.Count
            otLines = oReader.ReadToEnd
            oaLines = otLines.Split(New String() {ControlChars.NewLine.ToCharArray}, StringSplitOptions.None)
            oxLines = oaLines(0).Length
            oyLines = oaLines.Count
    
        End Sub
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
            DrawAll()
    
        End Sub
    
        Private Sub DrawAll()
    
            sImage.MakeTransparent(Color.White)
    
            For i = 0 To 6
                For j = 0 To 6
                    lineChar = aLines(j).Chars(i)
                    Select Case lineChar
                        Case "g"
                            sRect = New Rectangle(0, 0, 64, 64)
                            dRect = New Rectangle(i * 64, j * 64, 64, 64)
                            myDrawing.DrawImage(sImage, dRect, sRect, GraphicsUnit.Pixel)
                        Case "w"
                            'xWalls(i) = i * 64
                            'yWalls(j) = j * 64
                            sRect = New Rectangle(64, 0, 64, 64)
                            dRect = New Rectangle(i * 64, j * 64, 64, 64)
                            myDrawing.DrawImage(sImage, dRect, sRect, GraphicsUnit.Pixel)
                        Case "b"
                            sRect = New Rectangle(128, 0, 64, 64)
                            dRect = New Rectangle(i * 64, j * 64, 64, 64)
                            myDrawing.DrawImage(sImage, dRect, sRect, GraphicsUnit.Pixel)
                    End Select
                Next
            Next
    
            For m = 0 To 6
                For n = 0 To 6
                    oLineChar = oaLines(n).Chars(m)
                    Select Case oLineChar
                        Case "t"
                            osRect = New Rectangle(0, 64, 64, 64)
                            odRect = New Rectangle(m * 64, n * 64, 64, 64)
                            myDrawing.DrawImage(sImage, odRect, osRect, GraphicsUnit.Pixel)
                    End Select
                Next
            Next
    
    
            sRect = New Rectangle(64, 64, 64, 64)
            myDrawing.DrawImage(sImage, xCharacter, yCharacter, sRect, GraphicsUnit.Pixel)
    
            myDrawing = Graphics.FromImage(imageBackBuffer)
            myBackBuffer = Me.CreateGraphics
            myBackBuffer.DrawImage(imageBackBuffer, 0, 0, 448, 448)
    
        End Sub
    End Class
    I have the issue commented out.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    48

    Re: Collision array (two questions)

    P.S. I've tried using Booleans for the array and it still doesn't work.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width