pigeonaut
Member
Alright I got it to work for real this time haha:
I just needed grid movement for the up and down direction but was able to figure out left and right and wanted to share this solution with you. Yes it's messy but it can be shortened and cleaned up.
How does it work? The tile will check for player collision. If the player collides, the tile checks to see if the player is at the center of the tile. If at center of tile, then stop the player. Since the collision system is complex, the direction you collide with the tile will give different collision values. We need to account for this offset by using the player direction as a guide.
Here is the tile script, you will need to paint your whole floor with this tile type:
Next your player move scripts NEED to have the facing direction in them. You can still assign the d-pad "hold" input to these input scripts and it will still work. Here is my move UP script for example:
Lastly, and this is important, your player bounding box needs to be 2 pixels less on the top and bottom sides. And 1 pixel less on the left and right sides. This keeps the player from "skipping" tiles when they really should be stopping.
Expected output:
When you hold the UP input, your player should keep going up. As soon as the player lets go of UP input, the player should stop at the next tile. Similar to Pokemon.
Also this has the nice side-effect of "lining up" the player at the start of the game run. Newsmaker always starts their sprite 1 pixel off on the Y-axis for some reason. If the player starts on one of these tiles, they will be perfectly centered on the tile!
Let me know if you have any questions!
Here are my sources for figuring out this solution:
I just needed grid movement for the up and down direction but was able to figure out left and right and wanted to share this solution with you. Yes it's messy but it can be shortened and cleaned up.
How does it work? The tile will check for player collision. If the player collides, the tile checks to see if the player is at the center of the tile. If at center of tile, then stop the player. Since the collision system is complex, the direction you collide with the tile will give different collision values. We need to account for this offset by using the player direction as a guide.
Here is the tile script, you will need to paint your whole floor with this tile type:
Code:
;; TODO: clean the code!
;; first check if player collided with this tile:
CPX player1_object
BEQ +checkDirection
;else not a player
JMP +skip
+checkDirection
;; next check which way we are facing:
LDA Object_direction
AND #%00000111
CMP #%00000000 ;Down
BNE +notDown
; is down direction, do this:
;;convert tile coord to collision coords:
LDA tileX
AND #%11110000
STA tempx
;; fix the offset:
LDA tempx
SEC
SBC #$02
STA tempx
;; now do same for Y
LDA tileY
AND #%11110000
STA tempy
LDA tempy
SEC
SBC #$03
STA tempy
JMP +continue
+notDown
AND #%00000110 ; up
CMP #%00000100
BNE +notUp
LDA tileX
AND #%11110000
STA tempx
LDA tempx
SEC
SBC #$02
STA tempx
LDA tileY
AND #%11110000
STA tempy
JMP +continue
+notUp
AND #%00000110
CMP #%00000010 ;;right
BNE +notRight
LDA tileX
AND #%11110000
STA tempx
LDA tempx
SEC
SBC #$02
STA tempx
LDA tileY
AND #%11110000
STA tempy
JMP +continue
+notRight
AND #%00000110
CMP #%00000110
BNE +notLeft ;; left
;PlaySound #sfx_powerup
LDA tileX
AND #%11110000
STA tempx
LDA tempx
SEC
ADC #$00
STA tempx
LDA tileY
AND #%11110000
STA tempy
JMP +continue
+notLeft
JMP +skip
; stop the player at center of tile
+continue
LDA Object_y_hi,x
CMP tempy
BNE +checkX
JMP stop_player_1
+checkX
LDA Object_x_hi,x
CMP tempx
BNE +skip
stop_player_1
TXA
STA temp
StopMoving temp, #$FF, #$00
+skip
RTS
Next your player move scripts NEED to have the facing direction in them. You can still assign the d-pad "hold" input to these input scripts and it will still work. Here is my move UP script for example:
Code:
TXA
STA temp
StartMoving temp, #UP
TXA
STA temp ;; assumes the object we want to move is in x.
ChangeFacingDirection temp, #FACE_UP
RTS
Lastly, and this is important, your player bounding box needs to be 2 pixels less on the top and bottom sides. And 1 pixel less on the left and right sides. This keeps the player from "skipping" tiles when they really should be stopping.
Expected output:
When you hold the UP input, your player should keep going up. As soon as the player lets go of UP input, the player should stop at the next tile. Similar to Pokemon.
Also this has the nice side-effect of "lining up" the player at the start of the game run. Newsmaker always starts their sprite 1 pixel off on the Y-axis for some reason. If the player starts on one of these tiles, they will be perfectly centered on the tile!
Let me know if you have any questions!
Here are my sources for figuring out this solution:
(Solved)How to determine player or object direction
Hey everyone! I was wondering how one could check for the player's facing-direction from a tile collision. Here is what I tried: I found the variable Object_direction under the "object variables" tab in the project settings. Under the nodes its states this: xxxxZyyy Where xxxx = inertial...
www.nesmakers.com
If Left is #%00000110, what are the other directions?
I'm trying to code a new AI Behavior to make a monster move up and right off the screen. I know I've seen a list of binary codes representing the 8 different directions somewhere in the .asm files for one of my projects but I can't find it now. Can someone tell me what the other directions are?
www.nesmakers.com
[4.5.6] Finding the x & y coordinates of a tile [solved]
Question: is there a way to determine a tile's x & y position using .asm? For example, I have a hurt tile, and I'd like to know it's x and y position via .asm, and not looking at it's location on-screen. Answer: In a tile collision asm script, tileX and tileY variables are the coords (in...
www.nesmakers.com