[4.5.9] Any Non-Scrolling Module - Which Collision Table?

CluckFox

Active member
During work on Special Tiles I saw variations of this pattern in several places:


Code:
LDA currentNametable
AND #%00000001
BEQ +isEvenCt
LDA #$24
STA temp1 ;; high byte of thing
;;; is odd col table.
LDA collisionTable2,x
CMP #MONSTER_BLOCK_TILE
BEQ +isMonsterBlockTile
JMP +notMonsterBlockTile
+isMonsterBlockTile
;; is monster block table.
LDA #$00
STA collisionTable2,x

JSR getTileToChange_forMonBlock

JMP +doneWithTileUpdate
+isEvenCt
LDA #$20
STA temp1 ;; high byte of thing.
;;; is odd col table.
LDA collisionTable,x
CMP #MONSTER_BLOCK_TILE
BEQ +isMonsterBlockTile
JMP +notMonsterBlockTile
+isMonsterBlockTile
;; is monster block table.
LDA #$00
STA collisionTable,x
JSR getTileToChange_forMonBlock

JMP +doneWithTileUpdate

In some cases it was repeatedly called inside a loop. With a view towards optimizing for code simplicity I consolidated the key decisions into the post-screen-load script. The script requires a two-byte Zero Page variable ctPtr and single-byte hBot (High Byte of Thing, according to comments) and accomplishes the following:

  • Creates a single pointer to either collisionTable or collisionTable2 as appropriate
  • Stores an offset that's different for even or odd screens, needed for changing tile appearance
The effect is that changing a tile collision is simplified to:


Code:
LDY #$c8 ;; tile coordinates
LDA (ctPtr),y
CMP #SOME_TILE_TYPE
BEQ +doChangeThisTile
;;;;;;;; stuff
+doChangeThisTile
LDA #$00 ;; tile type for Null/Walkable
STA (ctPtr),y
;;;;;;;; stuff, continued

The attached code is a revision to the Special Tiles code, modified to use this concept. Please be aware that the code has only been tested in my demo, and only applies to non-scrolling games.
 

Attachments

  • SPECIAL_TILES_rev3.zip
    5.1 KB · Views: 2
Top Bottom