Need help finishing my maze game

need help creating a maze game

Page 1 of 1

5 Replies - 7104 Views - Last Post: 27 February 2008 - 03:02 AM Rate Topic: -----

#1 antgraham  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-January 08

Need help finishing my maze game

Post icon  Posted 10 January 2008 - 05:11 AM

hi evereybody


i have recently moved coleges and have very limited knowledge of visual basic, i have completed the first assignment acheived a merit but the 2nd assignment is too hard for me. i have to create a maze. I have managed to set the keypresses so the shape moves around the screen and will not go off the screen, mny next task was to create the maze using the lines, i have had a little help and managed to get 1 line so the shape will not pass through it but now i am stuck any help out there :D thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Need help finishing my maze game

#2 antgraham  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-January 08

Re: Need help finishing my maze game

Posted 10 January 2008 - 05:18 AM

[quote name='antgraham' date='10 Jan, 2008 - 05:11 AM' post='295953']
hi evereybody


i have recently moved coleges and have very limited knowledge of visual basic, i have completed the first assignment acheived a merit but the 2nd assignment is too hard for me. i have to create a maze. I have managed to set the keypresses so the shape moves around the screen and will not go off the screen, mny next task was to create the maze using the lines, i have had a little help and managed to get 1 line so the shape will not pass through it but now i am stuck any help out there :D thanks

sorry i forgot to mention my code for the game so far is is

 If KeyCode = vbKeyD Then '
  If shpball.Left + shpball.Width > Line1.X1 And _
  shpball.Top < Line1.Y2 And _
  shpball.Top + shpball.Height > Line1.Y1 Then
  'do nothing'
  Else
  shpball.Left = shpball.Left + 100
  End If
  End If


  If KeyCode = vbKeyA Then
  If shpball.Left + shpball.Left <= frmmaze.ScaleLeft Then
  'do nothing'
  Else
  shpball.Left = shpball.Left - 100
  End If
  End If

  If KeyCode = vbKeyW Then
  If shpball.Top + shpball.Top <= frmmaze.ScaleTop Then
  'do nothing'
  Else
  shpball.Top = shpball.Top - 100
  End If
  End If

  If KeyCode = vbKeyS Then
  If shpball.Top + shpball.Height >= frmmaze.ScaleHeight Then
  'do nothing'
  Else
  shpball.Top = shpball.Top + 100
  End If
  End If
End Sub



Was This Post Helpful? 0
  • +
  • -

#3 ryan14690  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-January 08

Re: Need help finishing my maze game

Posted 24 January 2008 - 04:54 AM

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

If KeyCode = vbKeyRight Then
  
 If shpball.Left + shpball.Width <= frmmaze.ScaleWidth Then
	   'do nothing
 Else
	 shpball.Left = shpball.Left - 100
End If
  
 If shpball.Left + shpball.Width > lne1.X1 And _
   shpball.Top < lne1.Y2 And _
   shpball.Top + shpball.Height > lne1.Y1 Then
	   'do nothing
 Else
   shpball.Left = shpball.Left + 100
 End If
  
End If


If KeyCode = vbKeyLeft Then
 If shpball.Left + shpball.Left <= frmmaze.ScaleLeft Then
	'do nothing
 Else
	shpball.Left = shpball.Left - 100
 End If
 
End If

If KeyCode = vbKeyUp Then
 If shpball.Top + shpball.Top <= frmmaze.ScaleTop Then
	'do nothing
 Else
	shpball.Top = shpball.Top - 100
 End If
 
End If

If KeyCode = vbKeyDown Then
 If shpball.Top + shpball.Height >= frmmaze.ScaleHeight Then
	'do nothing
 Else
	shpball.Top = shpball.Top + 100
 End If
End If


End Sub




this is my code which is similar to yours.....

my ball wont move throught the wall when the right key id pressed

the problem is that when i go round the wall it will go back through the wall when i press left. also when im on the right hand side of the line it wont let me move right when the ball is in line with the line itself, why is this?

EDIT: Please use code tags in the future when posting code, it make it much easier for the reader to read the code, use them like so => :code:

PsychoCoder :)

This post has been edited by PsychoCoder: 24 January 2008 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#4 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Need help finishing my maze game

Posted 24 January 2008 - 06:09 AM

