Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Elysium Source Forum Index » Approved Tutorials

Post new topic   Reply to topic
Diagonal Movement Goto page 1, 2, 3, 4, 5  Next
View previous topic :: View next topic  
Author Message
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Sun May 28, 2006 2:19 pm    Post subject: Diagonal Movement Reply with quote

Diagonal Movement
Made by pingu

That's right, suck it bitches. I spent most of today getting it to work, but I think I spent more time writing the actual text below than I spent coding.

I suggest you do this if you know how to code, because I might of missed a few simple things. I'd test it on a blank copy, but it's too long for me right now. I already spent enough of my time. However, if others seem to have it working, you should then try it.

Please, post any errors you may get while doing this tutorial.

Keep this tutorial on ES.

Tutorial Difficulty: 5/5
Concept Difficulty: 2/5

All Client Side

------

Find:
Code:
    MaxSP As Long
    XOffset As Integer
    YOffset As Integer
    Moving As Byte


Replace With:
Code:
    MaxSP As Long
    XOffset As Integer
    YOffset As Integer
    MovingH As Integer
    MovingV As Integer


------

Find:
Code:
Sub ProcessMovement


Replace With:
Code:
Sub ProcessMovement(ByVal Index As Long)
    If GetPlayerAccess(Index) > 0 Then
        If Player(Index).MovingV <> 0 Then Player(Index).YOffset = Player(Index).YOffset +

(GM_WALK_SPEED * Player(Index).MovingV)
        If Player(Index).MovingH <> 0 Then Player(Index).XOffset = Player(Index).XOffset +

(GM_WALK_SPEED * Player(Index).MovingH)
    Else
        If Player(Index).MovingV <> 0 Then Player(Index).YOffset = Player(Index).YOffset +

(WALK_SPEED * Player(Index).MovingV)
        If Player(Index).MovingH <> 0 Then Player(Index).XOffset = Player(Index).XOffset +

(WALK_SPEED * Player(Index).MovingH)
    End If
   
    ' Check if completed walking over to the next tile
    If Player(Index).XOffset = 0 Then
        Player(Index).MovingH = 0
    End If
    If Player(Index).YOffset = 0 Then
        Player(Index).MovingV = 0
    End If
End Sub


------

Find:
Code:
Sub CheckInput


Replace Whole Sub With:
Code:
Sub CheckInput(ByVal KeyState As Byte, ByVal KeyCode As Integer, ByVal Shift As Integer)
    If GettingMap = False Then
        If KeyState = 1 Then
            If KeyCode = vbKeyReturn Then
                Call CheckMapGetItem
            End If
            If KeyCode = vbKeyControl Then
                ControlDown = True
            End If
            If KeyCode = vbKeyUp Then
                DirUp = True
                DirDown = False
            End If
            If KeyCode = vbKeyDown Then
                DirUp = False
                DirDown = True
            End If
            If KeyCode = vbKeyLeft Then
                DirLeft = True
                DirRight = False
            End If
            If KeyCode = vbKeyRight Then
                DirLeft = False
                DirRight = True
            End If
            If KeyCode = vbKeyShift Then
                ShiftDown = True
            End If
        Else
            If KeyCode = vbKeyUp Then
                DirUp = False
                DirDown = False
            End If
            If KeyCode = vbKeyDown Then
                DirUp = False
                DirDown = False
            End If
            If KeyCode = vbKeyLeft Then
                DirRight = False
                DirLeft = False
            End If
            If KeyCode = vbKeyRight Then
                DirRight = False
                DirLeft = False
            End If
            If KeyCode = vbKeyShift Then ShiftDown = False
            If KeyCode = vbKeyControl Then ControlDown = False
        End If
    End If
End Sub


------

Find:
Code:
    ' Make sure they aren't trying to move when they are already moving
    If Player(MyIndex).Moving <> 0 Then
        CanMove = False
        Exit Function
    End If


Replace With:
Code:
    ' Make sure they aren't trying to move when they are already moving
    If Player(MyIndex).MovingH <> 0 And Player(MyIndex).MovingV <> 0 Then
        CanMove = False
        Exit Function
    End If


------

Find:
Code:
    If DirUp Then


Under, Add:
Code:
        If Player(MyIndex).MovingV <> 0 Then
            CanMove = False
            Exit Function
        End If


------

Find:
Code:
        Else
            ' Check if they can warp to a new map
            If Map(GetPlayerMap(MyIndex)).Up > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If


Under, Add:
Code:
        Exit Function


