Moving Character

Help with a moving character using Pictureboxes

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

36 Replies - 5303 Views - Last Post: 23 July 2010 - 03:30 AM Rate Topic: ***-- 2 Votes

#1 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Moving Character

Posted 19 July 2010 - 01:17 AM

HELP!!!
Moving code:
Ok, i need help with this. I think i got it figured out, but i cant really get it into code. So can u just look over this and see if u can help me out.
Dim Sqaure(69) As Picturebox
Dim Whereto As Integer
Dim Rockto As Integer
Dim charpos As Integer
Dim changer As Integer
Dim GrassNumber As Integer
Charpos = 13
Select Case UCase(Cstr(e.KeyChar))
	Case “W”
Whereto = charpos + 10
		If whereto.image = imlAllpictures.Image.Item(0) than ‘ if image = grass

Also, the line above doesn’t work for some reason, idk why, do u?
GrassNumber = Tag used
Where i need you help.. What i am trying to do is pull out the Tag of whereto and then from the tag get the location of the picturebox with the tag of whereto
Changer = picCharacter.location  ‘get location of character
picCharacter.location = Whereto.location ‘move character to new location
picGrass(GrassNumber) .location = Changer.location ‘Move grass to characters last position


So thats the basic outline of it..
Explain the bold to me PLEASE. THANK U FOR UR TIME...

This post has been edited by Saint_Kyle: 19 July 2010 - 01:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Moving Character

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 19 July 2010 - 02:01 AM

last time i check Dim Whereto As Integer integers dont have .image property If whereto.image = ... in all your code you give properties to integers:
picGrass(GrassNumber) .location = Changer.location -> Dim changer As Integer
picCharacter.location = Whereto.location -> Dim Whereto As Integer

now you maybe want to use the array of pictureboxes you made Dim Sqaure(69) As Picturebox ? am i right then change them to :
picCharacter.location = Sqaure(Whereto).location

i dont quite understand what you want to do
Was This Post Helpful? 1
  • +
  • -

#3 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 19 July 2010 - 02:07 AM

So "picCharacter.location = Sqaure(Whereto).location" should get the character to move around in the array of picture boxes?

Also, i know you aren't allowed to give me code, but how will i be able to pull out a tag from a picturebox, and from the tag get the location of the picturebox?

thanks for ur help mate
Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 19 July 2010 - 02:21 AM

so your using VB.NET (because VB6 dont have location property on pictureboxes) and yes this will move the picture box named picCharacter to the location where picture box Sqaure with index Whereto is.

EDIT: what you want to do is to move it around using the keys right ? then increase the index(whereto). make your array 2D (the chess 8x8 (64 picture boxes)) it will act like a x and y coordinates the "W" will increase the Y coordinates the "S" key will reduce the Y coordinates "A" reduce X coordinates and "D" increase X coordinates. for example if we have 64 grid of picture boxes made in 2D array move will be like so:
Dim Sqaure(7,7) As Picturebox 'from 0 to 7 (8 elements)'
Dim Xc As Integer
Dim Yc As Integer
        Select Case e.KeyChar.ToString
            Case Keys.W
                Yc = Yc + 1
            Case Keys.S
                Yc = Yc - 1
            Case Keys.A
                Xc = Xc - 1
            Case Keys.D
                Xc = Xc + 1
        End Select


then all you have to do is move your picture box of the char like this "picCharacter.location = Sqaure(Xc,Yc).location". well something like this. it is example. also make sure to check if the Xc and Yc dont go under 0

This post has been edited by NoBrain: 19 July 2010 - 02:40 AM

Was This Post Helpful? 1
  • +
  • -

#5 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 19 July 2010 - 02:48 AM

WoW, way more help then other people :P ty!!
Ok, just to explain to myself alittle more. (talk to myself outload, and u confirm if its right)

beacuse my array was 70 sqaures it will need to be 9,6 (because its 0 based)
and i wont need tags? because Yc = Yc + 1 will auto make it go up?

Idk, i am kinda new to the whole thing, and i need to do this assignment. It sucks cos the teacher is away, so NO help from him... lol
Was This Post Helpful? 0
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 19 July 2010 - 02:57 AM

yes 9,6 = 10,7 if you count the 0 so all you need to do is check if the Yc and Xc dont go outside the array bound ( lower then 0 and higher then 9 for X and 6 for Y)
Was This Post Helpful? 1
  • +
  • -

#7 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 19 July 2010 - 03:05 AM

