- ; collision shapes:
- ; a collision shape is a collection of dots
- ; relative to a sprite
- ; structure:
- ; N: Amount of dots
- ; Y: y position
- ; X: x position
- ; y and x repeat until N is reached
- ; player -> act collision
- ; each sprite will check statically for collision
- ; with the player by using pt -> rec collision
-
- ; act -> act collision
- ; actors should flag their current location in map flags
- ; actors should simply avoid moving onto tiles that are already busy
-
- ; defines a collision header
- ; inputs:
- ; $1: N
-#macro col_head
- .db $1
-#endmacro
-
- ; defines a collsion point
- ; inputs:
- ; $1: y
- ; $2: x
-#macro col_point
- .db $1, $2
-#endmacro
-
-collision_player:
- col_head 1
- col_point 0, 0
-
-
- ; 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
- ; ct_mask: bit mask for flag to check
- ; 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, [de] ; load loop counter
- inc de ; de + 1 = first point y coordinate
-@loop:
- push af
-
- ld a, [de]
- ld l, a
- ld a, [ct_poy]
- add a, l ; a = y + collision y offset
- ld l, a ; store y result in l for now
- inc de ; de++ == x pos
-
- ld a, [de]
- ld h, a
- ld a, [ct_pox]
- add a, h ; a = x + collision x offset
- inc de ; de++ == next y
- push de ; save de for next iteratin
-
- ld d, l ; d = y
- ld e, a ; e = x
-
- call collision_tile
- cp a, 0
- jr nz, @done REL
-
- pop de
- pop af
-
- dec a ; a--
- cp a, 0 ; again if not 0
- jp nz, @loop
-
- ret
-@done:
- ; we need to pop before ret!
- ; the register values
- ; do not matter too much at this point
- ; but a needs to be preserved
- pop de
- pop de
- ret
-
; checks a point
; with a map's meta tile
; if the tile has collision flag set
ret
- ; performs a simple collision check
- ; inputs:
- ; $1: collision table
- ; hl: y/x coordinate
- ; returns:
- ; z/nz -> collision hit or not
-#macro player_collision_check
- ; check collision
- ; 1) save registers
- push hl
- push de
-
- ; 2) hl = player_y already
- ; 3) load correct collision points
- ld de, $1
- call collision_tile_table_check
- pop de
- pop hl
-
- cp a, 0
-#endmacro
-
; update the player
; players do not behave like regular actors
; and are not allocate to the regular