Page 1 of 1

Pathfinding

Posted: Thu Jul 22, 2010 3:52 pm
by Lewis
Hello guys,
Well lately i have been trying to make an isometric game with pathfinding ( explained later in post ) but i have resorted to making the user click to move a tile.
gamepic.png
When the user clicks a tile ( highlighted red ) i want the box shape to make a rout from tile to tile, the fastest way, until it has reached the specified location, All help will be great, if you need any more info please put it bellow.

Lewis

current source:
Code: Select all
Public Class Form1

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        PictureBox1.Location = New Point(PictureBox1.Location.X - 28, PictureBox1.Location.Y + 14)
        PictureBox2.Location = New Point(PictureBox2.Location.X - 28, PictureBox2.Location.Y + 14)
        PictureBox3.Location = New Point(PictureBox3.Location.X - 28, PictureBox3.Location.Y + 14)
        PictureBox4.Location = New Point(PictureBox4.Location.X - 28, PictureBox4.Location.Y + 14)
        PictureBox5.Location = New Point(PictureBox5.Location.X - 28, PictureBox5.Location.Y + 14)
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        PictureBox1.Location = New Point(PictureBox1.Location.X + 28, PictureBox1.Location.Y - 14)
        PictureBox2.Location = New Point(PictureBox2.Location.X + 28, PictureBox2.Location.Y - 14)
        PictureBox3.Location = New Point(PictureBox3.Location.X + 28, PictureBox3.Location.Y - 14)
        PictureBox4.Location = New Point(PictureBox4.Location.X + 28, PictureBox4.Location.Y - 14)
        PictureBox5.Location = New Point(PictureBox5.Location.X + 28, PictureBox5.Location.Y - 14)
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        PictureBox1.Location = New Point(PictureBox1.Location.X + 28, PictureBox1.Location.Y + 14)
        PictureBox2.Location = New Point(PictureBox2.Location.X + 28, PictureBox2.Location.Y + 14)
        PictureBox3.Location = New Point(PictureBox3.Location.X + 28, PictureBox3.Location.Y + 14)
        PictureBox4.Location = New Point(PictureBox4.Location.X + 28, PictureBox4.Location.Y + 14)
        PictureBox5.Location = New Point(PictureBox5.Location.X + 28, PictureBox5.Location.Y + 14)
    End Sub

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        PictureBox1.Location = New Point(PictureBox1.Location.X - 28, PictureBox1.Location.Y - 14)
        PictureBox2.Location = New Point(PictureBox2.Location.X - 28, PictureBox2.Location.Y - 14)
        PictureBox3.Location = New Point(PictureBox3.Location.X - 28, PictureBox3.Location.Y - 14)
        PictureBox4.Location = New Point(PictureBox4.Location.X - 28, PictureBox4.Location.Y - 14)
        PictureBox5.Location = New Point(PictureBox5.Location.X - 28, PictureBox5.Location.Y - 14)
    End Sub
End Class

Re: Pathfinding

Posted: Thu Jul 22, 2010 4:24 pm
by mandai
Maybe you could move the shape with 2 for loops until it is where it needs to be?

Re: Pathfinding

Posted: Thu Jul 22, 2010 4:45 pm
by Lewis
Example code, I dont realy get it like that .

Re: Pathfinding

Posted: Thu Jul 22, 2010 7:43 pm
by lesan101
haha, looks like habbo hotel. lol

Re: Pathfinding

Posted: Thu Jul 22, 2010 7:51 pm
by Lewis
yeah well, i designed it, i diddnt rip.

Re: Pathfinding

Posted: Thu Jul 22, 2010 8:14 pm
by mandai
Code: Select all
        Dim xBlocks As Integer = 2
        Dim yBlocks As Integer = 3 'example to move right by 2 blocks, down by 3

        Dim blocksize As Integer = 28

        For x As Integer = 0 To xBlocks * blocksize Step blocksize
            PictureBox1.Left += x
        Next

        For y As Integer = 0 To yBlocks * blocksize Step blocksize
            PictureBox1.Top += y
        Next

Re: Pathfinding

Posted: Thu Jul 22, 2010 8:54 pm
by Lewis
Mandai that code diddnt work as it went off path and diddnt go on the tile correctly, Also i want it to like "animate" itself to each tile (slide)

Re: Pathfinding

Posted: Thu Jul 22, 2010 9:07 pm
by mandai
For animation you can add in delays and have the loop running inside a different thread like in a backgroundworker, you could also decrease the step amount in each loop.
You might have to adjust the blocksize to the amount needed for it to work in isometric bounds.

Edit: Sorry this isn't my area of expertise maybe someone else can help?

Re: Pathfinding

Posted: Fri Jul 23, 2010 5:36 pm
by Lewis
im having problems animating it ): Any help ?

Re: Pathfinding

Posted: Wed Jul 28, 2010 9:40 am
by Lewis
Bump 's head on the forum because I still need help.