Ladders not working?

User avatar
dale_coop
Posts: 5215
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ladders not working?

Post by dale_coop » Fri Mar 27, 2020 7:54 pm

The Check For Horizontal Collision macro, does just half of the work (checking only the left bounding when moving to the left... else the right bounding box when not moving or moving to the right).

Here's an alternate CheckForHorizontalCollision.asm script, I use it for my projects
(make a backup of your NESmaker folder or just the file, just in case... to restore if you have issues or not working well with your project)

CheckForHorizontalCollision.asm (to be placed in your "Routines\Basic\System\Macros" folder):

Code: Select all

	
MACRO CheckForHorizontalCollision

;;;; RESET SOLID
	LDA #$00
    STA tile_solidity
	Sta collisionPoint0
	STA collisionPoint1
	STA collisionPoint2
	STA collisionPoint3
	STA collisionPoint4
	STA collisionPoint5
	
;;; RESET LADDER STATE	
	LDA Object_physics_byte,x
	AND #%11111101
	STA Object_physics_byte,x
	
	
	LDA Object_flags,x
	AND #%00000010
	BNE +
	JMP doLeftHorColCheck
	+

	LDA Object_h_speed_lo,x
	CLC
	ADC #$00
	LDA Object_h_speed_hi,x
	ADC #$00
	BMI + 
	JSR doRightHorColCheck
	JSR doLeftHorColCheck
	JMP ++
	+
	JSR doLeftHorColCheck
	JSR doRightHorColCheck
	++

	JMP doneWithHorColCheck
	
	
	
doLeftHorColCheck:

    LDA xHold_hi
    CLC
    ADC Object_left,x
    STA tileX

    LDA Object_y_hi,x
    CLC
    ADC Object_top,x
    STA tileY
	
    JSR GetTileAtPosition
    ;JSR DetermineCollisionTable
	;LDA #$00
	LDA Object_left,x
	STA temp
	DetermineCollisionTableOfPoints temp
	
    STA collisionPoint0
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    JMP HandleSolidCollision ;; hit a solid so won't update position. 
+   
	LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
	;;; check bottom left point

    LDA xHold_hi
    CLC
    ADC Object_left,x
    STA tileX

    LDA Object_y_hi,x
    CLC
    ADC Object_bottom,x
    STA tileY
    
    JSR GetTileAtPosition
   ; JSR DetermineCollisionTable
   	;LDA #$00
	LDA Object_left,x
	STA temp
	DetermineCollisionTableOfPoints temp

    STA collisionPoint3
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    ;LDA Object_physics_byte,x
    ;ORA #%01000000 ;; solid was at top.
    ;STA Object_physics_byte,x
    JMP HandleSolidCollision ;; hit a solid so won't update position.
+

    LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
;;;;; left middle
	LDA Object_bottom,x
    SEC
    SBC Object_top,x
    LSR 
    STA temp3 ;; temp 3 now equals half of the height of the object, so top+temp3 = mid point vertically.
  
	
    LDA xHold_hi
    CLC
    ADC Object_left,x
    STA tileX

    LDA Object_y_hi,x
    CLC
    ADC Object_top,x
    CLC
    ADC temp3
    STA tileY
    
    JSR GetTileAtPosition
    ;JSR DetermineCollisionTable
	;LDA #$00
	LDA Object_left,x
	STA temp
	DetermineCollisionTableOfPoints temp
    STA collisionPoint4
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    JMP HandleSolidCollision ;; hit a solid so won't update position.
+
    	LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
	;LDX currentObject
	LDA Object_flags,x
    AND #%00000010
	BNE +
	JMP doRightHorColCheck
	+
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
doRightHorColCheck:


    LDA xHold_hi
	CLC
    ADC Object_right,x
    STA tileX

    LDA Object_y_hi,x
    CLC
    ADC Object_top,x
    STA tileY
    
    JSR GetTileAtPosition
   ; JSR DetermineCollisionTable
   	LDA Object_right,x
	STA temp
	DetermineCollisionTableOfPoints temp
    STA collisionPoint1
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    JMP HandleSolidCollision ;; hit a solid so won't update position.
+
	LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	

    LDA xHold_hi
    CLC
    ADC Object_right,x
    STA tileX
   
    LDA Object_y_hi,x
    CLC
    ADC Object_bottom,x

    STA tileY
    
    JSR GetTileAtPosition
    ;JSR DetermineCollisionTable
	LDA Object_right,x
	STA temp
	DetermineCollisionTableOfPoints temp
    STA collisionPoint2
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    ;LDA Object_physics_byte,x
    ;ORA #%01000000 ;; solid was at top.
    ;STA Object_physics_byte,x
    JMP HandleSolidCollision ;; hit a solid so won't update position.
+
    	LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
    ;;; IF YOU NEED TO FIND OUT THE MID POINT HORIZONTALLY
    ;LDA Object_right,x
    ;SEC
    ;SBC Object_left,x
    ;LSR
    ;STA temp2 ;; temp 2 now equals half the width of the object, so left+temp2 = mid point horizontally.
    
    LDA Object_bottom,x
    SEC
    SBC Object_top,x
    LSR 
    STA temp3 ;; temp 3 now equals half of the height of the object, so top+temp3 = mid point vertically.
    

    LDA Object_y_hi,x
    CLC
    ADC Object_top,x
    CLC
    ADC temp3
    STA tileY

	LDA xHold_hi
    CLC
    ADC Object_right,x
    STA tileX
     
    JSR GetTileAtPosition
    ;JSR DetermineCollisionTable
	LDA Object_right,x
	STA temp
	DetermineCollisionTableOfPoints temp
    STA collisionPoint5
    JSR CheckForCollision
    LDA tile_solidity
	AND #%00000001
    BEQ +
    JMP HandleSolidCollision ;; hit a solid so won't update position.
+
	LDA tile_solidity
	AND #%00000010
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000010
	BNE +
	;;; DO LADDER STUFF
	JSR DoLadderStuff
+
	LDA Object_flags,x
    AND #%00000010
	BNE +
	JMP doneWithHorColCheck
	+
	RTS

doneWithHorColCheck:
	ENDM
-----
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)
My son's game: KUBO 3
User avatar
Dirk
Posts: 586
Joined: Fri Mar 09, 2018 5:30 am

Re: Ladders not working?

Post by Dirk » Fri Mar 27, 2020 11:10 pm

Thank you Dale! Finally I can climb the ladders correctly :-)
-----
Disclaimer: English is not my first language, so mistakes are bound to happen.
User avatar
dale_coop
Posts: 5215
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ladders not working?

Post by dale_coop » Sat Mar 28, 2020 2:46 pm

Glad this work a little better now :)
-----
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)
My son's game: KUBO 3
User avatar
dale_coop
Posts: 5215
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ladders not working?

Post by dale_coop » Sun Mar 29, 2020 4:58 pm

I updated the script with a minor modification... (the previous code would cause invisible wall issues when the player bounding box was small)
-----
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)
My son's game: KUBO 3
User avatar
Dirk
Posts: 586
Joined: Fri Mar 09, 2018 5:30 am

Re: Ladders not working?

Post by Dirk » Sun Mar 29, 2020 5:20 pm

Awesome! Thank you again :-)
-----
Disclaimer: English is not my first language, so mistakes are bound to happen.
Post Reply