Mirage Engine
[Feature] Run & Walk speed values. - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13)
+------ Thread: [Feature] Run & Walk speed values. (/showthread.php?tid=2837)

Pages: 1 2


[Feature] Run & Walk speed values. - Robin - 03-06-2009

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_LEFT
            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_LEFT
                MapNpc(MapNpcNum).XOffset = MapNpc(MapNpcNum).XOffset - WALK_SPEED
                If MapNpc(MapNpcNum).XOffset = 0 Then MapNpc(MapNpcNum).XOffset = 0
        End Select

Enjoy.


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 03-06-2009

don't fully understand.


Re: [Feature] Run & Walk speed values. - Robin - 03-06-2009

DarkPhoenix Wrote:don't fully understand.

Then ignore it.


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 03-06-2009

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


Re: [Feature] Run & Walk speed values. - Matt - 03-06-2009

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.


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 03-06-2009

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


Re: [Feature] Run & Walk speed values. - Robin - 04-06-2009

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.


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 04-06-2009

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


Re: [Feature] Run & Walk speed values. - Robin - 04-06-2009

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.


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 04-06-2009

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


Re: [Feature] Run & Walk speed values. - Matt - 04-06-2009

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.


Re: [Feature] Run & Walk speed values. - Doomy - 04-06-2009

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


Re: [Feature] Run & Walk speed values. - DarkPhoenix - 04-06-2009

sweet I'm so using this.


Re: [Feature] Run & Walk speed values. - Dragoons Master - 04-06-2009

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 =/


Re: [Feature] Run & Walk speed values. - Drwe - 14-06-2009

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!


Re: [Feature] Run & Walk speed values. - Nean - 14-06-2009

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?


Re: [Feature] Run & Walk speed values. - GIAKEN - 14-06-2009

No, Nean...no.


Re: [Feature] Run & Walk speed values. - Robin - 14-06-2009

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.


Re: [Feature] Run & Walk speed values. - Toast - 15-06-2009

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?


Re: [Feature] Run & Walk speed values. - Robin - 15-06-2009

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.


Re: [Feature] Run & Walk speed values. - Toast - 15-06-2009

Meh, it's probably just my internet then. Sad


Re: [Feature] Run & Walk speed values. - Beres - 15-06-2009

I see the same stuff. Its quite annoying sometimes.


Re: [Feature] Run & Walk speed values. - GIAKEN - 15-06-2009

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.


Re: [Feature] Run & Walk speed values. - Beres - 15-06-2009

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


Re: [Feature] Run & Walk speed values. - Tony - 16-06-2009

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..