[4.1.5] 8 Directional Movement

User avatar
CutterCross
Posts: 402
Joined: Sat Apr 28, 2018 9:42 pm
Contact:

[4.1.5] 8 Directional Movement

Post by CutterCross » Thu Jun 20, 2019 6:29 pm

8 directional movement is actually really easy to set up. All of the movement code is already set up under the hood (which I'm assuming is left over from Mystic Searches). All you have to do is set up the StartMoving macro.

All of the movement arguments can be found in Constants.asm, starting on line 97:

Code: Select all

MOVE_RIGHT	= #%11000000
MOVE_LEFT 	= #%10000000
MOVE_DOWN	= #%00110000
MOVE_UP		= #%00100000
MOVE_RIGHT_DOWN = #%11110000
MOVE_LEFT_DOWN  = #%10110000
MOVE_RIGHT_UP	 = #%11100000
MOVE_LEFT_UP	 = #%10100000

STOP_RIGHT = #%01111111
STOP_LEFT = #%00111111
STOP_UP = #%11001111
STOP_DOWN = #%11011111
STOP_RIGHT_DOWN = #%01011111
STOP_LEFT_DOWN = #%00011111
STOP_RIGHT_UP = #%01001111
STOP_LEFT_UP = #%00001111
So for adding diagonal directions, just add and assign these scripts to the proper inputs.

Start Movement:

Code: Select all

;;;; Start moving Down+Right ;;;;
StartMoving player1_object, MOVE_RIGHT_DOWN
RTS

Code: Select all

;;;; Start moving Down+Left ;;;;
StartMoving player1_object, MOVE_LEFT_DOWN
RTS

Code: Select all

;;;; Start moving Up+Right ;;;;
StartMoving player1_object, MOVE_RIGHT_UP
RTS

Code: Select all

;;;; Start moving Up+Left ;;;;
StartMoving player1_object, MOVE_LEFT_UP
RTS
(You don't actually NEED these next scripts for stopping movement if you already set up your standard StopMoving scripts for Up, Down, Left, and Right, but I'll post them here anyway.)

Stop Movement:

Code: Select all

;;;; Stop moving Down+Right ;;;;
StopMoving player1_object, STOP_RIGHT_DOWN
RTS

Code: Select all

;;;; Stop moving Down+Left ;;;;
StopMoving player1_object, STOP_LEFT_DOWN
RTS

Code: Select all

;;;; Stop moving Up+Right ;;;;
StopMoving player1_object, STOP_RIGHT_UP
RTS

Code: Select all

;;;; Stop moving Up+Left ;;;;
StopMoving player1_object, STOP_LEFT_UP
RTS
So yeah, this is pretty simple. Makes me wonder why Joe never just gave us these scripts seeing as they're so easy to set up.

*EDIT: Accidently used "StartMoving" in the StopMoving diagonal scripts. Now they should all be correct.
Last edited by CutterCross on Sat Jul 13, 2019 2:14 pm, edited 1 time in total.
Music Man:
The Tower of Turmoil: http://www.nesmakers.com/viewtopic.php?f=12&t=1348
When the Clock Hands Stall: http://www.nesmakers.com/viewtopic.php?f=52&t=2723
User avatar
dale_coop
Posts: 4463
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: [4.1.5] 8 Directional Movement

Post by dale_coop » Thu Jun 20, 2019 6:36 pm

This IS very useful, CutterCross. Thanks for sharing that. I know some are very very interesting.
It should be part of NESmaker by default.

...we should make a Module with that (and more stuff fixed).
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
CutterCross
Posts: 402
Joined: Sat Apr 28, 2018 9:42 pm
Contact:

Re: [4.1.5] 8 Directional Movement

Post by CutterCross » Thu Jun 20, 2019 6:40 pm

dale_coop wrote:
Thu Jun 20, 2019 6:36 pm
This IS very useful, CutterCross. Thanks for sharing that. I know some are very very interesting.
It should be part of NESmaker by default.

...we should make a Module with that (and more stuff fixed).
I think once I finish up my Point and Click demo for WtCHS I'll start working on tutorials for my custom Point and Click and 3D Dungeon Crawler modules (and release them too, of course).
Music Man:
The Tower of Turmoil: http://www.nesmakers.com/viewtopic.php?f=12&t=1348
When the Clock Hands Stall: http://www.nesmakers.com/viewtopic.php?f=52&t=2723
Gilbertmaxter
Posts: 100
Joined: Tue Oct 16, 2018 3:04 am

Re: [4.1.5] 8 Directional Movement

Post by Gilbertmaxter » Thu Jun 20, 2019 6:49 pm

And bookmarked :)

