Advertisement
Zeda

ACag's Routine

Feb 4th, 2015
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define renderDistance 10   ; adjust this to change the render distance
  2. #define priorAngle rcStack+2    ; 1 byte
  3.  
  4.    
  5. engine_raycaster_Init:
  6.     ld de,SlendMapPtr
  7. _raycaster_loopobject
  8.     push de
  9.         inc de
  10.         ld a,(de)
  11.         ld hl,playerPosY
  12.         sub (hl)
  13.         ld c,a
  14.         dec de
  15.         ld a,(de)
  16.         ld hl,playerPosX
  17.         sub (hl)
  18.         call _getDistance
  19.         ld de,(renderDistance)
  20.         sbc hl,de \ add hl,de
  21.         jr nc,_raycaster_nextobject
  22.         ld a,l
  23.         push af                         ; distance
  24.             ld a,(de)
  25.             ld hl,playerPosX
  26.             sub (hl)
  27.             ld b,a
  28.             inc de
  29.             ld a,(de)
  30.             ld hl,playerPoxY
  31.             sub (hl)
  32.             call a_div_b
  33.             call arctan_88
  34.             ld hl,playerDirection
  35.             sub (hl) \ add a,5 \ cp 11 \ jr nc,_raycaster_nextobject
  36.             push af                     ; angle
  37.                 inc de
  38.                 ld a,(de)               ; a = object type id, use to pull sprite
  39.                 ld hl,spriteLUT \ add a,a \ ld c,a \ ld b,0
  40.                 add hl,bc
  41.                 ld c,(hl) \ inc hl \ ld b,(hl) \ ld hl,spriteStart \ add hl,bc      ; hl = PTR to sprite layers
  42.             pop af      ; angle back out
  43.             rla \ rla \ rla
  44.             ld d,a                      ; we got our x-coord
  45.             ld b,a \ ld a,20 \ add a,b \ ld e,a     ; we got our y-coord
  46.         pop af                          ; distance back out
  47. ;fixed from "ld a,c"
  48.         ld c,a \ ld b,0
  49.         ld hl,distanceLUT
  50.         add hl,bc
  51.         ld a,(hl)                       ; distance -> scale factor, out a
  52.         call render_ScaledSprite
  53. _raycaster_nextobject
  54.     pop de
  55.         inc de
  56.         inc de
  57.         inc de
  58.     ld a,(de)
  59.     inc a
  60.     jr nz_raycaster_loopobject
  61.     ret
  62.        
  63. spriteLUT:
  64. ; pretend there is data here   
  65. distanceLUT:
  66. .db $00,$F2,$E5,$D8,$CC,$BF,$B2,$A5,$99,$8C,$7F
  67.        
  68.    
  69. render_ScaledSprite:
  70. ;   in: hl = ptr to sprite, de = coords of sprite, a = scale factor
  71. ;   scalespr.inc
  72. ; putScaledSprite reqs: hl=sprite PTR, de=(x,y), bc=(height,width/8), a=scale factor ($01 to $00 <=> 0.4% to 100%)
  73. ; in the original routine, it wrote to plotsscreen (ld de,plotSScreen). I changed its write-to to iy, so that I could call the routine twice (ld de,iy).
  74.     ld b,(hl)
  75.     inc hl
  76.     ld c,(hl)
  77.     inc hl
  78.     ld iy,frontBuffer1
  79.     push de
  80.         push af
  81.             push hl
  82.                 push bc
  83.                     call putScaledSprite
  84.                 pop bc
  85.             pop hl
  86.             ; jump hl to start of back buffer sprite
  87.             ld e,c      ; bc: c is width (in bytes), b is height
  88.             ld d,0
  89.             push bc
  90.             __get2ndLayer_loop:
  91.                 add hl,de
  92.                 djnz __get2ndLayer_loop
  93.             pop bc
  94.         pop af
  95.     pop de
  96.     ld iy,frontBuffer2
  97.     call putScaledSprite
  98.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement