[4.1.5] 8 Directional Movement

CutterCross

Active member
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:
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:
;;;; Start moving Down+Right ;;;;
StartMoving player1_object, MOVE_RIGHT_DOWN
RTS
Code:
;;;; Start moving Down+Left ;;;;
StartMoving player1_object, MOVE_LEFT_DOWN
RTS
Code:
;;;; Start moving Up+Right ;;;;
StartMoving player1_object, MOVE_RIGHT_UP
RTS
Code:
;;;; 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:
;;;; Stop moving Down+Right ;;;;
StopMoving player1_object, STOP_RIGHT_DOWN
RTS
Code:
;;;; Stop moving Down+Left ;;;;
StopMoving player1_object, STOP_LEFT_DOWN
RTS
Code:
;;;; Stop moving Up+Right ;;;;
StopMoving player1_object, STOP_RIGHT_UP
RTS
Code:
;;;; 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.
 

dale_coop

Moderator
Staff member
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).
 

CutterCross

Active member
dale_coop said:
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).
 

Raftronaut

Member
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! :)
 

SciNEStist

Well-known member
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:
FaceDirection player1_object, LEFT_DOWN

but this will work:
Code:
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:
;;;; 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)
 

dale_coop

Moderator
Staff member
Code:
	;FACE_DOWN      = #%00000000
	;FACE_DOWN_RIGHT = #%00000001
	;FACE_RIGHT	= #%00000010
	;FACE_UP_RIGHT	= #%00000011
	;FACE_UP	= #%00000100
	;FACE_UP_LEFT	= #%00000101
	;FACE_LEFT	= #%00000110
	;FACE_DOWN_LEFT	= #%00000111
 

SciNEStist

Well-known member
The issue I'm having now is that with 8 directional movement you get stuck on tile collisions. for example, if you are going diagonally up and right and there is a wall blocking you from moving further right, it also stops you from moving up. you should be able to slide along the wall.

The only solution I can think of for that is doing horizontal and vertical collision separately. I wouldn't know where to begin with that.
 

Saulus_Lira

Member
Very good. I have already entered the codes and it is working.
I'm only having a problem with the character's face direction when I go up or down (without the diagonals).
Since I don't know anything about assembly programming, I can't condition the face direction.
For example: if I am facing right and pressing up, my animation will continue to the right, however, if my character is facing left and putting up, my animation will continue to the right.
How can I change this?
 

dale_coop

Moderator
Staff member
In your project, your facing up doesn't use a UP animation?
Maybe, you're just using LEFT and RIGHT facing animations?
when left -> left animation
when right -> right animation
when up or down -> left or right animation depending of the previous facing?


In that situation, you need to store the current facing, first (left or right)
then instead of do a facing direction UP, you will just use the one you store previously...

Code (to be place at the beginning of the start moving up/down scripts), to store the current facing:
Code:
 	LDA Object_movement,x
	AND #%00000111
	CMP #%00000100
	BCS +
	LDA #FACE_RIGHT
	STA temp2
	JMP ++
	+
	LDA #FACE_LEFT
	STA temp2
	++

At the end, instead of the current:
Code:
	FaceDirection player1_object, FACE_UP
Replace with:
Code:
	FaceDirection player1_object, temp2


EDITED: replace "Object_direction" (code for the 4.5 version) by "Object_movement" (code for the 4.1.5 version)
 

Saulus_Lira

Member
dale_coop said:
In your project, your facing up doesn't use a UP animation?
Maybe, you're just using LEFT and RIGHT facing animations?
when left -> left animation
when right -> right animation
when up or down -> left or right animation depending of the previous facing?


In that situation, you need to store the current facing, first (left or right)
then instead of do a facing direction UP, you will just use the one you store previously...

Code (to be place at the beginning of the start moving up/down scripts), to store the current facing:
Code:
 	LDA Object_direction,x
	AND #%00000111
	CMP #%00000100
	BCS +
	LDA #FACE_RIGHT
	STA temp2
	JMP ++
	+
	LDA #FACE_LEFT
	STA temp2
	++

At the end, instead of the current:
Code:
	FaceDirection player1_object, FACE_UP
Replace with:
Code:
	FaceDirection player1_object, temp2

Not Working. I just put the code on the start of script, and replace the last (face direction object), and it crashes on the line 5 (LDA Object_direction,x) when compile the rom.
In UP/DOWN, i just use default animations.

My Code:
;;;;; START MOVING PLAYER UP:
;;;;; We will use this when the up button is pressed.
;;;;; If we are already showing the walking animation, which is for this module
;;;;; action step 1, we will skip changing to the walking state.
LDA Object_direction,x
AND #%00000111
CMP #%00000100
BCS +
LDA #FACE_RIGHT
STA temp2
JMP ++
+
LDA #FACE_LEFT
STA temp2
++
LDX player1_object
GetCurrentActionType player1_object
CMP #$02 ;; if the state is attacking
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_UP
++
;;;;;; Lastly, we will change the facing direction.
FaceDirection player1_object, temp2
RTS
 

dale_coop

Moderator
Staff member
Arg, my bad, I shared a code for the 4.5 :p
Try the same code but with "Object_movement" instead of "Object_direction.
 

Saulus_Lira

Member
dale_coop said:
Arg, my bad, I shared a code for the 4.5 :p
Try the same code but with "Object_movement" instead of "Object_direction.

Thanks. Now i compile the game.
However, there was a problem. When I put it up my player goes down. and he sets the direction only to the right.
 

Saulus_Lira

Member
As far as I know, no. I just did as in the example, without modifying the pre-existing code. But I will review the codes and see if everything is right.
 

dale_coop

Moderator
Staff member
Share your script (StartMovingPlayerDown), we can check if there's a error ;)

Also, when you share script on the forum, use the < code /> tag (in the "Full Editor & Preview")
 
Top Bottom