[4.5.6] ByteOff 2020 H Shooter Adv Tutorial Bug

AllDarnDavey

Active member
If like me you followed along with the advanced HShooter video. We speed up performance by writing a custom "doDrawSprites_ShooterBase_Simple" routine.

If you played your game after the tutorial, you might have noticed some weirdness going on, extra and phantom enemies and projectiles (they fly through the player) appearing onscreen. This is because in stripping out the bloat, we also removed a check if the object was actually onscreen before we process it, causing some unintended glitches when the scroll seam reaches a spawn position. Not to worry we just need to add a few lines of code before checking sprite type to check if we even need to draw it yet.
Code:
;;; CHECK OBJECT IS ONSCREEN
JSR evaluateTileAgainstCameraPosition
BEQ +
JMP doneDrawingThisSprite
+

The entire code should look something like this:
Code:
;; sprite drawing routine.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; For horizontal scrolling games, extra attention has to be taken to draw 
;;; sprites off screen if they are no longer in the camera render area.

	LDA gameHandler
	AND #%01000000
	BEQ doDrawThisSprite
	JMP doneDrawingThisSprite
doDrawThisSprite:
	;;; loaded into X is the object calling this routine.
	LDA Object_x_hi,x
	SEC
	SBC camX
	STA tempA
	
	LDA Object_y_hi,x
	STA tempB
	
	;;; CHECK OBJECT IS ONSCREEN FOR SCROLLING GAMES
	JSR evaluateTileAgainstCameraPosition
	BEQ +
	JMP doneDrawingThisSprite
	+	
	
	LDA Object_type,x
	BEQ +isPlayerObject
		JMP +isNotPlayerObject
	+isPlayerObject
		;;; DRAW PLAYER OBJECT 
		DrawSprite tempA, tempB, #$00, #%00000000
			LDA tempA
			CLC
			ADC #$08
			STA temp1
		DrawSprite temp1, tempB, #$01, #%00000000
			LDA tempB
			CLC
			ADC #$08
			STA temp2
		DrawSprite tempA, temp2, #$10, #%00000000
		DrawSprite temp1, temp2, #$11, #%00000000
		JMP doneDrawingThisSprite
	+isNotPlayerObject
	;;; CHECK OTHER OBJECTS
	CMP #$01
	BEQ +isLaser
		JMP +isNotLaser
	+isLaser
		;;;DRAW LASER OBJECT 
		DrawSprite tempA, tempB, #$02, #%00000000
		JMP doneDrawingThisSprite
	+isNotLaser 
	CMP #$02
	BEQ +isMonsterWeapon
		JMP +isNotMonsterWeapon
	+isMonsterWeapon 
		;;;DRAW MONSTER WEAPON 
		LDA vBlankTimer
		AND #%00000100
		BEQ +isEvenFrame
			;;; is odd frame
			DrawSprite tempA, tempB, #$21, #%00000010
			JMP doneDrawingThisSprite
		+isEvenFrame
			;;; is even frame
			DrawSprite tempA, tempB, #$20, #%00000010
			JMP doneDrawingThisSprite		
	+isNotMonsterWeapon
	CMP #$10
	BEQ +isAlien
		JMP +isNotAlien
	+isAlien
		;;; DRAW THE ALIEN, object #$10 (Monster number 1)
		DrawSprite tempA, tempB, #$80, #%00000010
			LDA tempA
			CLC
			ADC #$08
			STA temp1
		DrawSprite temp1, tempB, #$81, #%00000010
			LDA tempB
			CLC
			ADC #$08
			STA temp2
		DrawSprite tempA, temp2, #$90, #%00000010
		DrawSprite temp1, temp2, #$91, #%00000010
		JMP doneDrawingThisSprite
	+isNotAlien
	CMP #$11
	BEQ +isAlienShooter
		JMP +isNotAlienShooter
	+isAlienShooter	
		;;; DRAW THE ALIEN SHOOTER, object #$11 (Monster number 2)
		DrawSprite tempA, tempB, #$80, #%00000011
			LDA tempA
			CLC
			ADC #$08
			STA temp1
		DrawSprite temp1, tempB, #$81, #%00000011
			LDA tempB
			CLC
			ADC #$08
			STA temp2
		DrawSprite tempA, temp2, #$90, #%00000011
		DrawSprite temp1, temp2, #$91, #%00000011
		JMP doneDrawingThisSprite
	+isNotAlienShooter
doneDrawingThisSprite:
	RTS
	
	
	
		
evaluateTileAgainstCameraPosition:

	LDA Object_x_hi,x
	STA pointer
	LDA Object_screen,x
	AND #%00001111
	STA pointer+1
	
	LDA pointer
	
				
	Compare16 pointer+1, pointer, camX_hi, camX
	; arg0 = high byte of first value
	; arg1 = low byte of first value
	; arg2 = high byte of second value
	; arg3 = low byte of second value

	+
	JMP checkRightForDrawingOffCamera
	
	++		
		DestroyObject
		LDA #$01		
		RTS
checkRightForDrawingOffCamera
	LDA Object_x_hi,x
	CLC
	ADC self_right
	STA pointer
	LDA Object_screen,x
	ADC #$00
	AND #%00001111
	STA pointer+1

	LDA camX
			
	STA pointer5
	LDA camX+1
	clc
	ADC #$01
	STA temp
	Compare16 pointer+1, pointer, temp, pointer5; camX
	+
	LDA #$01
	rts
	++
	LDA #$00
	rts
 

Arctic Blizzard

New member
Thanks so much for posting this. I thought I did something wrong in the coding. And redid that tutorial 3 times before giving up. And just reloaded the original script. The one that gives you lag real bad.
 

AllDarnDavey

Active member
Thanks so much for posting this. I thought I did something wrong in the coding. And redid that tutorial 3 times before giving up. And just reloaded the original script. The one that gives you lag real bad.
Once I figured out what was happening and how to fix it, after I went through the tutorial myself. I had to post the fix in case I forgot, or in case anyone else also got blocked. I'm glad someone found it helpful :)

I think it was just a simple oversight, they were making 3 tutorials at once, for every module.
 

vanderblade

Active member
Your the spiritual successor to Dale in terms of helpfulness and guidance, Davey. Even though that 8-bit hero is still around, too.
 
Top Bottom