Writing a NES game day 11, Fire!

pablosoifer1

Draculinio

Posted on July 23, 2023

Writing a NES game day 11, Fire!

Now that I have my first version of the character, and he can move, I need to make him so something else. Remember that you can check the status of the code in my github repo.
I created a simple sprite for bullet which is a 2 colors circle (redoing sprites into something better is a problem for future me) and created 3 variables for this: sx (shoot in x axis), sy (shoot in y axis) for the position of the shoot every frame and a shootStatus to see if it is actually firing something or not (maybe in the future I can delete this variable and use a special value in sx and clean 1 byte?)
For making this work, I added the shoot behaviour to button B in the engine sector:

bButton:
    CMP #%01000000
    BNE bDone
    LDA #$01
    STA shootStatus
    LDA p2x
    STA sx
    LDA p1y
    STA sy
bDone:

Enter fullscreen mode Exit fullscreen mode

After that, I see if the shooting is active and I jump to a shooting "function"

;Shooting update
LDA #$01
CMP shootStatus
BNE :+
JMP shoot
:
Enter fullscreen mode Exit fullscreen mode

And then the shoot part:

shoot:
    ;for now it will only shoot to the right.
    LDA sx
    CLC
    ADC #01
    STA sx
    RTS
Enter fullscreen mode Exit fullscreen mode

As you can see I place a lot of comments, the code in assembly is not that "self readable" as other languages.

Now, I have to update the sprites refresh to make all this visible.

LDA sy
    STA $0210
    LDA sx
    STA $0213
    LDA #$00
    STA $0212
    LDA #$01
    CMP shootStatus
    BEQ isShooting
    LDA #$FC
    STA $0211
    JMP shootDone
    isShooting:
    LDA #$30
    STA $0211
    shootDone:
Enter fullscreen mode Exit fullscreen mode

As it is a one tile sprite, I only need 4 positions in memory, so I assigned it the $0210 to $0213 space.

Image description

(tomorrow we will talk about the other thing that appears on the screen)

On the other hand, to keep me MORE motivated I am playing some nes games lately. Not only Final Fantasy in japanese to learn, but I started Rockman (Megaman)

Image description

If you have a child that loves video games, show them the old Nintendo games, for them this all will be in nightmare level.

💖 💪 🙅 🚩
pablosoifer1
Draculinio

Posted on July 23, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related