diff options
author | Astatin <[email protected]> | 2024-08-04 15:49:59 +0900 |
---|---|---|
committer | Astatin <astatin@redacted> | 2024-08-04 15:49:59 +0900 |
commit | e20e0ce42d1c1fc65cea1a655d64f2c9b2efc17a (patch) | |
tree | 0d798e43c2e0becba0807bfec7de6b60e35ab73c | |
parent | 0cb98aa2abb54e0a922ed9e3280e6b67aff5ba6a (diff) |
Scrolling when bunny goes out of center
-rw-r--r-- | RAM_Var_map | 6 | ||||
-rw-r--r-- | bunny.gbasm | 57 | ||||
-rw-r--r-- | main.gbasm | 2 | ||||
-rw-r--r-- | print.gbasm | 18 | ||||
-rw-r--r-- | tiles.gbasm | 31 |
5 files changed, 105 insertions, 9 deletions
diff --git a/RAM_Var_map b/RAM_Var_map index fdcdc0f..2399897 100644 --- a/RAM_Var_map +++ b/RAM_Var_map @@ -1,6 +1,8 @@ -FF80 = Bunny X position (in px) -FF81 = Bunny Y position (in px) +FF80 = Bunny X position (on the screen in px) +FF81 = Bunny Y position (on the screen in px) FF82 = Current Button Direction (Up = 1, Right = 2, Down = 3, Left = 4) FF83 = Current Sprite Direction (Moving) FF84 = Px step inside of grid (0x00 to 0x0f) FF85 = Last Sprite Direction +FF86 = Bunny X position (in tiles) +FF87 = Bunny Y position (in tiles) diff --git a/bunny.gbasm b/bunny.gbasm index 62ee751..9e80bef 100644 --- a/bunny.gbasm +++ b/bunny.gbasm @@ -1,7 +1,7 @@ Initialize_Bunny: - LD A, $20 + LD A, $50 LD ($80), A - LD A, $20 + LD A, $50 LD ($81), A RET @@ -27,32 +27,77 @@ Move_Bunny: Move_Bunny.check_direction_end: BIT 1, A - JR NZ, =Move_Bunny.vertical_move + JR NZ, =Move_Bunny.vertical_px_move - Move_Bunny.horizontal_move: + Move_Bunny.horizontal_px_move: LD A, ($81) ADD B + CP $30 + JR C, =Move_Bunny.horizontal_px_move.scrolling_fallback + CP $71 + JR NC, =Move_Bunny.horizontal_px_move.scrolling_fallback LD ($81), A JP =Move_Bunny.check_end_of_movement + Move_Bunny.horizontal_px_move.scrolling_fallback: + LD A, ($43) + ADD B + LD ($43), A + JP =Move_Bunny.check_end_of_movement - Move_Bunny.vertical_move: + + Move_Bunny.vertical_px_move: LD A, ($80) ADD B + CP $30 + JR C, =Move_Bunny.vertical_px_move.scrolling_fallback + CP $71 + JR NC, =Move_Bunny.vertical_px_move.scrolling_fallback LD ($80), A + JP =Move_Bunny.check_end_of_movement + Move_Bunny.vertical_px_move.scrolling_fallback: + LD A, ($42) + ADD B + LD ($42), A + JP =Move_Bunny.check_end_of_movement Move_Bunny.check_end_of_movement: + LD A, ($84) + INC A AND $0f LD ($84), A JR NZ, =Move_Bunny.end LD ($83), A + LD A, ($85) + DEC A + + BIT 1, A + JR NZ, =Move_Bunny.vertical_tile_move + + Move_Bunny.horizontal_tile_move: + LD A, ($86) + ADD B + LD ($86), A + JP =Move_Bunny.end + + Move_Bunny.vertical_tile_move: + LD A, ($87) + ADD B + LD ($87), A Move_Bunny.end: RET Display_Bunny: ; X position in $81, Y position in $80 + LD A, ($86) + LD HL, $9800 + CALL =Print_8bit + + LD A, ($87) + LD HL, $9820 + CALL =Print_8bit + LD A, ($81) LD B, A - LD A, ($80) LD C, A LD A, ($84) @@ -2,6 +2,7 @@ Entrypoint: CALL =Load_Tile + CALL =Load_Number_Font CALL =Initialize_Bunny EI @@ -16,5 +17,6 @@ VBLANK_Entrypoint: RET .INCLUDE "tiles.gbasm" +.INCLUDE "print.gbasm" .INCLUDE "bunny.gbasm" .INCLUDE "buttons.gbasm" diff --git a/print.gbasm b/print.gbasm new file mode 100644 index 0000000..e5bb898 --- /dev/null +++ b/print.gbasm @@ -0,0 +1,18 @@ +Print_8bit: ; Number in A, Memory Tilemap position in HL + PUSH AF + PUSH BC + + LD C, A + SWAP A ; We start by the highest nibble + AND $0f + OR $10 + LD (HL+), A + + LD A, C + AND $0f ; Then the lowest + OR $10 + LD (HL+), A + + POP BC + POP AF + RET diff --git a/tiles.gbasm b/tiles.gbasm index f69a87d..cd37801 100644 --- a/tiles.gbasm +++ b/tiles.gbasm @@ -5,6 +5,24 @@ Tile_Image_Data: .DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $c0, $c0 .DB $34, $f4, $ce, $3a, $fe, $0a, $fc, $04, $bc, $c4, $5c, $64, $88, $f8, $f0, $f0 +Number_Font_Data: + .DB $00, $38, $4c, $c6, $c6, $64, $38, $00 ; 0 + .DB $00, $18, $38, $18, $18, $18, $7e, $00 ; 1 + .DB $00, $7c, $c6, $0e, $7c, $e0, $fe, $00 ; 2 + .DB $00, $7e, $0c, $38, $06, $c6, $7c, $00 ; 3 + .DB $00, $1c, $3c, $6c, $cc, $fe, $0c, $00 ; 4 + .DB $00, $fc, $80, $fc, $06, $c6, $7c, $00 ; 5 + .DB $00, $7c, $c0, $fc, $c6, $c6, $7c, $00 ; 6 + .DB $00, $fe, $c6, $0c, $18, $30, $30, $00 ; 7 + .DB $00, $7c, $c6, $7c, $c6, $c6, $7c, $00 ; 8 + .DB $00, $7c, $c6, $c6, $7e, $06, $7c, $00 ; 9 + .DB $00, $3c, $46, $46, $7e, $46, $46, $00 ; A + .DB $00, $7c, $46, $7c, $46, $46, $7c, $00 ; B + .DB $00, $3c, $62, $60, $60, $62, $3c, $00 ; C + .DB $00, $7c, $62, $62, $62, $62, $7c, $00 ; D + .DB $00, $7e, $60, $7c, $60, $60, $7e, $00 ; D + .DB $00, $7e, $60, $7c, $60, $60, $60, $00 ; D + Load_Tile: LD HL, $8010 LD DE, =Tile_Image_Data @@ -19,4 +37,15 @@ Load_Tile: JR NZ =Load_Tile.loop0 RET - +Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x19 + LD HL, $8100 + LD DE, =Number_Font_Data + LD B, $80 + + Load_Number_Font.loop: + LD A, (DE) + LD (HL+), A + LD (HL+), A + INC DE + DEC B + JR NZ, =Load_Number_Font.loop |