tokumaru wrote:
I don't see anything wrong with this piece of code. How exactly are the bullets misbehaving? How are you creating and destroying the bullets? Are you initializing bullet_speed properly before firing any bullets?
Thank for your help guys on making sure the loop is proper ASM, I am still not confident when writing ASM, but I guess I am getting better now. So more context on the issue.
Main issue is the bullet is not showing on screen. I would expect 1 bullet to be drawn and move to the right. Its all I am looking for now.
(This is what I am working on, a Zelda-Mad God inspired game)
;
; Init all bullets as off at the start of a level
;
LDA #$00
STA bullet_index
.next_bullet
LDA bullet_index
TAX
LDA #$02
STA bullet_speed, x
LDA #$80
STA bullet_y, x
LDA #$80
STA bullet_x, x
LDA bullet_update_constants, x
TAX
LDA #INACTIVE
STA SPRITE_RAM_BULLETS, x
INC bullet_index
LDA bullet_index
CMP #ALL_MAX_BULLETS
BNE .next_bullet
------------------------------------------
;------------------------
; FireBullet()
; NOTE: this is triggering correctly on button press...
;------------------------
FireBullet:
LDA entity_x
STA bullet_x
LDA entity_y
STA bullet_y
RTS
;-------------------------------------------------------------------------------
; UpdateBulletsPosition()
; PPU position update for bullets
;-------------------------------------------------------------------------------
UpdateBulletsPosition: ; This seems to be not working
LDA #$00
STA bullet_index
.next_bullet
LDY bullet_index
LDA bullet_y, y
CMP #INACTIVE
BNE .skip_bullet
LDA bullet_update_constants, y
TAX
LDA bullet_x, y
STA SPRITE_RAM_BULLETS + 3, x
LDA bullet_y, y
STA SPRITE_RAM_BULLETS, x
.skip_bullet
INC bullet_index
LDA bullet_index
CMP #ALL_MAX_BULLETS
BNE .next_bullet
RTS
;----------------------------------------------------------------------
;-----------------------START MAIN PROGRAM-----------------------------
;----------------------------------------------------------------------
Forever:
INC sleeping ;wait for NMI
.loop
LDA sleeping
BNE .loop ;wait for NMI to clear out the sleeping flag
LDA #$01
STA updating_background ;this is for when you are changing rooms or something, not really needed here
;it will skip the NMI updates so as not to mess with your room loading routines
LDA level_loaded
CMP #$00
BNE .no_level_load_request
JSR LoadRoom
INC level_loaded
.no_level_load_request
; Update random number ticker vars
INC random_dir
LDA random_dir
CMP #$04
BNE .no_update_needed
LDA #$00
STA random_dir
.no_update_needed
JSR ReadController1 ; get the current button data for player 1
JSR ProcessUserInput
JSR UpdateEnemies
JSR UpdateBullets
JSR CheckItemCollisions
JSR CheckEnemyCollisions
JSR CheckEntityBackgroundCollision
; PPU sprite update (position and possible tile attributes?)
JSR UpdateMetaSpritesPosition
JSR UpdateBulletsPosition
LDA #$00
STA updating_background
.end_loop
JMP Forever ;jump back to Forever, and go back to sleep