• entries
104
102
• views
259743

# A C64 Game - Step 97

1843 views

And here's a little gameplay update, the bats. The diagonal movement was too predictable, so now there's more randomness to it.

The bat will move in curves. On every end of a curve the new direction will be decided randomly. Two tables are enough, however due to the C64 using two bit complement negative values are annoying to handle. Therefor I went the naive route and simply added code for every case. Ugly, but it works

;------------------------------------------------------------
;simply move diagonal
;------------------------------------------------------------
!zone BehaviourBatDiagonal
BehaviourBatDiagonal
jsr HandleHitBack
beq .NoHitBack

rts

.RandomDir
jsr GenerateRandomNumber
and #$07 sta SPRITE_DIRECTION,x inc SPRITE_DIRECTION,x lda #0 sta SPRITE_MOVE_POS,x rts .NoHitBack lda DELAYED_GENERIC_COUNTER and #$03
bne .NoAnimUpdate
inc SPRITE_ANIM_POS,x
lda SPRITE_ANIM_POS,x
and #$03 sta SPRITE_ANIM_POS,x tay lda BAT_ANIMATION,y sta SPRITE_POINTER_BASE,x .NoAnimUpdate lda SPRITE_DIRECTION,x beq .RandomDir cmp #1 beq .MoveCCWWN cmp #2 beq .MoveCCWSW cmp #3 beq .MoveCCWES cmp #4 beq .MoveCCWNE cmp #5 bne + jmp .MoveCWWS + cmp #6 bne + jmp .MoveCWNW + cmp #7 bne + jmp .MoveCWEN + cmp #8 bne + jmp .MoveCWSE + .NextStep inc SPRITE_MOVE_POS,x lda SPRITE_MOVE_POS,x cmp #16 bne + lda #0 sta SPRITE_DIRECTION,x sta SPRITE_MOVE_POS,x + rts .MoveCCWWN ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveUp ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveRight jmp .NextStep .MoveCCWSW ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveLeft ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveUp jmp .NextStep .MoveCCWES ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveDown ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveLeft jmp .NextStep .MoveCCWNE ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveRight ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveDown jmp .NextStep .MoveCWWS ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveDown ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveRight jmp .NextStep .MoveCWNW ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveLeft ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveDown jmp .NextStep .MoveCWEN ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveUp ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveLeft jmp .NextStep .MoveCWSE ldy SPRITE_MOVE_POS,x lda PATH_CURVE,y sta PARAM3 jsr .TryMoveRight ldy SPRITE_MOVE_POS,x lda PATH_CURVE_R,y sta PARAM3 jsr .TryMoveUp jmp .NextStep .Blocked lda #0 sta SPRITE_DIRECTION,x rts .TryMoveUp beq + jsr ObjectMoveUpBlocking beq .Blocked dec PARAM3 jmp .TryMoveUp + rts .TryMoveDown beq + jsr ObjectMoveDownBlocking beq .Blocked dec PARAM3 jmp .TryMoveDown + rts .TryMoveLeft beq + jsr ObjectMoveLeftBlocking beq .Blocked dec PARAM3 jmp .TryMoveLeft + rts .TryMoveRight beq + jsr ObjectMoveRightBlocking beq .Blocked dec PARAM3 jmp .TryMoveRight + rts The table are simple delta updates per frame, one being the reverse of the other: PATH_CURVE !byte 0 !byte 0 !byte 1 !byte 0 !byte 0 !byte 1 !byte 0 !byte 1 !byte 0 !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 PATH_CURVE_R !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 !byte 1 !byte 0 !byte 1 !byte 0 !byte 1 !byte 0 !byte 0 !byte 1 !byte 0 !byte 0  The other thing is a little fix for a bug I found with the vanishing bats for the last portal stages. The bats could appear outside the playing area. The fix are two border values for left and right which will be set to be farther inside the screen if a portal level is run:  ;set default lda #10 sta SPAWN_LEFT_BORDER lda #30 sta SPAWN_RIGHT_BORDER ;adjust spawn border on portal level lda LEVEL_CONFIG and #$04
beq +

lda #15
sta SPAWN_LEFT_BORDER
lda #25
sta SPAWN_RIGHT_BORDER

+

...and adjust the spawn code inside BehaviourBatVanishing:

          ;position diagonal above/below player
lda SPRITE_CHAR_POS_X
cmp #SPAWN_LEFT_BORDER

;was #10
bcc .SpawnOnRight
cmp #SPAWN_RIGHT_BORDER

;was #30
bcs .SpawnOnLeft

Doesn't the 6502 just use the same two's complement used in pretty much all modern CPUs? (some specialized DSPs being the only modern exception) I don't see what's so weird about it, in fact the whole point is that they can be treated the same as unsigned numbers for a lot of operations.

Yeah it does, but having only the MSB set as a negative flag would make working with it easier. At least for that particular use :)

You could use BPL or BMI to check the flag and if BMI would be branched simply AND #\$7f the value to have the result.

Two's complement is however really nice to simply "add" negative values.

## Create an account

Register a new account