ok, and with stopping when i hit a wall, its like this?
Dim playerYC As integer
Dim playerXC As integer
Dim RockYC As integer
Dim RockXC As integer

Case Keys.W  

  If picture box = wall than
      Playeryc = yc               'character stays still

  else if picture box = blank than
     PlayerYc = Yc + 1          'move character up 1
 
  else if picture box = rock than
    Playeryc = yc + 1           'move character up
    RockYc = Yc + 1             'move rock up



Right?
cos i had it planned the other way, and it didn't work, now i am lost :S
Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 19 July 2010 - 03:13 AM

yes.
Dim playerYC As integer
Dim playerXC As integer
Dim RockYC As integer
Dim RockXC As integer

Case Keys.W  

  if picture box = blank than
     PlayerYc = PlayerYc + 1          'move character up 1
 
  else if picture box = rock than

    Playeryc = PlayerYc + 1           'move character up
    RockYc = RockYc + 1             'move rock up
  end if



check only if they are black or have a rock. but if you move the rock check if the next square is empty

Attached File(s)

  • Attached File  pic1.bmp (126.9K)
    Number of downloads: 70

This post has been edited by NoBrain: 19 July 2010 - 03:20 AM

Was This Post Helpful? 1
  • +
  • -

#9 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 19 July 2010 - 03:25 AM

ok, well i dont have access to the VB.Net program at home, but i'll work on some code in Word. I'll post that some time tomorrow, and then i need u to check over it for me please. On Wensday i can get on VB and code the walking. (lets hope it'll work)

Thanks for ur help today, and i dont understand those pics LOL, but thanks for them too

cya tomoz
Was This Post Helpful? 0
  • +
  • -

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 19 July 2010 - 03:30 AM

well the pic is to show you that if your going to move the rock you need to check the square where the rock will be if it is empty(it is not a wall) so you can move it.
Was This Post Helpful? 1
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6037
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: Moving Character

Posted 19 July 2010 - 04:53 AM

Moved to VB.NET
Was This Post Helpful? 1
  • +
  • -

#12 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 21 July 2010 - 01:38 AM

Ok, so i tryed some new stuff today.(the stuff u had pretty much) and something happened that i didn't want. When it gets the value of positon X, And Y it keeps the position, which is what we want.. But when i try and move again it the same way it doesn't becaue position of each key is saved and it wont move on..

So here it the code for keypress W. (the other keys are the same code, just keypress "A","S","D")

Static Y As Integer
Static X As Integer
Static Rockto As Integer
Static RockY As Integer
Static RockX As Integer

CharPos = 13
Y = 2
X = 1

Select Case UCase(Cstr(e.Keychar))
Casw "W"
If picplayer.location = picdoor.location Then
messagebox.show("Great job, you have done the first level")
Else If Sqaure(X,Y).Tag = "Blank" Then
X=X+1
picPlayer.location = Sqaure(X,Y).Location
Else If Sqaure(X,Y).Tag = "Wall" Then
X=X
picPlayer.location = Sqaure(X,Y).Location
Else If Sqaure(X,Y).Tag = "Rock" Then
[color="#FF0000"]Will do this later when i get other stuff to work[/color]
End If 


So what is wrong with it? i thought it was fine.
Was This Post Helpful? 0
  • +
  • -

#13 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 21 July 2010 - 01:48 AM

Declare your X and Y variables outside of the Keypress event sub. because they are reseted every time you enter the sub.
Option Explicit
Private Y As Integer
Private X As Integer
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        'rest of your code'
    End Sub



if i understand correct your variables X and Y have the same values and that is why the picture box dont move am i right?
Was This Post Helpful? 1
  • +
  • -

#14 Saint_Kyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-July 10

Re: Moving Character

Posted 21 July 2010 - 01:52 AM

Ohh, really? I asked like 5 people at school today and no-one knew what was wrong.. Ok, so that will make the picature keep moving evertime i press it? ((Thanks))

Cant do that? because i also use X,Y to set up the array in Form.load?
Well, i can do it, just have to fix up my setup array. Do i have to do that?
Was This Post Helpful? 0
  • +
  • -

#15 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Moving Character

Posted 21 July 2010 - 01:59 AM

what do you mean by that?

well you see if you declare a variable in the sub(or function) the variable values will last for the sub only. if you want the variable values to increase every time she go in a sub you need to make the variable global. however i dont understand what you mean by using X and Y in form load. also you can rename the variables in form load to Xc and Yc so they dont conflict with the global one or to reset their values from the start point of your char :P
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3