User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

base:simple_software_sprite_to_background_collision [2015-10-07 22:13] (current)
ftc created
Line 1: Line 1:
 +====== Simple Software to Background collision ======
 +by Achim
 +To check wether a specific object has been hit or not, the correct screen position has to be calculated.
 +Use sprite-X to calculate the screen column:
 +lda spriteX     //16bit subtraction
 +sbc #$18 //x-offset, visible screen area starts at x=$18
 +sta tmp1
 +lda spriteMSB //MSB in bit 0 of spriteMSB
 +sbc #$00        
 +lsr             //MSB -> carry
 +lda tmp1
 +ror //9bit value : 8
 +sta column
 +If you're code uses the 2*x trick to simplify MSB-handling, an 8bit subtraction
 +and a division by 4 is needed.
 +Use sprite-Y to calculate number of screen rows:
 +lda spriteY
 +sbc #$32        //y-offset, visible screen area starts at y=$32
 +lsr //8bit value : 8
 +sta numberrows
 +Use "numberrows" to fetch actual screen row from a lookup table:
 +        ldx numberrows
 +        lda screenmemlowbyte,x //=lookup table for low bytes of screen rows
 +        sta tmp0 //zp address
 +        lda screenmemhibyte,x //=lookup table for hi bytes
 +        sta tmp1 //zp address+1
 + ldy column
 + lda (tmp0),y         //read char value
 + ...
 +The result is the top left screen position of the sprite.
 +There are two options to check the other eight possible screen positions underneath the sprite (or any other position next to the sprite):
 +  - Use different x- and y-offset values for subtraction. (Check this program: {{|}}, hit "x" and "y" to change offset values, Sprite located at $2000)
 +  - Manipulate "column" to reach next two screen rows and next two screen columns: column+40=next screen row, column+80=lowest screen row, column+1=top middle of sprite, column+2=top right of sprite etc.
base/simple_software_sprite_to_background_collision.txt ยท Last modified: 2015-10-07 22:13 by ftc