Click to See Complete Forum and Search --> : Game moving
progeix
Apr 14th, 2000, 09:23 AM
I am making a game with maps.
These maps are icons that are 16x16.
Can anyone tell me how, when u click on the picturebox, it will move the Character to that place, but it will move it Square by sqaure till it gets there, and It will check for impassible objects along the way, if it hits, it will stop..
any one help?
Mc Brain
Apr 14th, 2000, 10:35 AM
You should have any info about the layout of your map. Either a matrix with 0 and 1 (where 0 means air, and 1 stands for something impassible) or get the info from your image. For example, if you load the image (icon) on your form, you could use the form1.point(X,Y) to get the colour of that point. This point should be a bit shifted towards the character's direction. E.G.: If your character is moving to the left, and X,Y is the position of your character, you should do form1.point(X-2,Y). Then you should analize, what does the color you get stands for.
Apollo
Apr 17th, 2000, 12:25 AM
Alright.
You can easily do this using an array. They're very simple, but you have to fill them manually. I'm going to go into this like you know nothing about VB, sorry.
Dim map(1 to 10, 1 to 10) as boolean 'Boolean is true or false
This makes a 'matrix' with two dimensions, 10 across and 10 down.
Ok. The default value for boolean is false, so since you'll probably want more free squares, you'll want to set the impassable squares to true (less work). Like this:
map(5,9) = true 'That will set the coordinate 5, 9 to true
map(5,10) = true
etc...
Now. Start the person in the top left corner. Which would contain a false value. I will let you decide upon the method used to create the graphical interface. But, when the user clicks on a square, get it's coordinates.
Now you take your current coordinates, and use a timer, because you'll probably want the user to be able to see his person move. For loops are too fast.
You need four variables, you need to store your current x and y value, and your destination x and y value.
Make a comparison to see if the destination x is lower, or higher than the current x, and do the same for the y as well.
Private Sub timer1_timer()
make sure you're not already at the destination point
In here add or subtract current values accordingly, and see if the area is open to move into inside your array. If it is, then move your character's graphic to the new graphic location on the map,
end sub
[/code]
If you have any questions, get AIM and contact me, I want to help my IM is: Anselmaster.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.