I don't know if I should have just resurrected the old thread, but I figured I would ask more "advanced" questions this time. I was wondering how everyone makes an object go to different pieces of code that correspond to a different action, like if the object is jumping or if it is on the ground. I suppose you could use a jump table, but I guess there isn't really a "definitive" way to do these kind of things. I wrote a code where the player spawns a bullet, and when I spawned the bullet, I wrote a certain number to a register in the bullets object slot. When the bullet code gets jumped to, I load the special register and I offset a jump table by the register which jumps to a certain piece of code that works for the direction of the bullet. I was thinking I could just change the bullet's velocity and check all sides of the screen instead of just the one the bullet is traveling, but the bullet's graphics would be the same and so would everything else including the hit box, so I really don't know.
If it helps, here is the code:
If it helps, here is the code:
Code:
;====================================================================================
;Bullet
;====================================================================================
.proc bullet
rep #$30 ; A=16, X/Y=16
ldx ObjectTable+6,y
jmp (BulletIdentificationTable,x) ;jump to the code that corresponds with the object
.endproc
;====================================================================================
BulletIdentificationTable:
.word bulletright,bulletleft
;====================================================================================
.proc bulletright
lda ObjectTable+2,y
cmp #256
bcs terminate_bullet
clc
adc #$0A
sta ObjectTable+2,y
lda Bullet1MetaspriteTableSize ; Load number of Metasprites
sta MetaspriteCount ; ...and store it in MetaspriteCount
ldx #Bullet1MetaspriteTable ; Offset into MetaspriteTable
stx MetaspriteTableOffset
lda ObjectTable+2,y
sta MetaspriteXPosition
lda ObjectTable+4,y
sta MetaspriteYPosition
stz MetaspriteDirection
jsr start_metasprite ; jump to start_metasprite to build metasprites
rts
terminate_bullet:
lda #$0000
sta ObjectTable,y
rts
.endproc
;====================================================================================
.proc bulletleft
lda ObjectTable+2,y
cmp #256
bcs terminate_bullet
sec
sbc #$0A
sta ObjectTable+2,y
lda Bullet1MetaspriteTableSize ; Load number of Metasprites
sta MetaspriteCount ; ...and store it in MetaspriteCount
ldx #Bullet1MetaspriteTable ; Offset into MetaspriteTable
stx MetaspriteTableOffset
lda ObjectTable+2,y
sta MetaspriteXPosition
lda ObjectTable+4,y
sta MetaspriteYPosition
lda #$0001
sta MetaspriteDirection
jsr start_metasprite ; jump to start_metasprite to build metasprites
rts
terminate_bullet:
lda #$0000
sta ObjectTable,y
rts
.endproc
;Bullet
;====================================================================================
.proc bullet
rep #$30 ; A=16, X/Y=16
ldx ObjectTable+6,y
jmp (BulletIdentificationTable,x) ;jump to the code that corresponds with the object
.endproc
;====================================================================================
BulletIdentificationTable:
.word bulletright,bulletleft
;====================================================================================
.proc bulletright
lda ObjectTable+2,y
cmp #256
bcs terminate_bullet
clc
adc #$0A
sta ObjectTable+2,y
lda Bullet1MetaspriteTableSize ; Load number of Metasprites
sta MetaspriteCount ; ...and store it in MetaspriteCount
ldx #Bullet1MetaspriteTable ; Offset into MetaspriteTable
stx MetaspriteTableOffset
lda ObjectTable+2,y
sta MetaspriteXPosition
lda ObjectTable+4,y
sta MetaspriteYPosition
stz MetaspriteDirection
jsr start_metasprite ; jump to start_metasprite to build metasprites
rts
terminate_bullet:
lda #$0000
sta ObjectTable,y
rts
.endproc
;====================================================================================
.proc bulletleft
lda ObjectTable+2,y
cmp #256
bcs terminate_bullet
sec
sbc #$0A
sta ObjectTable+2,y
lda Bullet1MetaspriteTableSize ; Load number of Metasprites
sta MetaspriteCount ; ...and store it in MetaspriteCount
ldx #Bullet1MetaspriteTable ; Offset into MetaspriteTable
stx MetaspriteTableOffset
lda ObjectTable+2,y
sta MetaspriteXPosition
lda ObjectTable+4,y
sta MetaspriteYPosition
lda #$0001
sta MetaspriteDirection
jsr start_metasprite ; jump to start_metasprite to build metasprites
rts
terminate_bullet:
lda #$0000
sta ObjectTable,y
rts
.endproc