Instead of it stopping you from going through the line why don't you make it restart the form which would be easier.
Here is a sample code as I have done a similar thing to you.
Private Sub shpLine_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Load frm???
frm???.Show
Unload frm???
End Sub


It works for me and very easy to do.
Was This Post Helpful? 0
  • +
  • -

#5 ryan14690  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-January 08

Re: Need help finishing my maze game

Posted 24 January 2008 - 06:54 AM

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

If KeyCode = vbKeyRight Then

   If shpball.Left + shpball.Width = frmmaze.ScaleWidth Or _
	  shpball.Left + shpball.Width > lne1.X1 And _
	  shpball.Top < lne1.Y2 And _
	  shpball.Top + shpball.Height > lne1.Y1 Then
	  'do nothing
   Else
	  shpball.Left = shpball.Left + 100
   End If
End If


If KeyCode = vbKeyLeft Then
 
   If shpball.Left <= frmmaze.ScaleLeft Or _
	  shpball.Left = lne1.X1 And _
	  shpball.Top < lne1.Y2 And _
	  shpball.Top + shpball.Height > lne1.Y1 Then
	  'do nothing
   Else
	  shpball.Left = shpball.Left - 100
   End If
End If

If KeyCode = vbKeyUp Then
  
   If shpball.Top < frmmaze.ScaleTop Or _
	  shpball.Top < lne1.Y2 And _
	  shpball.Left < lne1.X1 And _
	  shpball.Left + shpball.Width > lne1.X1 Then
	  'do nothing
   Else
	  shpball.Left = shpball.Left + 100
   End If
End If

If KeyCode = vbKeyDown Then
 
   If shpball.Height <= frmmaze.ScaleHeight Or _
	  shpball.Height <= lne1.Y2 And _
	  shpball.Left < lne1.X1 And _
	  shpball.Left + shpball.Width > lne1.X1 Then
	  'do nothing
   Else
	  shpball.Left = shpball.Left + 100
   End If
End If


End Sub




i now have it working but it wont move up or down. and the up button moves right as well???????? and i cant find the reason why?

EDIT: Please use code tags in the future when posting code, it make it much easier for the reader to read the code, use them like so => :code:

PsychoCoder :)

This post has been edited by PsychoCoder: 24 January 2008 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#6 antgraham  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-January 08

Re: Need help finishing my maze game

Posted 27 February 2008 - 03:02 AM

I now have it all working apart from when you go around the wall it still comes back through this is the final peice of code i need help with is there anybody that can do it here is the code i have so far


 Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'********MOVES SHAPE RIGHT********
If KeyCode = vbKeyD Then
If shpball.Left + shpball.Width <= frmmaze.ScaleWidth Then
'do nothing
Else
shpball.Left = shpball.Left - 100
End If
  
If shpball.Left + shpball.Width > lne1.X1 And _
   shpball.Top < lne1.Y2 And _
   shpball.Top + shpball.Height > lne1.Y1 Then
	   'do nothing
Else
   shpball.Left = shpball.Left + 100
End If
  
End If


'******MOVES SHAPE LEFT *************

If KeyCode = vbKeyA Then
If shpball.Left <= frmmaze.ScaleLeft Or _
shpball.Left <= lne1.X1 And _
shpball.Top < lne1.Y2 And _
shpball.Top < lne1.Y2 And _
shpball.Top < shpball.Height > lne1.Y2 Then
'do nothing'
Else
shpball.Left = shpball.Left - 100
End If
End If

'************moves shape up****************

If KeyCode = vbKeyW Then
If shpball.Top <= frmmaze.ScaleTop Or _
shpball.Top <= lne1.Y2 And _
shpball.Left < lne1.X1 And _
shpball.Left + shpball.Width > lne1.X1 Then
'do nothing'
Else
shpball.Top = shpball.Top - 100
End If
End If

'**************moves shape down****************'
If KeyCode = vbKeyS Then
  If shpball.Top + shpball.Height > frmmaze.ScaleHeight Then
   'do nothing'
  Else
   If shpball.Top + shpball.Width <= frmmaze.ScaleTop Or _
   shpball.Height <= lne1.Y1 And _
   shpball.Left < lne1.X1 And _
   shpball.Left + shpball.Width > lne1.X1 Then
   'do nothing
   Else
   shpball.Top = shpball.Top + 100
   
   End If
  End If
End If

End Sub



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1