Movement of the player a few tiles
Posted: Wed Sep 23, 2015 1:21 pm
How to make to move the whole area and not one piece of it?
Code: Select all
;(in the main game engine)
ReadRight:
lda $4016
and #%00000001
beq ReadRightDone
lda $0203
clc
adc #$01
sta $0203
jsr UpdatePlayerMetaSprite
ReadRightDone:
...
...
...
rti ;exit NMI
;(outside game loop)
UpdatePlayerMetaSprite:
lda $0200 ;first sprite's Y position
sta $0204 ;same as second sprite's Y position
clc
adc #$08 ;8 pixels down
sta $0208 ;third sprite's Y position
sta $020C ;same as fourth sprite's Y position
lda $0203 ;first sprite's X position
sta $020B ;same as third sprite's X position
clc
adc #$08 ;8 pixels to the right
sta $0207 ;second sprite's X position
sta $020F ;fourth sprite's X position
rts ;go back to where we were when the subroutine was called
Code: Select all
; Metasprite addon lib for PPU.s
; (c) 2014-2015 Peter Santing
;
;
; OAM is always 0x0500 in my engine so place meta sprites there.
; also NEVER TOUCH 0x00 (SPRITE #0)
WRITEBUF EQU $C ; zeropage address counters.
XBUF EQU $D;
add_meta_sprite: ; ($00) = holds metasprite addr.
; $02 = x pos, $03 = y pos.
; meta data is as follows. x, y, tile, bgcolor and attr
; sprite is as follows: y, tile, attr, x
ldx WRITEBUF
ldy #0
- lda $02 ; load x pos.
clc
adc ($00), Y ; add meta x pos.
sta XBUF
iny
lda $03 ; load y pos
clc
adc ($00), Y ; add meta y pos.
sta ($0500), X ; save byte Y
inx
iny
lda ($00), Y ; load tile number.
sta ($0500), x ; save tile number.
inx
iny
lda ($00), Y ; load attribute.
sta ($0500), X ; save attribute.
inx
lda XBUF
sta ($0500), X ; save x position.
iny
inx
lda ($00), Y ; load x pos?
cmp #128 ; if x = 128
bne - ; then end loop
stx WRITEBUF
rts
prep_write_meta_sprites:
lda #$4 ; always ignore spr #0 (hard set for scrollbars, etc)
sta WRITEBUF
rts
done_write_meta_sprites:
lda #0
ldx WRITEBUF
inx ; goto tile.
- sta ($0500), X
inx
inx
inx
inx
cpx #$01
bne -
rts
Code: Select all
spr0:
.db -8, -16, 1, 2, 0, -16, 2, 2, -8, -8, $11, 2
.db 0, -8, $12, 2, -8, 0, $21, 2, 0, 0, $22, 2, 0, 8, $32, 2, 128
Code: Select all
jsr prep_write_meta_sprites
lda #<spr0
sta $00
iny
lda #>spr0
sta $01
lda PLAYERX
sta $02
lda PLAYERY
sta $03
jsr add_meta_sprite
jsr done_write_meta_sprites