Hi

I was programming a 2D scroller game in VB.net, but am having problems with collision. I spent ages thinking how to program collision into my program, but haven’t gotten a good result yet. Basically, my game takes numbers from a notepad file and draws tiles on the screen based on which number it is. So for example, the numbers in my notepad document are something like:

1 1 1 1 1 1 1 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1

Tiles with the number “3” are meant to be impassible, but I can’t figure out how to make it so the character can’t walk there.

Public Sub Initialize()
'Opens the map file from a notepad file
FileOpener = New StreamReader(ChapterName & ".txt")
'Defines what image to draw dependant on the number in the notepad file
For CurrentRow = 0 To 47
MapTile = FileOpener.ReadLine.Split
For CurrentColumn = 0 To 50
Tiles(CurrentColumn, CurrentRow) = New Bitmap(MapTile(CurrentColumn) & ".bmp")
Next
Next
End Sub

Private Sub Game_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
'Draw the images from the map
For y = 0 To 47
For x = 0 To 50
e.Graphics.DrawImage(Tiles(x, y), x * 60 + OffsetX, y * 60 + OffsetY)
ObjectLocX = x * 60 + OffsetX
ObjectLocY = y * 60 + OffsetY
Next
Next
'The position of the character on the screen
e.Graphics.DrawImage(PC, 550, 400)

Thanks

Cardboard Box,
Use bb code tags to post source code. Source code must be surrounded with code tags.
For example,

[CODE=VB.NET] ... statements..

[/code]

Hi

Sorry about the lack of code tags. I will put one in next time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.