------

Find:
Code:
    If DirDown Then


Under, Add:

Code:
        If Player(MyIndex).MovingV <> 0 Then
            CanMove = False
            Exit Function
        End If


------

Find:
Code:
        Else
            ' Check if they can warp to a new map
            If Map(GetPlayerMap(MyIndex)).Down > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If


Under, Add:
Code:
        Exit Function


------

Find:
Code:
    If DirLeft Then


Under, Add:
Code:
        If Player(MyIndex).MovingH <> 0 Then
            CanMove = False
            Exit Function
        End If


------

Find:
Code:
        Else
            ' Check if they can warp to a new map
            If Map(GetPlayerMap(MyIndex)).Left > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If


Under, Add:
Code:
        Exit Function


------

Find:
Code:
    If DirRight Then


Under, Add:
Code:
        If Player(MyIndex).MovingH <> 0 Then
            CanMove = False
            Exit Function
        End If


------

Find:
Code:
        Else
            ' Check if they can warp to a new map
            If Map(GetPlayerMap(MyIndex)).Right > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If


Under, Add:
Code:
        Exit Function


------

Find:
Code:
    If (Parse(0) = "playermove") Then


Replace the whole if statement with:
Code:
    If (Parse(0) = "playermove") Then
        I = Val(Parse(1))
        x = Val(Parse(2))
        y = Val(Parse(3))
        Direction = Val(Parse(4))
        n = Val(Parse(5))

        If Direction < DIR_UP Or Direction > DIR_RIGHT Then Exit Sub

        Call SetPlayerX(I, x)
        Call SetPlayerY(I, y)
        Call SetPlayerDir(I, Direction)
       
        Select Case GetPlayerDir(I)
            Case DIR_UP
                Player(I).YOffset = PIC_Y
                Player(I).MovingV = -n
            Case DIR_DOWN
                Player(I).YOffset = PIC_Y * -1
                Player(I).MovingV = n
            Case DIR_LEFT
                Player(I).XOffset = PIC_X
                Player(I).MovingH = -n
            Case DIR_RIGHT
                Player(I).XOffset = PIC_X * -1
                Player(I).MovingH = n
        End Select
        Exit Sub
    End If


------

Find:
Code:
Sub SendPlayerMove()


Replace Whole Sub With:
Code:
Sub SendPlayerMove()
Dim Packet As String
    If GetPlayerDir(MyIndex) = DIR_LEFT Or GetPlayerDir(MyIndex) = DIR_RIGHT Then
        Packet = "playermove" & SEP_CHAR & GetPlayerDir(MyIndex) & SEP_CHAR &

Abs(Player(MyIndex).MovingH) & SEP_CHAR & END_CHAR
    Else
        Packet = "playermove" & SEP_CHAR & GetPlayerDir(MyIndex) & SEP_CHAR &

Abs(Player(MyIndex).MovingV) & SEP_CHAR & END_CHAR
    End If
    Call SendData(Packet)
End Sub


------

Find (there are two, do both):
Code:
If Player(MyIndex).Moving = 0 Then


Replace With:
Code:
If Player(MyIndex).MovingH = 0 And Player(MyIndex).MovingV = 0 Then


------

Find:
Code:
If Player(MyIndex).Moving = NO Then


Replace With:
Code:
If Player(MyIndex).MovingH = NO And Player(MyIndex).MovingV = NO Then


------

Find:
Code:
    Player(Index).YOffset = 0
    Player(Index).Moving = 0


Replace With:
Code:
    Player(Index).YOffset = 0
    Player(Index).MovingH = 0
    Player(Index).MovingV = 0


------

Find:
Code:
' Speed moving vars
Public Const WALK_SPEED = 4
Public Const RUN_SPEED = 8
Public Const GM_WALK_SPEED = 4
Public Const GM_RUN_SPEED = 8
'Set the variable to your desire,
'32 is a safe and recommended setting


Replace With:
Code:
' Speed moving vars
Public Const WALK_SPEED = 4
Public Const GM_WALK_SPEED = 4


------

Find (there are two, do both):
Code:
GetPlayerDir(Index) = DIR_DOWN And Player(Index).Moving > 0


Replace With:
Code:
GetPlayerDir(Index) = DIR_DOWN And Player(Index).MovingV <> 0


------

Find (make sure you do the step above first) (there are four of these, do all):
Code:
Player(Index).Moving > 0


Replace With:
Code:
Player(Index).MovingH <> 0


------

