0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Cardboard Box
0

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]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.