From: Lukas Krickl Date: Wed, 2 Oct 2024 15:31:50 +0000 (+0200) Subject: added basic player movement X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=a917dae21a10b9795c0d4050544501215ae0545a;p=gbrg%2F.git added basic player movement --- diff --git a/src/hw.inc b/src/hw.inc index 3942be3..dc8ac70 100644 --- a/src/hw.inc +++ b/src/hw.inc @@ -14,6 +14,7 @@ #define LCDCF_ON 0b10000000 #define LCDCF_OBJON 0b00000010 #define LCDF_WINDOWON 0b00100000 +#define LCDF_OBJ_SIZE 0b00000100 #define RBGP 0xFF47 #define ROBP0 0xFF48 @@ -33,14 +34,18 @@ #define P1F4 0b00010000 ; get dpad ; buttons -#define BTNDOWN 0x80 -#define BTNUP 0x40 -#define BTNLEFT 0x20 -#define BTNRIGHT 0x10 -#define BTNSTART 0x08 -#define BTNSELECT 0x04 -#define BTNA 0x02 -#define BTNB 0x01 +.def int BTNDOWN = 0x80 +.def int BTNUP = 0x40 +.def int BTNLEFT = 0x20 +.def int BTNRIGHT = 0x10 +.def int BTNSTART = 0x08 +.def int BTNSELECT = 0x04 +.def int BTNA = 0x02 +.def int BTNB = 0x01 + +; obj off-screen offsets +#define OBJ_OFF_X 8 +#define OBJ_OFF_Y 16 ; interrupts ; interrupt flag diff --git a/src/input.s b/src/input.s index b14edfd..bc13f07 100644 --- a/src/input.s +++ b/src/input.s @@ -1,3 +1,17 @@ +#macro input_just + +#endmacro + + ; checks for a button press + ; inputs: + ; $1 BUTTON + ; returns: + ; a: button state +#macro input_held + ld a, [curr_inputs] + and a, $1 +#endmacro + ; poll inputs ; returns: ; new inputs in [curr_inputs] diff --git a/src/player.s b/src/player.s index 43401ef..ac4d0b9 100644 --- a/src/player.s +++ b/src/player.s @@ -1,3 +1,9 @@ +; player gets 3 sprite slots in a row +.def int PLAYER_SPRITE1 = shadow_oam + 0 + +.def int PLAYER_TILE_IDLE1 = 0x04 +.def int PLAYER_TILE_IDLE2 = 0x14 + ; update the player ; players do not behave like regular actors ; and are not allocate to the regular @@ -5,4 +11,63 @@ ; inputs: ; hl: pointer to player memory player_update: + ; update + + ; input handling + input_held BTNDOWN + jr z, @notdown REL + + ld de, player_y + add hl, de + ld a, [hl] + inc a + ld [hl], a +@notdown: + + + ; drawing + ; d: player_y + ; e: player_x + + ld a, [hl+] + ld d, a + ld a, [hl+] + ld e, a + + ; obj 1 + ld hl, PLAYER_SPRITE1 + + ; set player position + ld a, d ; y + add a, OBJ_OFF_Y + + ld [hl+], a + ld a, e ; x + add a, OBJ_OFF_X + ld [hl+], a + + ; idel tile 1 + ld a, PLAYER_TILE_IDLE1 + ld [hl+], a + + ; flags + xor a, a + ld [hl+], a + + ; obj 2 + ld a, d ; y + add a, OBJ_OFF_Y + ld [hl+], a + ld a, e ; x + add a, 8 + OBJ_OFF_X + ld [hl+], a + + ; idle tile 2 + ld a, PLAYER_TILE_IDLE2 + ld [hl+], a + + ; flags + xor a, a + ld [hl+], a + ret diff --git a/src/video.s b/src/video.s index 4d4bf54..f08c3ae 100644 --- a/src/video.s +++ b/src/video.s @@ -35,7 +35,7 @@ lcd_off: ; turns on the lcd lcd_on: - ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON + ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDF_OBJ_SIZE ld [RLCD], a ret @@ -52,6 +52,13 @@ video_init: ; set up bgp ld a, 0b11100100 ld [RBGP], a + + ld a, 0b11100100 + ld [ROBP0], a + + ld a, 0b11011000 + ld [ROBP1], a + ret ; copies tilest0 and tileset1 to diff --git a/tiles/tileset0.inc b/tiles/tileset0.inc index 3d464da..f234e97 100644 --- a/tiles/tileset0.inc +++ b/tiles/tileset0.inc @@ -36,21 +36,21 @@ .chr 00000000 ; tile 4 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00033333 +.chr 00322222 +.chr 03222222 +.chr 03222222 +.chr 03221222 +.chr 03221222 +.chr 03221222 ; tile 5 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 03221222 +.chr 03221222 +.chr 03222222 +.chr 03222222 +.chr 03222222 +.chr 00322222 +.chr 00033333 .chr 00000000 ; tile 6 .chr 00000000 @@ -180,21 +180,21 @@ .chr 00000000 ; tile 20 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333000 +.chr 22222300 +.chr 22222230 +.chr 22222230 +.chr 21222230 +.chr 21222230 +.chr 21222230 ; tile 21 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 21222230 +.chr 21222230 +.chr 22222230 +.chr 22222230 +.chr 22222230 +.chr 22222300 +.chr 33333000 .chr 00000000 ; tile 22 .chr 00000000