(fix some error I found, unrelated)
Find:
Code:
        ' Make sure they aren't walking
        Player(I).Moving = 0
        Player(I).XOffset = 0
        Player(I).YOffset = 0
       
        ' Make sure their pet isn't walking
        Player(I).Pet.Moving = 0
        Player(I).Pet.XOffset = 0
        Player(I).Pet.YOffset = 0


Replace With:
Code:
        ' Make sure their pet isn't walking
        Player(I).Pet.Moving = 0
        Player(I).Pet.XOffset = 0
        Player(I).Pet.YOffset = 0


------

Find (there are a few, make sure you do the above first):
Code:
Player(I).Moving = 0


Replace With:
Code:
Player(I).MovingH = 0
Player(I).MovingV = 0


------

Find:
Code:
Sub CheckMovement


Replace whole sub with:
Code:
Sub CheckMovement()
    If GettingMap = False Then
        If IsTryingToMove Then
            If CanMove Then
                Select Case GetPlayerDir(MyIndex)
                    Case DIR_UP
                        If ShiftDown Then
                            Player(MyIndex).MovingV = -MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingV = -MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).YOffset = PIC_Y
                        Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) - 1)
               
                    Case DIR_DOWN
                        If ShiftDown Then
                            Player(MyIndex).MovingV = MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingV = MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).YOffset = PIC_Y * -1
                        Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) + 1)
               
                    Case DIR_LEFT
                        If ShiftDown Then
                            Player(MyIndex).MovingH = -MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingH = -MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).XOffset = PIC_X
                        Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) - 1)
               
                    Case DIR_RIGHT
                        If ShiftDown Then
                            Player(MyIndex).MovingH = MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingH = MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).XOffset = PIC_X * -1
                        Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) + 1)
                End Select
           
                ' Gotta check :)
                If Map(GetPlayerMap(MyIndex)).Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_WARP Then
                    GettingMap = True
                End If
            End If
        End If
    End If
End Sub


Did I win yet?
_________________


Last edited by pingu on Wed May 31, 2006 7:31 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
DELTA
Jr. Member


Joined: 30 Apr 2006
Posts: 60

Points

PostPosted: Sun May 28, 2006 4:14 pm    Post subject: Reply with quote

screenies?I cant add this in because I dont have vb so can you show us a screenie?
_________________

