diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-06 16:11:46 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-06 16:11:46 +0100 |
| commit | f1133047080fed08d7829a5115bd8c9e42cc1dfc (patch) | |
| tree | 927d1b55eabc98e5d38ff3b0d94bdea5dc0cd094 /src/enemies.s | |
| parent | 1efe10cf62ebf9f0749dd3329ea52f4c9ac2e96b (diff) | |
| download | jetpac.nes-f1133047080fed08d7829a5115bd8c9e42cc1dfc.tar.gz jetpac.nes-f1133047080fed08d7829a5115bd8c9e42cc1dfc.zip | |
Improve documentation on Enemies::zp_current_tiles
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/enemies.s')
| -rw-r--r-- | src/enemies.s | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/enemies.s b/src/enemies.s index 7097af5..2c43d77 100644 --- a/src/enemies.s +++ b/src/enemies.s @@ -75,17 +75,24 @@ ;; Checking for collision with bullets is actually way faster if after an ;; update we save tile coordinates for each enemy. For this, we only need to - ;; save the tile coordinates, but we actually span 4 bytes per enemy. That's - ;; because of padding: we are re-using the 'Enemies::zp_pool_index' variable - ;; to index both the pool and this buffer. Hence, identifying an enemy by - ;; 'zp_pool_index' works in both buffers. This is extremely useful so - ;; bullets don't have to work out two different indeces for two different - ;; structures. Yes, this also means that we are wasting away 6 bytes of RAM, - ;; but we can work with that. + ;; save the tile coordinates, but notice that we actually span 4 bytes per + ;; enemy. That's because of padding: we are re-using the + ;; 'Enemies::zp_pool_index' variable to index both the pool and this + ;; buffer. Hence, identifying an enemy by 'zp_pool_index' works in both + ;; buffers. This is extremely useful so bullets don't have to work out two + ;; different indeces for two different structures. + ;; + ;; Moreover, each enemy has its own palette, and we take advantage of the + ;; extra space from this structure by also allocating here this + ;; information. And, again, it's convenient for the indexing on base 4. + ;; + ;; In summary, the internal structure for each item of this buffer is: + ;; + ;; | tile Y | tile X | palette | (padding) | + ;; | + ;; |- tile Y/X: tile coordinates for the enemy. + ;; |- palette: the color palette to be applied to the enemy. ;; - ;; Similarly, palettes to be used for each enemy is also allocated here, - ;; just because of the convenience of the indexing on base 4. Here each - ;; enemy has the palette in 'lda zp_current_tiles + 2, x'. CURRENT_TILES_BYTES = ENEMIES_POOL_CAPACITY * 4 zp_current_tiles = $F0 ; asan:reserve CURRENT_TILES_BYTES |
