diff --git a/png/player.png b/png/player.png index 645c4f6..e151969 100644 Binary files a/png/player.png and b/png/player.png differ diff --git a/src/player.s b/src/player.s index 56a3bb6..d6582e4 100644 --- a/src/player.s +++ b/src/player.s @@ -12,6 +12,8 @@ spriteData: INCBIN "png/player.2bpp" DEF SPRITE_IDX EQU 32 +DEF SPRITE_WIDTH EQU 2 +DEF SPRITE_HEIGHT EQU 2 Player_Init:: ld a, 8 @@ -20,11 +22,12 @@ Player_Init:: ld bc, _VRAM8000 + SPRITE_IDX * 16 ld hl, spriteData - ld d, 16 + ld d, 16 * (SPRITE_WIDTH * SPRITE_HEIGHT) call memcpy + ; top left ld hl, _OAM - ld a, 144-8 + ld a, 144-8-8 ld [hli], a ld a, 8 ld [hli], a @@ -33,9 +36,39 @@ Player_Init:: xor a ld [hli], a + ; top right + ld a, 144-8-8 + ld [hli], a + ld a, 8 + 8 + ld [hli], a + ld a, SPRITE_IDX + 1 + ld [hli], a + xor a + ld [hli], a + + ; bottom left + ld a, 144-8 + ld [hli], a + ld a, 8 + ld [hli], a + ld a, SPRITE_IDX + 2 + ld [hli], a + xor a + ld [hli], a + + ; bottom right + ld a, 144-8 + ld [hli], a + ld a, 8 + 8 + ld [hli], a + ld a, SPRITE_IDX + 3 + ld [hli], a + xor a + ld [hli], a + ld bc, _OAMRAM ld hl, _OAM - ld d, 4 + ld d, 4 * (SPRITE_WIDTH * SPRITE_HEIGHT) call memcpy ret @@ -59,12 +92,41 @@ Player_Update:: ; check for right boundary ld hl, _OAM + 1 ld a, [hl] - cp 160 + cp 160 - 8 jr nc, .done - ; Update x-position and set x-flip = false + ; update top left sprite + inc [hl] + inc hl + ld [hl], SPRITE_IDX + inc hl + res 5, [hl] + + ; update top right sprite + inc hl + inc hl + inc [hl] + inc hl + ld [hl], SPRITE_IDX + 1 + inc hl + res 5, [hl] + + ; update bottom left sprite + inc hl + inc hl + inc [hl] + inc hl + ld [hl], SPRITE_IDX + 2 + inc hl + res 5, [hl] + + ; update bottom right sprite + inc hl + inc hl inc [hl] - ld hl, _OAM + 3 + inc hl + ld [hl], SPRITE_IDX + 3 + inc hl res 5, [hl] .left: @@ -79,9 +141,38 @@ Player_Update:: cp 9 jr c, .done - ; Update x-position and set x-flip = true + ; update top left sprite + dec [hl] + inc hl + ld [hl], SPRITE_IDX + 1 + inc hl + set 5, [hl] + + ; update top right sprite + inc hl + inc hl + dec [hl] + inc hl + ld [hl], SPRITE_IDX + inc hl + set 5, [hl] + + ; update bottom left sprite + inc hl + inc hl + dec [hl] + inc hl + ld [hl], SPRITE_IDX + 3 + inc hl + set 5, [hl] + + ; update bottom right sprite + inc hl + inc hl dec [hl] - ld hl, _OAM + 3 + inc hl + ld [hl], SPRITE_IDX + 2 + inc hl set 5, [hl] .done: diff --git a/src/util.s b/src/util.s index 07705a2..12f858c 100644 --- a/src/util.s +++ b/src/util.s @@ -29,3 +29,25 @@ memset:: dec c jr nz, memset ret + +; Divides a value by 10 (http://homepage.divms.uiowa.edu/~jones/bcd/decimal.html#division) +; @param b Dividend +; @return a Quotient +div10:: + ld a, b + srl a + srl a + add b + srl a + add b + srl a + srl a + srl a + add b + srl a + add b + srl a + srl a + srl a + srl a + ret