[url=http://splamm.com/elysium/forums/viewtopic.php?t=3233]
[/url]
Back to top
View user's profile Send private message MSN Messenger
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Sun May 28, 2006 4:40 pm    Post subject: Reply with quote

It allows you to move up/down and left/right at the same time. You kind of curve around when walking and it makes it more realistic. Instead of just walking one tile forward in one direction, you can walk a tile forward in one direction and a tile forward in another direction. You don't need to do both at once, so it creates a cool effect.

Somebody tell me if you get it working. It's huge, so I might have messed up.
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Damien
Sr. Member


Joined: 24 Feb 2006
Posts: 673

Points

PostPosted: Sun May 28, 2006 4:43 pm    Post subject: Reply with quote

Let me break it down what pingu is trying to say... You ever seen the matrix? It’s like creating all your characters into lil neos... all his super shifty moves rolled into 1! Very Happy aww I had to say that... I am joking kidos!
Back to top
View user's profile Send private message
BeNjO
Sr. Member


Joined: 28 May 2006
Posts: 418
Location: York
Points

PostPosted: Mon May 29, 2006 5:06 pm    Post subject: Reply with quote

hmm i followd your Very long tut and as i got to over half way i couldnt find 2 parts i had to replace ( sorry i forgot wich ) so overall the code didnt work and it just kept on giving my code errors about moving. might need to recheck it pingu Sad

Ben
_________________
Back to top
View user's profile Send private message Send e-mail MSN Messenger
mateo
Newcomer


Joined: 09 Apr 2006
Posts: 16
Location: london
Points

PostPosted: Mon May 29, 2006 5:15 pm    Post subject: Reply with quote

Quote:
Find (make sure you do the step above first) (there are four of these, do all):
Code:
Player(Index).Moving > 0


I cant find this !!!
_________________

Cilck
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Mon May 29, 2006 5:19 pm    Post subject: Reply with quote

There are two in the BltPlayer sub and there are two in the BltPlayerTop sub.

Look for the part that has "DIR_LEFT" or "DIR_RIGHT" as part of the if statement.
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
mateo
Newcomer


Joined: 09 Apr 2006
Posts: 16
Location: london
Points

PostPosted: Tue May 30, 2006 5:29 am    Post subject: Reply with quote

OK i found them and added everything on the top and i tryed to fix the errors below to make it work. tell me if i fixed them right and hwo to fix the last error.



[Edit] I think there needs to be some server side codeing[/edit]
_________________

Cilck
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Tue May 30, 2006 2:18 pm    Post subject: Reply with quote

For the first problem...

Find (there are a few, make sure you do the above first):
Code:
Player(I).Moving = 0


Replace With:
Code:
Player(I).MovingH = 0
Player(I).MovingV = 0


You just didn't read properly.

For the second problem, I forgot to post the code for that sub. I'll post it when I can (soon).
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
William
Member


Joined: 23 Feb 2006
Posts: 198

Points

PostPosted: Tue May 30, 2006 2:51 pm    Post subject: Reply with quote

Wow, very nice Pingu, I was struggeling with this some weeks back. And I just got this massive errors because you could walk out of the screens and such =/.

But thanks, this is very usefull Smile
_________________

Phoenix Engine: www.key2heaven.net/phoenix
pingu wrote:
I kind of suggest you make sure it works for Diamond before throwing it out there for all types of noobs to mess up their programs with.
Back to top
View user's profile Send private message
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Wed May 31, 2006 7:30 am    Post subject: Reply with quote

Thing I forgot to add.

Find:
Code:
Sub CheckMovement


Replace whole sub with:
Code:
Sub CheckMovement()
    If GettingMap = False Then
        If IsTryingToMove Then
            If CanMove Then
                Select Case GetPlayerDir(MyIndex)
                    Case DIR_UP
                        If ShiftDown Then
                            Player(MyIndex).MovingV = -MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingV = -MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).YOffset = PIC_Y
                        Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) - 1)
               
                    Case DIR_DOWN
                        If ShiftDown Then
                            Player(MyIndex).MovingV = MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingV = MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).YOffset = PIC_Y * -1
                        Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) + 1)
               
                    Case DIR_LEFT
                        If ShiftDown Then
                            Player(MyIndex).MovingH = -MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingH = -MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).XOffset = PIC_X
                        Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) - 1)
               
                    Case DIR_RIGHT
                        If ShiftDown Then
                            Player(MyIndex).MovingH = MOVING_RUNNING
                        Else
                            Player(MyIndex).MovingH = MOVING_WALKING
                        End If
                        Call SendPlayerMove
                        Player(MyIndex).XOffset = PIC_X * -1
                        Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) + 1)
                End Select
           
                ' Gotta check :)
                If Map(GetPlayerMap(MyIndex)).Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_WARP Then
                    GettingMap = True
                End If
            End If
        End If
    End If
End Sub

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
William
Member


Joined: 23 Feb 2006
Posts: 198

Points

PostPosted: Wed May 31, 2006 8:26 am    Post subject: Reply with quote

I havnt checked the code somuch yet, but it should work fine for a MS source with some modifications?
_________________

Phoenix Engine: www.key2heaven.net/phoenix
pingu wrote:
I kind of suggest you make sure it works for Diamond before throwing it out there for all types of noobs to mess up their programs with.
Back to top
View user's profile Send private message
pingu
"The Bird"


Joined: 23 Feb 2006
Posts: 3400
Location: Antartica
Points

PostPosted: Wed May 31, 2006 8:28 am    Post subject: Reply with quote

You'll have to skip a bunch of steps and edit it to work with MS.
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
William
Member


Joined: 23 Feb 2006
Posts: 198

Points

PostPosted: Wed May 31, 2006 9:23 am    Post subject: Reply with quote

Okay, cant be that hard thought. Thanks Smile
_________________

Phoenix Engine: www.key2heaven.net/phoenix
pingu wrote:
I kind of suggest you make sure it works for Diamond before throwing it out there for all types of noobs to mess up their programs with.
Back to top
View user's profile Send private message
BeNjO
Sr. Member


Joined: 28 May 2006
Posts: 418
Location: York
Points

PostPosted: Wed May 31, 2006 7:24 pm    Post subject: Reply with quote

hey iv done the code into my source, and it says "Run Time Error 6" "Over Flow"

i click Debug and it high lights

Code:
Sub SetPlayerY(ByVal Index As Long, ByVal y As Long)
    Player(Index).y = y   <-- this part
End Sub


the game actually loads but when i try and move any drection it says overflow, any ideas?

Ben
_________________
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Elysium Source Forum Index » Approved Tutorials All times are GMT - 5 Hours
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional