Auto Scroll eats player

User avatar
Raftronaut
Posts: 266
Joined: Mon Sep 03, 2018 4:47 pm

Re: Auto Scroll eats player

Post by Raftronaut » Sun Jun 09, 2019 4:11 pm

Mugi wrote:
Fri Mar 29, 2019 9:23 am
boundshandlers are 4 scripts defined in script settings that define what actually happens when you touch screen edges.
removing those effectively makes the screen just wrap around itself, they should be loaded by default from Routines\Basic\ModuleScripts\MainScripts\BoundsHandlers\

Mugi! I am STILL struggling with this issue. Just got back into the project with the forums being up again. Found my bounds handler scripts in project settings. Here is the script for 'handle left bounds'. I am not sure what to look for as far indicators as to what is going wrong. Any thoughts??!?

Can the X coordinate be changed here to limit the access it has to get pulled into the seem of the left bounds?

Code: Select all

	LDA screenFlags
	AND #%00000010
	BEQ +
	
	;LDA screenFlags
	;AND #%00000100 ;; left bounds autoscrolling right
	;BEQ +
	LDA #$00
	STA Object_x_lo,x
	STA Object_h_speed_lo,x
	STA Object_h_speed_hi,x
	; for auto scrolling, use xScroll instead of xPrev? 
	;LDA xScroll
	LDA xPrev
	STA xHold_lo
	STA Object_x_hi,x
	STA xHold_hi
;	LDA xScroll_hi
;	STA Object_scroll,x
;	STA nt_hold


	JMP doneWithUpdateLeftScreen
	
+
	
	LDA #BOUNDS_RIGHT
	SEC
	SBC Object_right,x
	SEC 
	SBC #$02

	STA xHold_hi
	STA newX
	STA Object_x_hi,x
	
	LDA Object_y_hi,x
	STA newY
	
		LDA #$00
	STA xHold_lo
	STA yHold_lo

;;; check if side triggers change screen...for instance, if hurt, wouldn't, and would instead return *solid*

	
	LDA Object_scroll,x
			sec
			sbc #$01
			STA Object_scroll,x
			STA currentNametable
			STA newScreen
			STA currentScreen ;currentScreen
			STA xScroll_hi
			
			clc
			adc #$01
			STA rightNametable
			SEC
			SBC #$02
			STA leftNametable
			
			LDA Object_scroll,x
			AND #%00000001
			STA showingNametable
			
			
			LDA #$01
			STA screen_transition_type
			
		;LDA warpMap
			;CLC
			;ADC #$01
			;STA update_screen_details
			
			;;; update screen details will not change with left, right, up or down movement
			;;; unless the edge of a map should take you to the other map or something.
			;;; warpMap variable is used solely to hold whether the warp-out is to overworld or underworld.
			

		
	LDA #$01
	STA tile_solidity		
	LDA #$00
	STA gameHandler
		LDA #%11000000
				;7 = active
				;6 = 8 or 16 px tiles
			ORA #GS_MainGame
			ORA #%01000000
			STA update_screen

doneWithUpdateLeftScreen:
Last edited by Raftronaut on Mon Jun 10, 2019 7:16 pm, edited 1 time in total.
Space Raft 2.0 Demo: [url] http://nesmakers.com/viewtopic.php?f=52&t=2867 [/url]

Chiptune: [url] https://soundcloud.com/user-634230995-350638590 [/url]
User avatar
Raftronaut
Posts: 266
Joined: Mon Sep 03, 2018 4:47 pm

Re: Auto Scroll eats player

Post by Raftronaut » Wed Jun 26, 2019 1:30 am

saturdayxiii wrote:
Tue Mar 26, 2019 10:31 pm
Sorry for the delay, I just got to try this now.

I got it working, or at least straight on. Pressing into the floor, and presumably the ceiling still does a really weird wrap around thing, but I guess it's a step in the right direction... or least a direction.

Mugi's code only edited the part of the Tilecollision code that uses gravity. The simple shooter module is a space shooter, so no gravity here. Here's the code I used to replace the "don'tUseGravity" section around line 110, so now it points to the new macros. Be aware I erased the comments here for readability, you may or may not still want them in your own file.

Code: Select all

