Welcome to Dream.In.Code
Become a VB Expert!

Join 149,934 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,683 people online right now. Registration is fast and FREE... Join Now!




Need help finishing my maze game

 
Reply to this topicStart new topic

Need help finishing my maze game, need help creating a maze game

antgraham
10 Jan, 2008 - 04:11 AM
Post #1

New D.I.C Head
*

Joined: 10 Jan, 2008
Posts: 4

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 biggrin.gif thanks
User is offlineProfile CardPM
+Quote Post

antgraham
RE: Need Help Finishing My Maze Game
10 Jan, 2008 - 04:18 AM
Post #2

New D.I.C Head
*

Joined: 10 Jan, 2008
Posts: 4

[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 biggrin.gif thanks

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

CODE
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


User is offlineProfile CardPM
+Quote Post

ryan14690
RE: Need Help Finishing My Maze Game
24 Jan, 2008 - 03:54 AM
Post #3

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 2

CODE

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.gif

PsychoCoder smile.gif

This post has been edited by PsychoCoder: 24 Jan, 2008 - 06:05 AM
User is offlineProfile CardPM
+Quote Post

sam_benne
RE: Need Help Finishing My Maze Game
24 Jan, 2008 - 05:09 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 368



Thanked: 2 times
Dream Kudos: 400
My Contributions
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.
CODE

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.
User is offlineProfile CardPM
+Quote Post

ryan14690
RE: Need Help Finishing My Maze Game
24 Jan, 2008 - 05:54 AM
Post #5

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 2

CODE

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.gif

PsychoCoder smile.gif

This post has been edited by PsychoCoder: 24 Jan, 2008 - 06:05 AM
User is offlineProfile CardPM
+Quote Post

antgraham
RE: Need Help Finishing My Maze Game
27 Feb, 2008 - 02:02 AM
Post #6

New D.I.C Head
*

Joined: 10 Jan, 2008
Posts: 4

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


CODE
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


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 03:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month