Mirage Source
http://www.miragesource.net/forums/

[Feature] Run & Walk speed values.
http://www.miragesource.net/forums/viewtopic.php?f=183&t=5737
Page 1 of 51

Author:  Robin [ Wed Jun 03, 2009 12:46 pm ]
Post subject:  [Feature] Run & Walk speed values.

This replaces the current Processmovement subroutines to have an extra "catch-all" code to make sure people don't wonder off a tile completely, which is what causes the flight effect where sprites start running off-screen.

It's copy and paste, I can't be arsed with decent formatting, so here you go.

Processmovement:

Code:
    Select Case GetPlayerDir(Index)
        Case DIR_UP
            Player(Index).YOffset = Player(Index).YOffset - MovementSpeed
            If Player(Index).YOffset <= 0 Then Player(Index).YOffset = 0
        Case DIR_DOWN
            Player(Index).YOffset = Player(Index).YOffset + MovementSpeed
            If Player(Index).YOffset >= 0 Then Player(Index).YOffset = 0
        Case DIR_LEFT
            Player(Index).XOffset = Player(Index).XOffset - MovementSpeed
            If Player(Index).XOffset <= 0 Then Player(Index).XOffset = 0
        Case DIR_RIGHT
            Player(Index).XOffset = Player(Index).XOffset + MovementSpeed
            If Player(Index).XOffset >= 0 Then Player(Index).XOffset = 0
    End Select


Processnpcmovement:

Code:
        Select Case MapNpc(MapNpcNum).Dir
            Case DIR_UP
                MapNpc(MapNpcNum).YOffset = MapNpc(MapNpcNum).YOffset - WALK_SPEED
                If MapNpc(MapNpcNum).YOffset <= 0 Then MapNpc(MapNpcNum).YOffset = 0
            Case DIR_DOWN
                MapNpc(MapNpcNum).YOffset = MapNpc(MapNpcNum).YOffset + WALK_SPEED
                If MapNpc(MapNpcNum).YOffset >= 0 Then MapNpc(MapNpcNum).YOffset = 0
            Case DIR_LEFT
                MapNpc(MapNpcNum).XOffset = MapNpc(MapNpcNum).XOffset - WALK_SPEED
                If MapNpc(MapNpcNum).XOffset <= 0 Then MapNpc(MapNpcNum).XOffset = 0
            Case DIR_RIGHT
                MapNpc(MapNpcNum).XOffset = MapNpc(MapNpcNum).XOffset + WALK_SPEED
                If MapNpc(MapNpcNum).XOffset >= 0 Then MapNpc(MapNpcNum).XOffset = 0
        End Select


Enjoy.