dontUseGravity:

	CheckPotentialPosition
	CheckPlayerCameraPositionHorizontal
    JSR updateHorizontalPosition
    CheckPotentialPosition
    CheckPlayerCameraPositionVertical
    JSR updateVerticalPosition
	
     JMP DoneWithTileChecksAndUpdatePosition
I am still struggling with this glitch, did you manage to find a solution? This last edit to the tilecollision.asm is raising all sorts of hell on the boundshandlers, causing player to respawn in the screen edge after death, getting stopped by null tiles behaving as solids (i've triple checked my screen collisions)

This is the one MAJOR roadbloack I have to finishing version 2.0 of my demo and would greatly like to see it resolved if possible. If you have any insight I would be forever grateful!
Space Raft 2.0 Demo: [url] http://nesmakers.com/viewtopic.php?f=52&t=2867 [/url]

Chiptune: [url] https://soundcloud.com/user-634230995-350638590 [/url]
User avatar
Mugi
Posts: 697
Joined: Thu Dec 27, 2018 8:30 pm

Re: Auto Scroll eats player

Post by Mugi » Wed Jun 26, 2019 1:34 am

Sorry i really havent had time to look into this.... between juggling with real life issues and my own game's development i cant seem to even have time to eat nowadays...
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
Raftronaut
Posts: 266
Joined: Mon Sep 03, 2018 4:47 pm

Re: Auto Scroll eats player

Post by Raftronaut » Wed Jun 26, 2019 1:45 am

I deleted the CheckPlayerCameraPosition.asm macro, I replaced with the CheckPlayerCameraPositionHorizontal and CheckPlayerCameraPositionVertical , then deleted and replaced the TileCollision_4_1_0.

Like I said in previous posts, all hell broke loose in the collision detection. This bug is driving me bananas. :shock:
Desperate for help at this point

CheckPlayerCameraPositionHorizontal:

Code: Select all

	
MACRO CheckPlayerCameraPositionHorizontal
	CPX player1_object
    BEQ notdoneWithCameraCheckHorizontal
	JMP doneWithCameraCheckHorizontal
notdoneWithCameraCheckHorizontal:
	LDA gameHandler
	AND #%10000000
	BNE gameIsActive
	JMP doneWithCameraCheckHorizontal
gameIsActive:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; let's check to see if we're against the leftmost edge.
	LDA xScroll_hi
	BNE + ; not on screen 0
	;; is on screen zero
	LDA Object_h_speed_lo,x
	CLC
	ADC #$00
	LDA Object_h_speed_hi,x
	ADC #$00
	BPL + ;; not moving left.
	LDA Object_scroll,x
	BNE +
	LDA xScroll
	CMP xHold_hi
	BCS leftOfCameraForPlayer
	JMP checkRightEdge
+
    LDA nt_hold
    CMP xScroll_hi
    BCC leftOfCameraForPlayer
	;BEQ leftOfCameraForPlayer
    BNE checkRightEdge
    LDA xHold_hi
    CMP xScroll
    BCC leftOfCameraForPlayer
	;BEQ leftOfCameraForPlayer
    JMP checkRightEdge
leftOfCameraForPlayer:
    ;;; dont update position
    JMP doScrollingLeftBounds
checkRightEdge:
    LDA xScroll_hi
    CLC
    ADC #$01
    STA temp
    
    LDA xScroll
    SEC
    SBC Object_right,x
    STA temp1
    LDA temp
    SBC #$00
    STA temp

    CMP nt_hold
    BCC rightOfCameraEdgeForPlayer
	;BEQ rightOfCameraEdgeForPlayer
    BNE doneWithCameraCheckHorizontal
    LDA temp1
    CMP xHold_hi
    BCC rightOfCameraEdgeForPlayer
	;BEQ rightOfCameraEdgeForPlayer
    JMP doneWithCameraCheckHorizontal
rightOfCameraEdgeForPlayer:
    JMP doScrollingRightBounds
  
doScrollingLeftBounds:
    ;;; enter what should happen at bounds for player.
	;;; an RTS here will result in skipping position update.
	JSR doLeftBounds_player
    RTS    
    
doScrollingRightBounds:
    ;;; enter what should happen at bounds for player.
	;;; an RTS here will result in skipping position update.
	JSR doRightBounds_player
    RTS

doneWithCameraCheckHorizontal:
    ENDM
CheckPlayerCameraPositionVertical:

Code: Select all

MACRO CheckPlayerCameraPositionVertical
	CPX player1_object
    BEQ notdoneWithVerticalCameraCheck
	JMP doneWithVerticalCameraCheck
notdoneWithVerticalCameraCheck:
	LDA gameHandler
	AND #%10000000
	BNE gameIsActiveCheckVertical
	JMP doneWithVerticalCameraCheck
gameIsActiveCheckVertical:

;;;;; TOP CHECK
	LDA Object_y_hi,x
	CLC
	ADC #$7F
	STA temp
	LDA Object_y_lo,x
	CLC
	ADC Object_v_speed_lo,x
	LDA temp
	ADC Object_v_speed_hi,x
	BVC notAtBoundsTop
	LDA #$00
	STA xScroll
	JSR doTopBounds_player
	RTS
;;;;; BOTTOM CHECK
notAtBoundsTop:
	LDA Object_y_lo,x
	CLC
	ADC Object_v_speed_lo,x
	LDA Object_y_hi,x
	ADC Object_v_speed_hi,x
	ADC Object_bottom,x
	CMP #BOUNDS_BOTTOM
	BCS atBottomBounds
	JMP doneWithVerticalCameraCheck
atBottomBounds:
	LDA #$00
	STA xScroll
	JSR doBottomBounds_player
	RTS

doneWithVerticalCameraCheck:
    ENDM
TileCollision_4_1_0:

Code: Select all

HandleTileCollision:
    ;;;;;ASSUMES vulnerability bit 000x0000, if one, skips collision.
    ;;;;;Six collision points. 
    ;;;;;All collision points checked and registered for all objects.
    ;;;; a solid in any of the points will result in negating all others.
    
        ;;; There are 6 ram variables, collisionPoint0 - collisionPoint5.
        ;;; collisionPoint0 = top left
        ;;; collisionPoint1 = top right
        ;;; collisionPoint2 = bottom right
        ;;; collisionPoint3 = bottom left.
        ;;; collisionPoint4 = mid left
        ;;; collisionPoint5 = mid right.
    
    TXA 
    STA currentObject
    TYA
    STA tempy

	LDA npc_collision
	AND #%11111101
	LDA #$00
	STA npc_collision
	LDA navFlag
	AND #%11111110
	STA navFlag
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EXPLANATION:
;; In this basic module, both non gravity and gravity scripts are loaded.
;; Under most circumstances, a user will likely make use of one or the other,
;; as they each take up a good chunk of data.  But the benefit of including both is that
;; a platforming game with gravity is just a simple bit flip in the screen flags.
    
    
    LDA screenFlags
    AND #%00100000
    BNE useGravity
    JMP dontUseGravity
useGravity:
	LDA Object_vulnerability,x
	AND #%00100000
	BEQ useGravity2
	LDA Object_physics_byte,x
	AND #%00000010
	BNE useGravity2
	JMP dontUseGravity
useGravity2:

;;;;;;===================================================
;;;;;;***************************************************
;;;;;; TILE COLLISION FOR SCROLLING PLATFORMERS:
;;;;;; For scrolling platformers we will use three types of collision detection:
;;;;;;          1. A routine to check under our feet to determine
;;;;;;              whether or not you are standing on a solid object.

                    ;;; This function will check under neath the object's feet
                    ;;; by arg0 pixels.
                    ;;; it will update bit 0 of the Object_physics_byte.
                    ;;; If that bit is 0, it means the place is free.
                    ;;; If that bit is 1, it means the place is solid.
    ;**********************
       CheckUnderObject #$01

;;;;;;
;;;;;;          2. A routine that checks to see if the potential position leaves you
;;;;;;              with your 'bottom' or 'top' in a solid object, in which case it ejects pixel perfect
;;;;;;              to that tile.

                    ;;; This function checks the POTENTIAL vertical position.
                    ;;; If it results in a point in a solid object, it appropriately
                    ;;; ejects and places the object directly against the point
                    ;;; of collision.
    ; **********************
     CheckForVerticalEjection 

  
;;;;;; Better check for any vertical updates now, or else
;;;;;; a horizontal collision could cancel out the required
;;;;;; bounds update
    CheckPlayerCameraPositionVertical


;;;;;;
;;;;;;          3. A routine which checks horizontal motion to see if the potential position
;;;;;;              sees a solid collision, in which case it can not move.
 
                    ;;; This function checks potential horizontal position.
                    ;;; without factoring in vertical motion.  If it sees a solid,
                    ;;; it skips motion.
    ; ***********************
      CheckForHorizontalCollision
    
;;;; This is the end of scrolling platform physics.  It automatically jumps to the proper place.  
;;;; Otherwise, if there was no collision, we jump to updating the position.
    ;; we only need to update horizontal position
    
  

    CheckPlayerCameraPositionHorizontal
;;;; if it turns out we were outside of the camera bounds, the macro
;;;; has RTSed out of this routine, so the hoziontal position will
;;;; never be updated.
   
     JSR updateHorizontalPosition
   
     JMP DoneWithTileChecksAndUpdatePosition
;;;;;;;;;;;;;==============================================  


dontUseGravity:

	CheckPotentialPosition
	CheckPlayerCameraPositionHorizontal
    JSR updateHorizontalPosition
    CheckPotentialPosition
    CheckPlayerCameraPositionVertical
    JSR updateVerticalPosition
	
     JMP DoneWithTileChecksAndUpdatePosition

     JMP DoneWithTileChecksAndUpdatePosition
   
   
   

;;; NO POINTS WERE SOLID    
    ;;;; update hold
DoneWithTileChecksAndUpdatePosition:
   ldx currentObject
    RTS
    
HandleSolidCollision:
	LDA screenFlags
	AND #%00000100 ;; is it autoscrolling?
	BEQ + ;; not autoscrolling
	;;; is auto scrolling
	CPX player1_object
	BNE +
	JSR CheckAutoScrollLeftEdge
	RTS 
+ ;; not auto scrolling.

	LDA xPrev
	STA xHold_hi
	LDA yPrev
	STA yHold_hi
    TYA
    STA tempy
    LDA Object_edge_action,x
    LSR
    LSR
    LSR
    LSR
    BEQ doNothingAtSolid
    TAY
    
    LDA AI_ReactionTable_Lo,y
    STA temp16
    LDA AI_ReactionTable_Hi,y
    STA temp16+1
    
    JSR doReactionTrampolineSolid
    JMP pastReactionTrampolineSolid
doReactionTrampolineSolid:
    JMP (temp16) ;;; this now does the action
            ;; and when it hits the RTS in that action,
            ;; it will jump back to the last JSR it saw,
            ;; which was doNewActionTrampoline...which will immediately
            ;; jump to pastDoNewActionTrampoline.
pastReactionTrampolineSolid:
    ;LDA #$00
    ;STA xHold_lo

doNothingAtSolid:
    ;;;;;;;;;;; Do solid reaction type.
    LDY tempy
    LDX currentObject
    RTS
    
    
ejectUp:
    LDA tileY
    and #%00001111;We can only be 0 to 15 pixels in any given wall
    sta temp
 
    lda Object_y_hi,x
    clc;Subtract one plus that so we're a pixel out of the wall rather than one pixel in it.
    SBC temp
    STA Object_y_hi,x
    LDA #$00
    STA yHold_lo
    STA Object_v_speed_hi,x
    STA Object_v_speed_lo,x
    RTS
    
ejectDown:

    lda tileY
    and #%00001111;we can only be 0 to 15 pixels in any given wall
    eor #%00001111;If we're at position 15 in the tile, we only want to eject 0 (+1) so flip the bits
    sec;Will add the extra one to the position so that we're a pixel out of the wall
    adc Object_y_hi,x;rather than one pixel in it.
    sta Object_y_hi,x
    
    LDA #$00
    STA yHold_lo
    STA Object_v_speed_hi,x
    STA Object_v_speed_lo,x
	
	;;; check the top two collision points to see if is it a prize block.
	LDA collisionPoint0
	CMP #COL_INDEX_PRIZE_BLOCK
	BEQ +
	JMP ++ 
+
	LDA Object_x_hi,x
	CLC
	ADC Object_left,x
	STA tileX
	JMP +++
++
	LDA collisionPoint1
	CMP #COL_INDEX_PRIZE_BLOCK
	BEQ +
	JMP ++
+
	LDA Object_x_hi,x
	CLC
	ADC Object_right,x
	STA tileX
+++


	
	LDA gameHandler
	ORA #%00010000
	STA gameHandler
	;;;;; check other head-hit type objects here.
	;; change collision data.
	;; should still have the correct coordinates in tileX and tileY
	ChangeTileAtCollision #$00, #TILE_INDEX_PRIZE_OFF
	
	TXA
	PHA
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	SEC
	SBC #$12 ;; a bit more than the height of it.
	STA temp1
	LDA Object_scroll,x
	STA temp2
	CreateObject temp, temp1, #OBJ_PRIZE, #$00, temp2
	LDA #$00
	SEC
	SBC #$04
	STA Object_v_speed_hi,x
	
	PLA
	TAX
	
++
    RTS
    
    
    

CheckForCollision:

    ;;;; commonly, we won't want to waste cycling 6 times through this for each object when
    ;;;; all points are at no collision.  If by chance we NEED the zero type collision to do something, 
    ;;;; we can comment out the zero type check in this next line.  But most games are going to have
    ;;;; at least one "blank tile" that does nothing, and most games will use zero for this.
	
	;;;; Another conundrum is that a collision could take place in the current or new nametable.
	;;;; if this collision is of type that draws from screen data (for instance, NPC data or warp data), it could
	;;;; be problematic, as all variables handling these things are loaded with the current collision tables data.
	;;;; tempCol ends up being 0 or 1 based on which collision table this should be referencing.
	
    STA temp
    BNE notZeroTypeCollision
    JMP zeroTypeCollision
notZeroTypeCollision:
    LDA #$00
    STA tile_solidity
DoCheckPointsLoop:
    LDA temp
    TAY
    LDA tileTypeBehaviorLo,y
    STA temp16
    LDA tileTypeBehaviorHi,y
    STA temp16+1
    JSR UseTileTypeTrampoline
    JMP pastTileTypeTrampoline
UseTileTypeTrampoline:
    JMP (temp16)
pastTileTypeTrampoline:
DontCheckTileType0:

    
zeroTypeCollision:
    ldx currentObject
    RTS
    
    
    
    
DetermineCollisionTable:
    LDA tempCol
    BNE colPointInDifferentTable
    ;;;; the collision point is in the current collision table.
    LDA Object_scroll,x
    AND #%00000001
    BNE isInOddTable
    JMP isInEvenTable
colPointInDifferentTable:
    ;;; the collision point to be checked is in the NEXT collision table.
    LDA Object_scroll,x
    AND #%00000001
    BNE isInEvenTable
    JMP isInOddTable
	

isInEvenTable:
    LDA collisionTable,y
    RTS
isInOddTable:
    LDA collisionTable2,y

    RTS


    
    
updateHorizontalPosition:
    LDA xHold_lo
    STA Object_x_lo,x
    LDA xHold_hi
    STA Object_x_hi,x
    LDA nt_hold
	CMP Object_scroll,x
	BEQ justUpdateScroll
	LDA #$01
	STA update_screen_data_flag
	LDA nt_hold
justUpdateScroll:
    STA Object_scroll,x
    
    RTS
    
updateVerticalPosition:
    LDA yHold_lo
    STA Object_y_lo,x
    LDA yHold_hi
    STA Object_y_hi,x   
    RTS
Space Raft 2.0 Demo: [url] http://nesmakers.com/viewtopic.php?f=52&t=2867 [/url]

Chiptune: [url] https://soundcloud.com/user-634230995-350638590 [/url]
User avatar
Raftronaut
Posts: 266
Joined: Mon Sep 03, 2018 4:47 pm

Re: Auto Scroll eats player

Post by Raftronaut » Wed Jun 26, 2019 1:48 am

Mugi wrote:
Wed Jun 26, 2019 1:34 am
Sorry i really havent had time to look into this.... between juggling with real life issues and my own game's development i cant seem to even have time to eat nowadays...
No worries! The trail went cold for me when the forums went down in April, I switched gears and started working on other aspects, many of which are done and ready to go, but I can't button anything up until I can resolve this one.
Space Raft 2.0 Demo: [url] http://nesmakers.com/viewtopic.php?f=52&t=2867 [/url]

Chiptune: [url] https://soundcloud.com/user-634230995-350638590 [/url]
Post Reply