Page 1 of 2 12 LastLast
Results 1 to 40 of 53

Thread: Help With Maze Game

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23

    Help With Maze Game

    Hi im Simon and im new to the forums because i have only recently got a hold of a copy of VB.

    I was wondering if anyone could help me withthis problem. I'm making a maze game and i have assigned the snail to the arrow keys so it can move about on the form but how can i make it so it can only go on the white parts(where the black arrows on the picture are) of the image and not the black parts (where the red arrows are)?
    Also is it possible to make it so when the snail gets to the end of the maze an msg box pops up saying level compeleted an goes back to the main screen.

    i would eb eternally greatful if any could help me with this and i will try and return the fav in the future.


  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Is this mase just a picture??? If it is, then you probably have to check the color in front of the snail....so if it is black, then you can't move it there, if it is white...then it will be able to move there..

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    the maze is an image one i just made up in fireworks i am a nOOb at Vb btw so could u plz explaian what u mean by checking the colour. do u mean an IF staement? if so how do i do that?

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    First you need to get the color...search this forum for GetPixel API. That one will tell you if it is a black or a white point you are checking...then I guess you have to check in the front of the snail..


    nose
    left shoulder
    right shoulder

    Then id all the pixels in fronr tof him is white, then move, if not do anything else...

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    An other thing I just thought of when I saw See The Geek reading this was, that BSP trees are great for this kind of thing.

    But that might be a bit hard....but you could do it simpler if you change your map a bit. If you make it in small sqares, so you can devide it in lets say 15*15 pixels, and all the pixels in that sqare has the same color, then you can set up a 2D array like this where 0 = black sqare and 1 = white sqare

    000000000000
    001101100000
    011111111000
    011000001110
    001110001100
    000011111000

    If you looka the pattern there, you can tell where the snail is, and then check if up is a 0 or a 1 and then tell it if it can go there or not...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    cheers for the all help i kinda of get the logic but the praticale for it is different.
    ive only had vb for the past 3-4days so it would be very helpfully if u could put explinations on how to do this stuff if that not a problem plz

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I am at school now...and on my way home...are going to eat and stuff first...but when I get my GF off my tail I can try to gice you a sample...if no one else has doen it before me...

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    if u could mate that would be like the best thing anyones ever done for me dude (speaking like a true n00b)

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Sorry that it took so much time...my GF is a pain in the ass when it comes to letting me play with my computer....


    but here it is...hope you still need it.


    I used the 2D array method. It is simpler to understand, but the way I have done it it can be a pain in the ass to set up...
    Attached Files Attached Files

  10. #10
    Member jonask's Avatar
    Join Date
    Apr 2004
    Location
    Sandefjord, Norway
    Posts
    38
    Hi, Just read your post here. I like these kind of games, I really do. But it's not the easiest thing to start with.. As Noteme said, you need to eighter check the color of square you move into, or better yet, load the whole thing into an array. I got JUST the sample for you, I made it a couple of years a go as an introduction to VB gaming.
    But unfortunatly I'm at work tonight and behind a heavy military firewall, so I cant access my homecomputer to move it to my httpd directory for you But hang tight, Noteme said he was gonna make you one so it would probaly kick mine hard anyways, but I'll post back when I get the file for you.

    Cheers!

    ---
    P.S.
    Oh, yeah, problem solved I see? never mind then
    --
    Jonas

  11. #11
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by jonask
    Hi, Just read your post here. I like these kind of games, I really do. But it's not the easiest thing to start with.. As Noteme said, you need to eighter check the color of square you move into, or better yet, load the whole thing into an array. I got JUST the sample for you, I made it a couple of years a go as an introduction to VB gaming.
    But unfortunatly I'm at work tonight and behind a heavy military firewall, so I cant access my homecomputer to move it to my httpd directory for you But hang tight, Noteme said he was gonna make you one so it would probaly kick mine hard anyways, but I'll post back when I get the file for you.

    Cheers!

    Don't get your hopes to high...I used 6 minutes to do that sample......I want him to do most of it him self...and used some ofther techinques as well so it is not that easy to just copy my source....I have some nice ideas on how to make it better, but I will waith for his reply to see what he sais..

  12. #12
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    And BTW....tell me if you need some simple algorithms to find the way out too...

  13. #13
    Member jonask's Avatar
    Join Date
    Apr 2004
    Location
    Sandefjord, Norway
    Posts
    38
    I found the old piece of crapcode now
    http://www.planet-source-code.com/vb...25939&lngWId=1

    It's not really what you need, there arent really any walls since the player falls off instead, but hey?
    --
    Jonas

  14. #14

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    cheers noteme that is just what im after i wont be able to put it in practise because i just check the fourms as soon as i got into my c programming class so when i get out i will give it a try. cheers!

  15. #15
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    cheers noteme that is just what im after i wont be able to put it in practise because i just check the fourms as soon as i got into my c programming class so when i get out i will give it a try. cheers!

    No problem, just tell me if you get any problems...and I forgot to comment the code...so just ask any questions.

  16. #16
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by jonask
    I found the old piece of crapcode now
    http://www.planet-source-code.com/vb...25939&lngWId=1

    It's not really what you need, there arent really any walls since the player falls off instead, but hey?

    Hehe...that was hard as drittfittefaen...went to fast... ..

  17. #17
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I also have an old sample here, for something I did some years ago.


    You can make the maze at runtime by clicking the grid lines. make sure there is an opening in the front of the mouse, and in one of the sides, top, right, or bottom. And never make the path bigger then one sqare. When you press start. The mouse will use the right hand algorithm, to find teh way out.
    Attached Files Attached Files

  18. #18

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    NoteMe i started looking at the maze example with the red block thats can be downloaded in this thred and i got confussed with this piece of code could u plz help

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     If KeyCode = 39 Then
    4.         If map(X + 1, Y) = 1 Then
    5.             X = X + 1
    6.             picRed.Left = picRed.Left + picRed.Width
    7.         End If
    8.     ElseIf KeyCode = 37 Then
    9.         If map(X - 1, Y) = 1 Then
    10.             X = X - 1
    11.             picRed.Left = picRed.Left - picRed.Width
    12.         End If
    13.     ElseIf KeyCode = 38 Then
    14.         If map(X, Y - 1) = 1 Then
    15.             Y = Y - 1
    16.             picRed.Top = picRed.Top - picRed.Height
    17.         End If
    18.     ElseIf KeyCode = 40 Then
    19.         If map(X, Y + 1) = 1 Then
    20.             Y = Y + 1
    21.             picRed.Top = picRed.Top + picRed.Height
    22.         End If
    23.     End If
    24.    
    25.    
    26. End Sub

    what are the numbers for the 39 ,37,38,40 and how did u work out what numbers u use i can for the life figure it out plz help me
    i will be gratefully

  19. #19
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    Those numbers are ascii codes for the arrow keys, go to www.asciitable.com should show you what the numbers mean.

    Or maybe it doesnt, anyway, to figure out what number corresponds with what key put this in the keydown event:

    MsgBox Chr(KeyCode)

    And to get the numbers that go with the arrowkeys:
    MsgBox vbKeyUp
    MsgBox vbKeyLeft
    msgbox vbKeyRight
    msgbox vbKeyDown


    Pretty sure those are all legit, havent checked em
    Last edited by dsheller; Jun 6th, 2004 at 10:24 PM.

  20. #20
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    NoteMe i started looking at the maze example with the red block thats can be downloaded in this thred and i got confussed with this piece of code could u plz help

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     If KeyCode = 39 Then
    4.         If map(X + 1, Y) = 1 Then
    5.             X = X + 1
    6.             picRed.Left = picRed.Left + picRed.Width
    7.         End If
    8.     ElseIf KeyCode = 37 Then
    9.         If map(X - 1, Y) = 1 Then
    10.             X = X - 1
    11.             picRed.Left = picRed.Left - picRed.Width
    12.         End If
    13.     ElseIf KeyCode = 38 Then
    14.         If map(X, Y - 1) = 1 Then
    15.             Y = Y - 1
    16.             picRed.Top = picRed.Top - picRed.Height
    17.         End If
    18.     ElseIf KeyCode = 40 Then
    19.         If map(X, Y + 1) = 1 Then
    20.             Y = Y + 1
    21.             picRed.Top = picRed.Top + picRed.Height
    22.         End If
    23.     End If
    24.    
    25.    
    26. End Sub

    what are the numbers for the 39 ,37,38,40 and how did u work out what numbers u use i can for the life figure it out plz help me
    i will be gratefully

    DSheller is right, but let me try to explain the rest of it too.

    X is the X position, Y is the Y position of the red sqare.

    Map is an 2D array of the type long if I remember right. It is either 1 or 0. If the value is 1 then the sqare at that X,Y position is white. If it is 0. Then it is Black, and you can't move there. So let me comment the code:

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     'If the right arrow key was pushed then
    4.     If KeyCode = 39 Then
    5.         'If the number in the array that is 1 more to the right is 1 (white) then
    6.         If map(X + 1, Y) = 1 Then
    7.             'Set the X positon one more to the right
    8.             X = X + 1
    9.             'Move the red sqare to the right the same amount as the width of the red square.
    10.             picRed.Left = picRed.Left + picRed.Width
    11.         End If
    12.     'If the left arrow key was pushed then
    13.     ElseIf KeyCode = 37 Then
    14.         'If the number in the array that is 1 more to the left is 1 (white) then
    15.         If map(X - 1, Y) = 1 Then
    16.             'Set the X positon one more to the left
    17.             X = X - 1
    18.              'Move the red sqare to the left the same amount as the width of the red square.
    19.             picRed.Left = picRed.Left - picRed.Width
    20.         End If
    21.      'If the up arrow key was pushed then
    22.     ElseIf KeyCode = 38 Then
    23.          'If the number in the array that is 1 more to up is 1 (white) then
    24.         If map(X, Y - 1) = 1 Then
    25.             'Set the y positon one more to the up
    26.             Y = Y - 1
    27.             'Move the red sqare to up the same amount as the hight of the red square.
    28.             picRed.Top = picRed.Top - picRed.Height
    29.         End If
    30.      'If the down arrow key was pushed then
    31.     ElseIf KeyCode = 40 Then
    32.         'If the number in the array that is 1 more down is 1 (white) then
    33.         If map(X, Y + 1) = 1 Then
    34.             'Set the y positon one more to the down
    35.             Y = Y + 1
    36.             'Move the red sqare to down the same amount as the hight of the red square.
    37.             picRed.Top = picRed.Top + picRed.Height
    38.         End If
    39.     End If
    40.    
    41.    
    42. End Sub


    If you still don't get it. Tell me what you don't understand, and I can try to make a picture for you when I get home today.

  21. #21

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    im still having a bit of trouble understanding it i try to do it in the same way but didn't work ill upload what i have done.

    the one im working on at the moment is level 1

    it probally something im over looking o if u can help me sort it that would be great cheers
    Attached Files Attached Files

  22. #22
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    im still having a bit of trouble understanding it i try to do it in the same way but didn't work ill upload what i have done.

    the one im working on at the moment is level 1

    it probally something im over looking o if u can help me sort it that would be great cheers

    What is the exact problem you are having? I am downloading it now, but I don't think I have the time to fix if before I go to work. If not, then I will do it after work. But please give me an explenation of what is not working...

  23. #23
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    And can you please try to upload it again. I can't download it correct. Please don't use spaces in the name. And try to zip it again just to be sure. My zip app sais it is not valid....

  24. #24

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    well when i try having ago on mine i cant get it to work thats y i asked about the number 39/38/37/40 becasue i didn't know what they signify
    Attached Files Attached Files

  25. #25
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    well when i try having ago on mine i cant get it to work thats y i asked about the number 39/38/37/40 becasue i didn't know what they signify

    First error...set KeyPreview to true on the form.


    I am jumping in the shower now. See if you can figgure the next error out by your self. At least now it is moving...


    PS: I liked the intro...

  26. #26
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Finished the shower now...

    ok....next problem was the starting values of X and X. X=0 Y=0 should be in the upper left corner. You had written

    X = 1
    Y = 1

    in the form load event. And then placed the sanil in the "upper" right corner. Then XY coordinates for that place is not (1,1) but (12,1). So this should do it:


    X = 12
    Y = 1


    The next "error" is that the snail is bigger then the sqares in your app. So when you move it with the hight and width of the snail, it moves just a bit more then the sqare. Resulting in an ever increasing error in posiotin. You have to make the snil smaller og move it as the same height or width of one of the black sqares...


    Hope that helped. I am out of here now. Just post again if there was something more, and I will help you when I get back home tonight, og someone else will.

    ØØ

  27. #27

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    cheers dude ill give that a try it always the obvious thing i can never do lol

  28. #28

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    hey noteme could u plz help me with the last stages im trying to work it out bit to no avale i cant get the image to stay on the path it ever so slightly goes off and i would like to put a point where the game ends whennu reach the end and a timer that changes so different difficultys i would like to to talk me through so i can learn while building it if u get me.
    i''m sorry to have to trouble you but i am keen to learn so if you could help it would be cool. Thanks!!

  29. #29
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    hehe...ok...I deleted the files sorry...can you post the code as it is now? Did you fix the things I commented on?


    And can you summary up what you needed like.

    - i cant get the image to stay on the path it ever so slightly goes off
    - and so on


    BTW didn't I tell you how to get the snail to not go off...look 2-3 posts up..

  30. #30

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    i will upload the file again with the changes but what i want is

    1, All three levels using the same map but the time per level decrease the harder it gets so you have shorter time to do it in.

    2. you will see what i mean by the sanil no matter what i do i cant get it to stay directly on the path.

    3. an end place where once u reace a certqain part ont eh map teh game will end and you would have won.

    is all that possible plz say it is lol

    cheers very much for this!!!!!
    Attached Files Attached Files

  31. #31
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    1. You have to add a timer to each level. Then just set the interval less on level two then level 1, and even less on level 3. The interval is mesured in ms. So 1000ms = 1sec. Then in the Timer event, do what ever you want when the time is out.


    2. You havn't made the snail the same size as the black sqares. The snail is 25*25 pixels. And the Black Sqares are 33*33


    3. Just have an if test or something that tests if you are on a spesific X, Y coordinate after you have moved.

    3. Or you can set the value to 2, one place in the array. Then do an if test after you have moved, and check if you are standing on the place in the array where it sais 2.


    Hope that helped

  32. #32

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    i cant get the 3rd on right what do i put in the say when the snail is on (0, 1) which =2 can i get a box saying you have won appear
    VB Code:
    1. Option Explicit
    2. Dim map(15, 9) As Long
    3. Dim X As Long
    4. Dim Y As Long
    5. Private Sub cmdExit_Click()
    6. End
    7. End Sub
    8.  
    9. Private Sub cmdMenu_Click()
    10. Load frmLevel
    11. frmLevel.Show
    12. frmMaze1.Hide
    13. End Sub
    14.  
    15. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    16.  
    17.     If KeyCode = 39 Then
    18.         If map(X + 1, Y) = 1 Then
    19.             X = X + 1
    20.             picSnail.Left = picSnail.Left + picSnail.Width
    21.          End If
    22.     ElseIf KeyCode = 37 Then
    23.         If map(X - 1, Y) = 1 Then
    24.             X = X - 1
    25.             picSnail.Left = picSnail.Left - picSnail.Width
    26.         End If
    27.     ElseIf KeyCode = 38 Then
    28.         If map(X, Y - 1) = 1 Then
    29.             Y = Y - 1
    30.             picSnail.Top = picSnail.Top - picSnail.Height
    31.         End If
    32.     ElseIf KeyCode = 40 Then
    33.         If map(X, Y + 1) = 1 Then
    34.             Y = Y + 1
    35.             picSnail.Top = picSnail.Top + picSnail.Height
    36.         End If
    37.    
    38.        
    39.     End If
    40.    
    41.    
    42. End Sub
    43.  
    44. Private Sub Form_Load()
    45.  
    46.     X = 14
    47.     Y = 1
    48.     map(0, 0) = 0
    49.     map(1, 0) = 0
    50.     map(2, 0) = 0
    51.     map(3, 0) = 0
    52.     map(4, 0) = 0
    53.     map(5, 0) = 0
    54.     map(6, 0) = 0
    55.     map(7, 0) = 0
    56.     map(8, 0) = 0
    57.     map(9, 0) = 0
    58.     map(10, 0) = 0
    59.     map(11, 0) = 0
    60.     map(12, 0) = 0
    61.     map(13, 0) = 0
    62.     map(14, 0) = 0
    63.  
    64.     map(0, 1) = 2
    65.     map(1, 1) = 1
    66.     map(2, 1) = 1
    67.     map(3, 1) = 0
    68.     map(4, 1) = 1
    69.     map(5, 1) = 1
    70.     map(6, 1) = 1
    71.     map(7, 1) = 1
    72.     map(8, 1) = 1
    73.     map(9, 1) = 1
    74.     map(10, 1) = 1
    75.     map(11, 1) = 1
    76.     map(12, 1) = 1
    77.     map(13, 1) = 1
    78.     map(14, 1) = 1
    79.  
    80.     map(0, 2) = 0
    81.     map(1, 2) = 0
    82.     map(2, 2) = 1
    83.     map(3, 2) = 0
    84.     map(4, 2) = 1
    85.     map(5, 2) = 0
    86.     map(6, 2) = 0
    87.     map(7, 2) = 0
    88.     map(8, 2) = 1
    89.     map(9, 2) = 0
    90.     map(10, 2) = 0
    91.     map(11, 2) = 1
    92.     map(12, 2) = 0
    93.     map(13, 2) = 0
    94.     map(14, 2) = 0
    95.    
    96.     map(0, 3) = 0
    97.     map(1, 3) = 1
    98.     map(2, 3) = 1
    99.     map(3, 3) = 0
    100.     map(4, 3) = 0
    101.     map(5, 3) = 1
    102.     map(6, 3) = 1
    103.     map(7, 3) = 0
    104.     map(8, 3) = 1
    105.     map(9, 3) = 0
    106.     map(10, 3) = 1
    107.     map(11, 3) = 1
    108.     map(12, 3) = 0
    109.     map(13, 3) = 0
    110.     map(14, 3) = 0
    111.    
    112.     map(0, 4) = 0
    113.     map(1, 4) = 0
    114.     map(2, 4) = 1
    115.     map(3, 4) = 1
    116.     map(4, 4) = 0
    117.     map(5, 4) = 1
    118.     map(6, 4) = 0
    119.     map(7, 4) = 0
    120.     map(8, 4) = 1
    121.     map(9, 4) = 0
    122.     map(10, 4) = 0
    123.     map(11, 4) = 0
    124.     map(12, 4) = 1
    125.     map(13, 4) = 1
    126.     map(14, 4) = 0
    127.    
    128.     map(0, 5) = 0
    129.     map(1, 5) = 0
    130.     map(2, 5) = 0
    131.     map(3, 5) = 1
    132.     map(4, 5) = 1
    133.     map(5, 5) = 1
    134.     map(6, 5) = 1
    135.     map(7, 5) = 1
    136.     map(8, 5) = 1
    137.     map(9, 5) = 1
    138.     map(10, 5) = 1
    139.     map(11, 5) = 0
    140.     map(12, 5) = 1
    141.     map(13, 5) = 0
    142.     map(14, 5) = 0
    143.    
    144.     map(0, 6) = 0
    145.     map(1, 6) = 1
    146.     map(2, 6) = 1
    147.     map(3, 6) = 1
    148.     map(4, 6) = 0
    149.     map(5, 6) = 1
    150.     map(6, 6) = 0
    151.     map(7, 6) = 1
    152.     map(8, 6) = 0
    153.     map(9, 6) = 0
    154.     map(10, 6) = 1
    155.     map(11, 6) = 0
    156.     map(12, 6) = 1
    157.     map(13, 6) = 0
    158.     map(14, 6) = 0
    159.    
    160.     map(0, 7) = 0
    161.     map(1, 7) = 1
    162.     map(2, 7) = 0
    163.     map(3, 7) = 1
    164.     map(4, 7) = 0
    165.     map(5, 7) = 1
    166.     map(6, 7) = 0
    167.     map(7, 7) = 1
    168.     map(8, 7) = 1
    169.     map(9, 7) = 1
    170.     map(10, 7) = 1
    171.     map(11, 7) = 1
    172.     map(12, 7) = 1
    173.     map(13, 7) = 0
    174.     map(14, 7) = 0
    175.    
    176.     map(0, 8) = 0
    177.     map(1, 8) = 0
    178.     map(2, 8) = 0
    179.     map(3, 8) = 0
    180.     map(4, 8) = 0
    181.     map(5, 8) = 0
    182.     map(6, 8) = 0
    183.     map(7, 8) = 0
    184.     map(8, 8) = 0
    185.     map(9, 8) = 0
    186.     map(10, 8) = 0
    187.     map(11, 8) = 0
    188.     map(12, 8) = 0
    189.     map(13, 8) = 0
    190.     map(14, 8) = 0
    191.  
    192. End Sub
    this is the code for the game dude can u help?

    i know u must be really pissed an shouting oh f*#$ing n00bs and i applogise again lol
    Attached Files Attached Files

  33. #33

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    i have done it now basivally but i was wondering how i could get a timer ie a lable to cout down so the user could see how much time they have left if u can help me out with this problem that is it cheers
    Attached Files Attached Files

  34. #34
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Sorry about the "you win" thingy. I didn't think of that you have to change


    if (map(x+1,y) = 1 then


    and so on lines had to be changed to

    if (map(x+1,y) >0 then


    so the correct code for the key down event is like this:

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     If KeyCode = 39 Then
    4.         If map(X + 1, Y) > 0 Then
    5.             X = X + 1
    6.             picSnail.Left = picSnail.Left + Picture37.Width
    7.         End If
    8.     ElseIf KeyCode = 37 Then
    9.         If map(X - 1, Y) > 0 Then
    10.             X = X - 1
    11.             picSnail.Left = picSnail.Left - Picture37.Width
    12.         End If
    13.     ElseIf KeyCode = 38 Then
    14.         If map(X, Y - 1) > 0 Then
    15.             Y = Y - 1
    16.             picSnail.Top = picSnail.Top - Picture37.Height
    17.         End If
    18.     ElseIf KeyCode = 40 Then
    19.         If map(X, Y + 1) > 0 Then
    20.             Y = Y + 1
    21.             picSnail.Top = picSnail.Top + Picture37.Height
    22.         End If
    23.     End If
    24.    
    25.     If (map(X, Y) = 2) Then
    26.         MsgBox "You won"
    27.     End If
    28.    
    29. End Sub

  35. #35

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    This is what i did and just made a form for the you won and it seems to work fine but what i would like to learn now is how to make a lable count down from 30 -0 as an idicator of a timer if you could help with that that would be great beeacse my game will now be compleleted
    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     If KeyCode = 39 Then
    4.         If map(X + 1, Y) = 1 Then
    5.             X = X + 1
    6.             picSnail.Left = picSnail.Left + Picture1.Width
    7.          End If
    8.     ElseIf KeyCode = 37 Then
    9.         If map(X - 1, Y) = 1 Then
    10.             X = X - 1
    11.             picSnail.Left = picSnail.Left - Picture1.Width
    12.         End If
    13.         If map(X - 1, Y) = 2 Then
    14.             X = X - 1
    15.             picSnail.Left = picSnail.Left - Picture1.Width
    16.             Load frmWon
    17.             frmWon.Show
    18.         End If
    19.     ElseIf KeyCode = 38 Then
    20.         If map(X, Y - 1) = 1 Then
    21.             Y = Y - 1
    22.             picSnail.Top = picSnail.Top - Picture1.Height
    23.         End If
    24.     ElseIf KeyCode = 40 Then
    25.         If map(X, Y + 1) = 1 Then
    26.             Y = Y + 1
    27.             picSnail.Top = picSnail.Top + Picture1.Height
    28.         End If
    29.    
    30.        
    31.     End If
    32.    
    33.    
    34. End Sub

  36. #36
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    i have done it now basivally but i was wondering how i could get a timer ie a lable to cout down so the user could see how much time they have left if u can help me out with this problem that is it cheers
    First of all. The code in the timer even was all wrong. You had an if test to check if the Interval was 30 sec. But that one will be 30 sec all the time.


    What you want to check is if there is not time left.

    The Timer event is only triggered when there is no time left...


    But since you want a count down, we have to alter the code in the timer anyway.

    First set the Caption in the label to 30. Becuase you want a 30 seconds count down. Then add this code to the timer event:

    VB Code:
    1. Private Sub Timer1_Timer()
    2.  
    3.     lblTime.Caption = Val(lblTime.Caption) - 1
    4.     If (Val(lblTime.Caption) = 0) Then
    5.         Timer1.Enabled = False
    6.         Load frmLost
    7.         frmLost.Show
    8.     End If
    9.  
    10. End Sub

    Then set the interval of thetimer to 1000 (then it gets triggered every sec). The first line here, decreeses the valuse in your label with one. Then it checks to see if the label now is 0. If it is not. Then not thing more, happen. It does this 30 times (30 seconds has gone). Then the 30th time the timer event is called. It goes into the if test. And shows the form you wanted to be displayed.



    And other error is that in your form load event had added this line:

    lblTime.Caption = Time

    That line gives the label the current time on your machine. You don't want that. And since you all ready have added 30 to the Caption of lblTime, then you are fine, so just remove this line.


    Thats how to do it.
    ØØ

  37. #37
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Llewells
    This is what i did and just made a form for the you won and it seems to work fine but what i would like to learn now is how to make a lable count down from 30 -0 as an idicator of a timer if you could help with that that would be great beeacse my game will now be compleleted
    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2.  
    3.     If KeyCode = 39 Then
    4.         If map(X + 1, Y) = 1 Then
    5.             X = X + 1
    6.             picSnail.Left = picSnail.Left + Picture1.Width
    7.          End If
    8.     ElseIf KeyCode = 37 Then
    9.         If map(X - 1, Y) = 1 Then
    10.             X = X - 1
    11.             picSnail.Left = picSnail.Left - Picture1.Width
    12.         End If
    13.         If map(X - 1, Y) = 2 Then
    14.             X = X - 1
    15.             picSnail.Left = picSnail.Left - Picture1.Width
    16.             Load frmWon
    17.             frmWon.Show
    18.         End If
    19.     ElseIf KeyCode = 38 Then
    20.         If map(X, Y - 1) = 1 Then
    21.             Y = Y - 1
    22.             picSnail.Top = picSnail.Top - Picture1.Height
    23.         End If
    24.     ElseIf KeyCode = 40 Then
    25.         If map(X, Y + 1) = 1 Then
    26.             Y = Y + 1
    27.             picSnail.Top = picSnail.Top + Picture1.Height
    28.         End If
    29.    
    30.        
    31.     End If
    32.    
    33.    
    34. End Sub
    What you have done here is a hack to make it work. It will only work on maps where you have to press left on the last tile you have to pass to win. If all the mazes are like that, then it will work.

    Nice job.

  38. #38

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    23
    hey dude with ur help i have managed to finish it. i made all the levels trhe same but with different times so it changed the difficulty of the game but heres the finished creation.

    cheers dude for all the help you gave me and basically did all the work lol i will try repay the fav if u ever need help on umm camels or somthing
    Attached Files Attached Files

  39. #39
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    No problem. Glad to help. It looks better now. Still a lot of things you can do with it. And it seems like you have learn a bit.

    And maybe if you ask very kindly the BAD BAD moderator want to put it in the demo section for you. So others can have some fun with it...

    ØØ

  40. #40
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Yeah if you want to put it in the Demo section I can either move this thread their or if you want just create a new thread in there .

    Might be better creating a new thread though becuase this one really starts off as a question .
    Might be an idea too to link to this thread from it so people can see the start of it .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width