[4.5.2] ASM help, doHandlePhysics - platformer, landing

jataka5000

New member
I'm working on reversing gravity -- My modifications to the gravity part of the code now work (yay!) -- however, when I run into a solid tile from below, my speed is reset to zero, then keep moving (in this case upwards) through the object.

My goal: Upon collision with a solid, I want the top of my character stopped just under the solid tile, and still able to run left and right...

It seems that my key difficulty is understanding "isSolidSoLand":

Code:
isSolidSoLand:
	;; move to position
	;;; load the top of the tile that is being run into.
	LDA tileY
	AND #%11110000
	SEC
	SBC self_bottom
	SEC
	SBC #$01
	STA Object_y_hi,x
	STA yHold_hi

doneWithGravity:

Would someone be willing to give me some more insights (commenting the lines would be awesome!) as to what this part of the code is really doing? e.g. I'm not sure why "AND #%11110000", or why we are subtracting the self_bottom position. I'm also not sure on the real meaning of yHold_hi and Object_y_hi. I tried modifying "self_bottom" to "self_top" but it doesn't seem that simple...

Thanks for any help!


-j5k
 

dale_coop

Moderator
Staff member
If you want it for an inversed gravity... I guess the code should look like:

Code:
isSolidSoLand:
	;; move to position
	;;; load the top of the tile that is being run into.
	LDA tileY				;; tileY is the vertical coord of the collision (...somewhere inside the tile)
	AND #%11110000				;; this will give you TOP coord of the tile coord
	CLC					;; now we will add
	ADC #$10				;; 16 pixels that is the height of a tile
	
	SEC					;; depends of your bounding box... but maybe not necessary
	SBC self_top				;; depends of your bounding box... but maybe not necessary
	
	CLC					;; we add 1 pixel
	ADC #$01				;; because the platform engine always draw off by 1 pixel (to be able to calculate collisions under the object)
	
	STA Object_y_hi,x			;; we store back that new vertical coord to the player vert position
	STA yHold_hi

doneWithGravity:


Or something like the (I haven't tested)
 

jataka5000

New member
Got this working now. Your code works, and I found another solution also.

The key issue now is that collisions are not being obeyed when approaching solid platform from above. I've been cranking on this for a while and can't seem to figure out why.

I think that the issue is in my meager understanding of code in stopOnSolid_Platformer. I want the object to stop vertical speed with the bottom of object against the top of the solid tile. Basically the same as if you flipped the screen upside down and wanted to play with normal gravity.

I try commenting the part of the original code stopOnSolid_Platformer below.. appreciate any comments that correct my thinking on what is happening here.

Code:
		;; is jumping up when hitting a solid.
		;; ONLY do this is there is a solid directly over head.
		LDY Object_type,x
		LDA Object_x_hi,x
		CLC
		ADC self_left
		STA temp                               ; store the left-hand coordinate of the object
		JSR getPointColTable
		
		LDA Object_y_hi,x                 ; loads the object's y-coord (center?)
		CLC
		ADC self_top                         ; not sure why we should add the top coord of object.. wouldn't that take us downward?
		CLC
		ADC Object_v_speed_hi,x      ; if jumping up, speed is negative, so adding this will predict the next step upward for object.
		SEC
		SBC #$01       ; this bumps the position up one pixel, because the platform engine always draw off 
				     ;  by 1 pixel (to be able to calculate collisions under the object)
		STA temp1           ; store y-coord for testing against current pixel in question as engine scans through all pixels on screen.
		CheckCollisionPoint temp, temp1, #$01, tempA        ; test if x (temp), y (temp1) of object is in a collision region for a solid tile...
		BNE +dontStopVertMove
		
		...
		
				+stopVerticalMovementOnSolidHit
				LDA #$00                              
				STA Object_v_speed_lo,x       ; just zero out the  
				STA Object_v_speed_hi,x       ; vertical speed


I modified the stopOnSolid_Platformer to look for solid tile below object, and if so, then to zero out the speed. This does not work as intended though! Character is pushed down until directly below a solid tile. Maybe there is interference from another subroutine (e.g. doHandleTileCollisions_hscroller?)


Code:
	        LDA Object_y_hi,x  ; load my object's y position, upper coordinate
		CLC
		SBC self_bottom    ;; was: ADC self_top
		CLC
		SBC Object_v_speed_hi,x  ;; ADC Object_v_speed_hi,x
		SEC
		sbc #$01  ;; SBC #$01
		STA temp1
		CheckCollisionPoint temp, temp1, #$01, tempA
		BNE +dontStopVertMove


Any ideas on how to force the object to obey collisions when approaching from above?
 
Top Bottom