Re: A86: Tilemaps and Collision Detection


[Prev][Next][Index][Thread]

Re: A86: Tilemaps and Collision Detection




In a message dated 4/22/00 11:18:16 AM Eastern Daylight Time, 
zoneti@tinews.net writes:

> I was looking at the tilemaps section over at 86 Central and went to put
>  together a little demo for an RPG I'm working on. I needed the guy to walk
>  around and stop if he hit a block. I tried ACZ's routines but couldn't put
>  together a working example of how to use them. The little guy just walks
>  around through the blocks :) He does however stop if you try to go left at
>  the very top or bottom row of the screen as well as stopping if you try to
>  go off the top or bottom of the screen. Can anyone put together an example
>  for me to see how to use these routines? (http://ti86.acz.org). Thanks.

The trick to collision detection is the GetTile subroutine.  For example:

mainloop:
  call _getcsc
  dec a ;K_DOWN
  jr z,move_down
  dec a ;K_LEFT
  jr z,move_left
  dec a ;K_RIGHT
  jr z,move_right
  dec a ;K_UP
  jr z,move_up
  ;...


move_right:
  ld bc,(coords)
  inc b   ;increase x
  jr move_tile

move_left:
  ld bc,(coords)
  dec b  ;decrease x
  jr move_tile

move_down:
  ld bc,(coords)
  inc c  ;increase y
  jr move_tile

move_up:
  ld bc,(coords)
  dec c  ;decrease y

move_tile:
  bit 7,b  ;x>=128 or <0
  jr nz,mainloop
  ld a,c
  cp 64  ;y>=64 or <0
  jr nc,mainloop
  push bc
  call GetTile
  pop bc
  ld a,(hl)
  or a  ;check if a clear tile
  jr nz,mainloop
  ld (coords),bc  ;save new coords
  jr mainloop


----
Jonah Cohen
<ComAsYuAre@aol.com>
http://jonah.ticalc.org



Follow-Ups: