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.
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..
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?
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...
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
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
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...
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
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..
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!
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.
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.
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:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
If map(X + 1, Y) = 1 Then
X = X + 1
picRed.Left = picRed.Left + picRed.Width
End If
ElseIf KeyCode = 37 Then
If map(X - 1, Y) = 1 Then
X = X - 1
picRed.Left = picRed.Left - picRed.Width
End If
ElseIf KeyCode = 38 Then
If map(X, Y - 1) = 1 Then
Y = Y - 1
picRed.Top = picRed.Top - picRed.Height
End If
ElseIf KeyCode = 40 Then
If map(X, Y + 1) = 1 Then
Y = Y + 1
picRed.Top = picRed.Top + picRed.Height
End If
End If
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
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:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
If map(X + 1, Y) = 1 Then
X = X + 1
picRed.Left = picRed.Left + picRed.Width
End If
ElseIf KeyCode = 37 Then
If map(X - 1, Y) = 1 Then
X = X - 1
picRed.Left = picRed.Left - picRed.Width
End If
ElseIf KeyCode = 38 Then
If map(X, Y - 1) = 1 Then
Y = Y - 1
picRed.Top = picRed.Top - picRed.Height
End If
ElseIf KeyCode = 40 Then
If map(X, Y + 1) = 1 Then
Y = Y + 1
picRed.Top = picRed.Top + picRed.Height
End If
End If
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:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'If the right arrow key was pushed then
If KeyCode = 39 Then
'If the number in the array that is 1 more to the right is 1 (white) then
If map(X + 1, Y) = 1 Then
'Set the X positon one more to the right
X = X + 1
'Move the red sqare to the right the same amount as the width of the red square.
picRed.Left = picRed.Left + picRed.Width
End If
'If the left arrow key was pushed then
ElseIf KeyCode = 37 Then
'If the number in the array that is 1 more to the left is 1 (white) then
If map(X - 1, Y) = 1 Then
'Set the X positon one more to the left
X = X - 1
'Move the red sqare to the left the same amount as the width of the red square.
picRed.Left = picRed.Left - picRed.Width
End If
'If the up arrow key was pushed then
ElseIf KeyCode = 38 Then
'If the number in the array that is 1 more to up is 1 (white) then
If map(X, Y - 1) = 1 Then
'Set the y positon one more to the up
Y = Y - 1
'Move the red sqare to up the same amount as the hight of the red square.
picRed.Top = picRed.Top - picRed.Height
End If
'If the down arrow key was pushed then
ElseIf KeyCode = 40 Then
'If the number in the array that is 1 more down is 1 (white) then
If map(X, Y + 1) = 1 Then
'Set the y positon one more to the down
Y = Y + 1
'Move the red sqare to down the same amount as the hight of the red square.
picRed.Top = picRed.Top + picRed.Height
End If
End If
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.
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...
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....
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...
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.
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!!
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.
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
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:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
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:
Private Sub Timer1_Timer()
lblTime.Caption = Val(lblTime.Caption) - 1
If (Val(lblTime.Caption) = 0) Then
Timer1.Enabled = False
Load frmLost
frmLost.Show
End If
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.
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:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
If map(X + 1, Y) = 1 Then
X = X + 1
picSnail.Left = picSnail.Left + Picture1.Width
End If
ElseIf KeyCode = 37 Then
If map(X - 1, Y) = 1 Then
X = X - 1
picSnail.Left = picSnail.Left - Picture1.Width
End If
If map(X - 1, Y) = 2 Then
X = X - 1
picSnail.Left = picSnail.Left - Picture1.Width
Load frmWon
frmWon.Show
End If
ElseIf KeyCode = 38 Then
If map(X, Y - 1) = 1 Then
Y = Y - 1
picSnail.Top = picSnail.Top - Picture1.Height
End If
ElseIf KeyCode = 40 Then
If map(X, Y + 1) = 1 Then
Y = Y + 1
picSnail.Top = picSnail.Top + Picture1.Height
End If
End If
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.
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
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.