Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


2d maze


2d maze

Author
Message
kaos8
kaos8
Forum God
Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)Forum God (355 reputation)

Group: Forum Members
Posts: 1, Visits: 5
This is my code to create a 2d mouse in the maze. Now i would like to check for collisions, if the mouse hit the walls.Can someone please tell me where i can add the codes.I know what to write but dont know where to put it.Can someone help me please.









Private Type Mouse

X1 As Integer 'bounding box values

X2 As Integer

Y1 As Integer

Y2 As Integer

End Type









Dim Leftwall As Mouse

Dim Rightwall As Mouse

Dim Topwall As Mouse

Dim Bottomwall As Mouse



Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyUp Then Call Mouseup_Click

If KeyCode = vbKeyDown Then Call Mousedown_Click

If KeyCode = vbKeyLeft Then Call Mouseleft_Click

If KeyCode = vbKeyRight Then Call Mouseright_Click



End Sub



Private Sub Render()

'This draws the proper shape





'for squares we just draw the four lines to make the outline

frmMaze.Line (Bottomwall.X1, Bottomwall.Y1)-(Bottomwall.X2, Bottomwall.Y1)

frmMaze.Line (Leftwall.X1, Leftwall.Y1)-(Leftwall.X1, Leftwall.Y2)

frmMaze.Line (Rightwall.X2, Rightwall.Y1)-(Rightwall.X2, Rightwall.Y2)

frmMaze.Line (Topwall.X1, Topwall.Y2)-(Topwall.X2, Topwall.Y2)







End Sub





Private Sub Form_Load()

'This initializes the properties of our shapes.



Bottomwall.X1 = 120

Bottomwall.X2 = 840

Bottomwall.Y1 = 240

Bottomwall.Y2 = 720



Leftwall.X1 = 120

Leftwall.X2 = 840

Leftwall.Y1 = 240

Leftwall.Y2 = 720



Rightwall.X1 = 120

Rightwall.X2 = 840

Rightwall.Y1 = 240

Rightwall.Y2 = 720





Topwall.X1 = 120

Topwall.X2 = 840

Topwall.Y1 = 240

Topwall.Y2 = 720





End Sub





Private Sub Mouseup_Click()



Bottomwall.X1 = Bottomwall.X1

Bottomwall.X2 = Bottomwall.X2

Bottomwall.Y1 = Bottomwall.Y1 - 100

Bottomwall.Y2 = Bottomwall.Y2 - 100



Leftwall.X1 = Leftwall.X1

Leftwall.X2 = Leftwall.X2

Leftwall.Y1 = Leftwall.Y1 - 100

Leftwall.Y2 = Leftwall.Y2 - 100



Rightwall.X1 = Rightwall.X1

Rightwall.X2 = Rightwall.X2

Rightwall.Y1 = Rightwall.Y1 - 100

Rightwall.Y2 = Rightwall.Y2 - 100



Topwall.X1 = Topwall.X1

Topwall.X2 = Topwall.X2

Topwall.Y1 = Topwall.Y1 - 100

Topwall.Y2 = Topwall.Y2 - 100



frmMaze.Cls

Render

End Sub



Private Sub Mousedown_Click()



Bottomwall.X1 = Bottomwall.X1

Bottomwall.X2 = Bottomwall.X2

Bottomwall.Y1 = Bottomwall.Y1 + 100

'Bottomwall.Y2 = Bottomwall.Y2 + 100



Leftwall.X1 = Leftwall.X1

Leftwall.X2 = Leftwall.X2

Leftwall.Y1 = Leftwall.Y1 + 100

Leftwall.Y2 = Leftwall.Y2 + 100



Rightwall.X1 = Rightwall.X1

Rightwall.X2 = Rightwall.X2

Rightwall.Y1 = Rightwall.Y1 + 100

Rightwall.Y2 = Rightwall.Y2 + 100



Topwall.X1 = Topwall.X1

Topwall.X2 = Topwall.X2

Topwall.Y1 = Topwall.Y1 + 100

Topwall.Y2 = Topwall.Y2 + 100



frmMaze.Cls

Render

End Sub





Private Sub Mouseleft_Click()





Bottomwall.X1 = Bottomwall.X1 - 100

Bottomwall.X2 = Bottomwall.X2 - 100

Bottomwall.Y1 = Bottomwall.Y1

Bottomwall.Y2 = Bottomwall.Y2



Leftwall.X1 = Leftwall.X1 - 100

Leftwall.X2 = Leftwall.X2 - 100

Leftwall.Y1 = Leftwall.Y1

Leftwall.Y2 = Leftwall.Y2



Rightwall.X1 = Rightwall.X1 - 100

Rightwall.X2 = Rightwall.X2 - 100

Rightwall.Y1 = Rightwall.Y1

Rightwall.Y2 = Rightwall.Y2



Topwall.X1 = Topwall.X1 - 100

Topwall.X2 = Topwall.X2 - 100

Topwall.Y1 = Topwall.Y1

Topwall.Y2 = Topwall.Y2

frmMaze.Cls

Render

End Sub



Private Sub Mouseright_Click()





Bottomwall.X1 = Bottomwall.X1 + 100

Bottomwall.X2 = Bottomwall.X2 + 100

Bottomwall.Y1 = Bottomwall.Y1

'Bottomwall.Y2 = Bottomwall.Y2



Leftwall.X1 = Leftwall.X1 + 100

Leftwall.X2 = Leftwall.X2 + 100

Leftwall.Y1 = Leftwall.Y1

Leftwall.Y2 = Leftwall.Y2



Rightwall.X1 = Rightwall.X1 + 100

Rightwall.X2 = Rightwall.X2 + 100

Rightwall.Y1 = Rightwall.Y1

Rightwall.Y2 = Rightwall.Y2



Topwall.X1 = Topwall.X1 + 100

Topwall.X2 = Topwall.X2 + 100

Topwall.Y1 = Topwall.Y1

Topwall.Y2 = Topwall.Y2

frmMaze.Cls

Render











End Sub











Chiko
Chiko
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 4, Visits: 3
Bottomwall.X1 = Bottomwall.X1
Bottomwall.X2 = Bottomwall.X2
Bottomwall.Y1 = Bottomwall.Y1 - 100
Bottomwall.Y2 = Bottomwall.Y2 - 100

^ You need to apply the checks before you execute code like that for example

Make an If statement and take away 100 to determine what it would be like if the wall was to move

then you would see if it conflicts with the mouse as hitting a wall e.g.

if BottomWall.Y1 - 100 ? mouse.y1 then

? replace with which ever code you need to <,>,=,<>,=<,=> etc

also i've noticed your moving the actual walls it would be better to just move the object its self however if its a sliding game moving the walls is easier but takes longer to process and also might be better to just draw a line rather then using lots of controls

e.g.  Form1.Line (X1,Y1)-(X2,Y2),Color,[Draw Type]

with Draw Type you can have

BF = makes a Filled in box

B = makes a box with no center (usually what ever is on the background)

It's also good to put Auto Redraw on for the Form and add Form1.refresh after you have done drawing to it and

Form1.cls to clear it

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search