Author:  DarkPhoenix [ Wed Jun 03, 2009 5:59 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

don't fully understand.

Author:  Robin [ Wed Jun 03, 2009 7:13 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

DarkPhoenix wrote:
don't fully understand.


Then ignore it.

Author:  DarkPhoenix [ Wed Jun 03, 2009 9:02 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

I mean I don't understand the flight effect and the sprites walking off the tile/screen? How would this code affect that?

Author:  Matt [ Wed Jun 03, 2009 9:09 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

DarkPhoenix wrote:
I mean I don't understand the flight effect and the sprites walking off the tile/screen? How would this code affect that?


Simple.

It makes it NOT happen.

Author:  DarkPhoenix [ Wed Jun 03, 2009 11:40 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

So it already happens without this code.... that's weird.

Author:  Robin [ Thu Jun 04, 2009 12:42 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

DarkPhoenix wrote:
So it already happens without this code.... that's weird.


No, it's not.

The reason the speeds can only be 1, 2, 4, 8, 16 or 32 is because the movement is pretty much just taking the speed value away from 32 until it reaches 0, or adding it to -32, depending on which direction you're going.

Of course, if the number isn't a factor of 32, it wont reach 0 exactly, which causes it to never stop walking. This code simply makes sure that a number can never go over the maximum or under the minimum values.

Author:  DarkPhoenix [ Thu Jun 04, 2009 12:53 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

wait... there is more than two speed values that are usable? O_o

Author:  Robin [ Thu Jun 04, 2009 1:27 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

DarkPhoenix wrote:
wait... there is more than two speed values that are usable? O_o


What?

In the default source, RUN_SPEED and WALK_SPEED are 8 and 4 respectively. Anything apart from those two numbers, generally will fuck up. This tutorial allows those values to be ANY number.

Author:  DarkPhoenix [ Thu Jun 04, 2009 2:30 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

so you can add more when you add this code, if I understand what you are saying.

Author:  Matt [ Thu Jun 04, 2009 3:51 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

DarkPhoenix wrote:
so you can add more when you add this code, if I understand what you are saying.


This code would allow, say, higher speed for your character to make you move slightly faster than other players. Or for speed buffs and what not. So, if you have 4 walk speed by default and you have you get +1 from a buff or item, you'd have a walk speed of 5, allowing you to walk just a tad faster.

However, with the default code, if you had 5 walking speed, you'd just glide off the screen and never stop moving. That's the problem. That's what this code fixes.

Awesome tut, Robin. Very useful.

Author:  Doomy [ Thu Jun 04, 2009 4:59 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

on the old way it could be only 4 8 16 or 32
or else it will glide off
with this it can be any number

Author:  DarkPhoenix [ Thu Jun 04, 2009 5:04 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

sweet I'm so using this.

Author:  Dragoons Master [ Thu Jun 04, 2009 11:50 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

Very nice tut. I'll try to make it work with my server-side canmove sub xD
Client side deciding the speed is just way too much insecure =/

Author:  Drwe [ Sun Jun 14, 2009 6:27 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

Very good script there, and it looks as if you kept it very compact and with no trash script involved. Gotta give you some nice props for this one!

Author:  Nean [ Sun Jun 14, 2009 7:14 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

Dragoons Master wrote:
Very nice tut. I'll try to make it work with my server-side canmove sub xD
Client side deciding the speed is just way too much insecure =/


Pfft, you and your security.

Also wouldn't adding it server side cause more lag? After all it's not like you want to add a heavier load to the server when the client can do it, right?

Author:  GIAKEN [ Sun Jun 14, 2009 10:13 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

No, Nean...no.

Author:  Robin [ Sun Jun 14, 2009 11:40 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

The client-side CanMove stuff is all there to counter-act the packet delay. It's not nice pressing "up" and only moving a second or so later.

It's decent enough theory, but not programmed very well. Handling speed and movement server side is fine, but having it all handled client side for a player's own character only is perfect. As long as you do some checks to make sure it's not out of sync, which is a common problem in all Mirage-based engines/games.

It's an easy fix, just like this was. I might post a tutorial to fix it, eventually.

Author:  Toast [ Mon Jun 15, 2009 4:21 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

Can you fix that lag where other people's movements are a bit laggy? Or is just something I'm going to have to live with?

Author:  Robin [ Mon Jun 15, 2009 11:50 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

I haven't really seen anything to show whether that's a programming error. I've noticed lag where people host the servers themselves, but when I was hosting my own game on a VPS, there was no movement lag at all.

Author:  Toast [ Mon Jun 15, 2009 1:58 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

Meh, it's probably just my internet then. :(

Author:  Beres [ Mon Jun 15, 2009 2:06 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

I see the same stuff. Its quite annoying sometimes.

Author:  GIAKEN [ Mon Jun 15, 2009 4:50 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

It has to do with your ping. You could receive data every 200 milliseconds or 20 milliseconds or even 1000+ milliseconds (which means 1 second of delay).

When the player moves you will receive their location every however many ping. They can move faster than your ping (unless you're under 32 or something probably) and when you catch up with the server they will jump from where you currently see them to where they actually are...which is what we call lag.

Author:  Beres [ Mon Jun 15, 2009 9:49 pm ]
Post subject:  Re: [Feature] Run & Walk speed values.

I wouldnt expect to really lag on a 2D DX7 game. Idk though. :?

Author:  Tony [ Tue Jun 16, 2009 6:54 am ]
Post subject:  Re: [Feature] Run & Walk speed values.

Beres wrote:
I wouldnt expect to really lag on a 2D DX7 game. Idk though. :?


It really all depends. I get alot of clientside lag. I hate playing games that uses DX7 though. DX8 is already outdated..

Page 1 of 51 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/