From: Lukas Krickl Date: Mon, 14 Oct 2024 11:59:09 +0000 (+0200) Subject: wip: collision bounds checking for tiles X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5c04db0e4e8cbe223276c4fbb3de9492426faa85;p=gbrg%2F.git wip: collision bounds checking for tiles --- diff --git a/src/collision.s b/src/collision.s index 2b9e5d7..91dcf8e 100644 --- a/src/collision.s +++ b/src/collision.s @@ -32,37 +32,63 @@ collision_player: collision_tile_lut: .rep cti, ROOM_H, 1, .db cti * ROOM_W - ; collision-tile call - ; but using static - ; params in wram: - ; inputs: - ; ct_pty/ct_ptx: collision tile y/x - ; ct_pox/ct_poy: position y/x -collision_tile_stat: - ld a, [ct_pty] - ld b, a ; b = pty - - ld a, [ct_ptx] - ld c, a ; c = ptx + ; checks an entire collision table based on an original point + ; and a ptr to a collision point table + ; inputs: + ; hl: ptr to y/x position + ; de: collision point table + ; returns: + ; a = 0 -> no collision + ; a = 1 -> collision +collision_tile_table_check: + ld a, [hl+] + ld [ct_poy], a ; y buffer + ld a, [hl] + ld [ct_pox], a ; x buffer - ld a, [ct_poy] - ld d, a ; d = poy + ld a, [de] ; load loop counter + inc de ; de + 1 = first point y coordinate +@loop: + push af + push de + push hl + ld a, [de] + ld l, a ld a, [ct_poy] - ld e, a ; e = pox + add a, l ; a = y + collision y offset + inc de + + ld a, [de] + ld h, a + ld a, [ct_pox] + add a, h ; a = x + collision x offset + + ld d, l + ld e, h + + call collision_tile + + pop af + pop de + pop hl + + dec a ; a-- + cp a, 0 ; again if not 0 + jp nz, @loop + + ret - ; checks a collision ptr + ; checks a point ; with a map's meta tile ; if the tile has collision flag set ; returns 1 otherwise 0 ; inputs: - ; b/c: collision point (y/x) ; d : y pos ; e : x pos ; returns: ; a = 0 -> no collision ; a = 1 -> collision - ; hl += 2 collision_tile: ; y pos / 16 -> tile pos sra d ; / 2 diff --git a/src/wram.s b/src/wram.s index 376b85f..9e7e8de 100644 --- a/src/wram.s +++ b/src/wram.s @@ -122,8 +122,6 @@ game_over_timer: .adv 1 game_mode: .adv 1 - ; collision tile params -ct_pty: .adv 1 -ct_ptx: .adv 1 + ; collision tile tmp values ct_poy: .adv 1 ct_pox: .adv 1