map: wip player scrolling
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 16:57:20 +0000 (17:57 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 16:57:20 +0000 (17:57 +0100)
src/map.s
src/player.s
src/tiles.s
src/video.s
src/wram.s

index e8afa8857b0acb09bce0ca2d116b3b2857abb436..f04823e9d949a508bc7fb0749487a488c029d798 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -33,11 +33,6 @@ map_load:
        call player_init
        call ui_init
 
-       ; initial scroll value 
-       ; to make bottom of scrn0 visible
-       ld a, 144
-       ld [scroll_y], a
-
        ret
        
        ; loads a tileset
index 8fb8662393467e021aa974e6f7cab4bbf8240fad..9a98f0efbc61897529236ee6926b144889dd0aa6 100644 (file)
@@ -4,10 +4,15 @@
 
        ; sets up the player actor
 player_init:
+       xor a, a
+       ld [player+act_pos_y], a
+       ld [player+act_pos_x], a
+       
        ret
        
        ; updates the special player actor
-player_update:
+player_update: 
+       call scroll_center_player
        ret
        
        ; draws player at current location
@@ -16,10 +21,29 @@ player_draw:
        call oamalloc
        
        ; write left cursor
-       ld a, 100
+
+       ; calculate y pos
+       ld a, [scroll_y]
+       ld b, a ; b = scroll y
+
+       ld a, [player+act_pos_y]
+       add a, OBJ_OFF_Y
+       sub a, b
+       ; store y for second obj
+       ld [tmp_y], a
 
        ; write y
        ld [hl+], a
+       
+       ; calculate x pos
+       ld a, [scroll_x]
+       ld b, a
+       sub a, b
+
+       ld a, [player+act_pos_x]
+       add a, OBJ_OFF_X
+       ; store x for second obj
+       ld [tmp_x], a
 
        ; write x
        ld [hl+], a
@@ -36,11 +60,12 @@ player_draw:
 
 
        ; write y
-       ld a, 100
+       ld a, [tmp_y]
        ld [hl+], a
 
        ; write x
-       ld a, 108
+       ld a, [tmp_x]
+       add a, 8
        ld [hl+], a
 
        ; write tile
index 4f1c9dac967f6dab27d37c9cb0c9da0fb5b2a2fb..6327de74a117cd9f65bb0683bc17b00a3ef5d078 100644 (file)
@@ -1,7 +1,7 @@
        ; tile definitions
 
 #define GFX_GRASS 0x48
-#define GFX_PHIVE 0x4A
+#define GFX_PHIVE 0x62
 #define GFX_EHIVE 0x4A
 #define GFX_FOOD 0x03
        
index 1900c0d267ee2025582da43b69b49dd3cb44edf3..f421c6cbaa846c0b81ca79d5765370a6b3531e43 100644 (file)
@@ -156,6 +156,18 @@ video_wait_n_frames:
     or a, c
   jr nz, video_wait_n_frames REL
   ret
+       
+       ; centers scroll on player
+       ; but does not allow camera to wrap
+scroll_center_player:
+       ld a, [player+act_pos_y]
+       sub a, 32
+       ld [scroll_y], a
+
+       ld a, [player+act_pos_x]
+       sub a, 32
+       ld [scroll_x], a
+       ret
 
 
   ; loads tilesets
index 1e7bc8879440264f7184bc7bf503580a551cfb58..d099a18cb423e2d2dfb3ebe095f0834f5a5dee47 100644 (file)
@@ -68,6 +68,9 @@ srand: .adv 2
 
 player: .adv act_size
 enemy: .adv act_size
+
+tmp_y: .adv 1
+tmp_x: .adv 1
        
        ; current map ptr
 map: .adv 2