Think this is how mugi did it ?
User avatar
crazygrouptrio
Posts: 68
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: [4.1.5] 8 Directional Movement

Post by crazygrouptrio » Mon Jun 24, 2019 11:00 pm

Awesome, thanks!
User avatar
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: [4.1.5] 8 Directional Movement

Post by Mugi » Tue Jun 25, 2019 8:58 am

Gilbertmaxter wrote:
Thu Jun 20, 2019 6:49 pm
And bookmarked :)

Think this is how mugi did it ?
?

im making a platformer, and it definitely doesnt have 8-directional movement anywhere :P
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
Gilbertmaxter
Posts: 100
Joined: Tue Oct 16, 2018 3:04 am

Re: [4.1.5] 8 Directional Movement

Post by Gilbertmaxter » Tue Jun 25, 2019 12:25 pm

For some reason i thought you making a top down as well. My mistake mugi thank you :)
User avatar
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: [4.1.5] 8 Directional Movement

Post by Mugi » Tue Jun 25, 2019 5:52 pm

i have 8 directional scrolling, not movement xD
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
Raftronaut
Posts: 307
Joined: Mon Sep 03, 2018 4:47 pm

Re: [4.1.5] 8 Directional Movement

Post by Raftronaut » Sun Aug 04, 2019 3:10 pm

I finally got around to getting this, took me a little longer as I was creating input commands for "PRESS" down+left etc instead of "HOLD" down+left. It's a rookie mistake on my part, but an important distinction in case anyone if having trouble with getting it working in the future.

Other than that, this was painless and works terrific! :)
Space Raft demo updates: [url]http://nesmakers.com/viewtopic.php?f=52&t=2867[/url]

Chiptune:[url] https://soundcloud.com/user-634230995-350638590 [/url]
User avatar
SciNEStist
Posts: 10
Joined: Sat Jun 08, 2019 3:31 pm

Re: [4.1.5] 8 Directional Movement

Post by SciNEStist » Wed Sep 18, 2019 3:27 am

Thank you for this info! I'm still learning and trying to work out how a lot of this tool works, but I was able to get my player to move all 8 directions with your help.

Everyone should also note that to get the player animations to work properly on the diagonal movement (the ones that you set in the player object details screen), you must also add FaceDirection. but it will only work slightly differently

this will NOT work currently:

Code: Select all

FaceDirection player1_object, LEFT_DOWN
but this will work:

Code: Select all

FaceDirection player1_object, #%00000111
the other problem I ran into is that my player character would glitch out if i changed direction while attacking rapidly. While this might be my fault, I was able to solve it by making it so on ALL player movement scripts, it skipped starting the movement and direction change if the player is attacking, so the attack has to finish before the player can move. While this might be a big issue for some gameplay, it suited my needs fine. here's an example of it all together:

Code: Select all

;;;; Start moving Down+Left ;;;;
    LDX player1_object
    GetCurrentActionType player1_object
    CMP #$02 ;; if the state is invincible
    BEQ ++ ; skip movement if attacking 
    CMP #$03
    BEQ ++ ;skip if we are casting spell
    CMP #$01
    BEQ + ;; if the action type already equals 1, jump forward
    ChangeObjectState #$01, #$04
+
;;;;;; Then, we will begin moving.
    StartMoving player1_object, MOVE_LEFT_DOWN
;;;;;; Lastly, we will change the facing direction.
    FaceDirection player1_object, #%00000111
++
    RTS
(notice how the "++" is moved after the startmoving and the facedirection parts)
Post Reply