DEV Community

Draculinio
Draculinio

Posted on

Writing a NES game day 12, The Aqualate!

Now that the main character can shoot, it should shoot something, so I need to create enemies.
When I was starting, my 7 year old daughter passed by my computer, asked me what I was doing and told me that she wanted to create the testing monster.

Image description

She called this "The Aqualate". I needed this to be on screen and needed to make it move on its own, so I needed to create some of this beautiful code.

First of all, I need 3 variables, one for the position in X, one for the position in Y and one for the stage of movement it is (we will go over it briefly).

 ax: .res 1 ; Aqualate x position
 ay: .res 1 ; Aqualate y position
 al: .res 1 ; Aqualate in the loop
Enter fullscreen mode Exit fullscreen mode

For now I put some initial values to place it somewhere

LDA #$50
STA ax
LDA #$80
STA ay
Enter fullscreen mode Exit fullscreen mode

Now, I need a fixed pattern for the enemy, let's say an easy one, so let's make the Aqualate move in squares. Here comes the third variable into the game. The position status, the position has 4 status ($00, $01, $02 and $03), every status has a place and in every cicle the al variable increments in one and changes the place of ay and ax. If incrementing the variable results in $04, then it goes to $00 again.

aqualate:
    LDA #$00 ;in the original position x+1, y-1
    CMP al
    BNE :+
    LDA ax
    CLC
    ADC #05
    STA ax
    LDA ay
    SEC
    SBC #05
    STA ay
    :
    LDA #$01 ;position 2 x+1, y+1
    CMP al 
    BNE :+
    LDA ax
    CLC
    ADC #05
    STA ax
    LDA ay
    CLC
    ADC #05
    STA ay
    :
    LDA #$02 ;position 3 x-1, y+1
    CMP al
    BNE :+
    LDA ax
    SEC
    SBC #05
    STA ax
    LDA ay
    CLC
    ADC #05
    STA ay
    :
    LDA #$03 ; position 4 x-1, y-1
    CMP al
    BNE :+
    LDA ax
    SEC
    SBC #05
    STA ax
    LDA ay
    SEC
    SBC #05
    STA ay
    :
    ;update
    LDA al
    CLC
    ADC #01
    STA al
    LDA #05
    CMP al
    BNE :+
    LDA #00
    STA al
    :
    RTS
Enter fullscreen mode Exit fullscreen mode

And now in the engine zone, in every cicle I need to call this function

JMP aqualate
Enter fullscreen mode Exit fullscreen mode

The last part is placing it into the screen, for that I assigned the aqualate the addresses from $0214 to $0217. So I only need to put this into the updatesprites function

;Aqualate ($0214 to $0217)
    LDA ay
    STA $0214
    LDA #$02
    STA $0215
    LDA #$00
    STA $0216
    LDA ax
    STA $0217
Enter fullscreen mode Exit fullscreen mode

Image description

And about Megaman 1, well, I could beat Cutman, but the rest is terribly hard. I have no skills :(

Top comments (0)