Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define renderDistance 10 ; adjust this to change the render distance
- #define priorAngle rcStack+2 ; 1 byte
- engine_raycaster_Init:
- ld de,SlendMapPtr
- _raycaster_loopobject
- push de
- inc de
- ld a,(de)
- ld hl,playerPosY
- sub (hl)
- ld c,a
- dec de
- ld a,(de)
- ld hl,playerPosX
- sub (hl)
- call _getDistance
- ld de,(renderDistance)
- cpHL
- jr nc,_raycaster_nextobject
- ld a,l
- push af ; distance
- ld a,(de)
- ld hl,playerPosX
- sub (hl)
- ld b,a
- inc de
- ld a,(de)
- ld hl,playerPoxY
- sub (hl)
- call a_div_b
- call arctan_88
- ld hl,playerDirection
- sub (hl) \ add a,5 \ cp 11 \ jr nc,_raycaster_nextobject
- push af ; angle
- inc de
- ld a,(de) ; a = object type id, use to pull sprite
- ld hl,spriteLUT \ add a,a \ ld c,a \ ld b,0
- add hl,bc
- ld hl,(hl) \ ld bc,spriteStart \ add hl,bc ; hl = PTR to sprite layers
- pop af ; angle back out
- rla \ rla \ rla
- ld d,a ; we got our x-coord
- ld b,a \ ld a,20 \ add a,b \ ld e,a ; we got our y-coord
- pop af ; distance back out
- ld a,c \ ld b,0
- ld hl,distanceLUT
- add hl,bc
- ld a,(hl) ; distance -> scale factor, out a
- call render_ScaledSprite
- _raycaster_nextobject
- pop de
- ld hl,3
- add hl,de
- ex de,hl
- ld a,(de)
- cp $ff
- ret z
- jr _raycaster_loopobject
- spriteLUT:
- ; pretend there is data here
- distanceLUT:
- .db $00,$F2,$E5,$D8,$CC,$BF,$B2,$A5,$99,$8C,$7F
- render_ScaledSprite:
- ; in: hl = ptr to sprite, de = coords of sprite, a = scale factor
- ; scalespr.inc
- ; putScaledSprite reqs: hl=sprite PTR, de=(x,y), bc=(height,width/8), a=scale factor ($01 to $00 <=> 0.4% to 100%)
- ; 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)).
- ld b,(hl)
- inc hl
- ld c,(hl)
- inc hl
- ld (iy),frontBuffer1
- push de
- push af
- push hl
- push bc
- call putScaledSprite
- pop bc
- pop hl
- ; jump hl to start of back buffer sprite
- ld e,c ; bc: c is width (in bytes), b is height
- ld d,0
- push bc
- __get2ndLayer_loop:
- add hl,de
- djnz __get2ndLayer_loop
- pop bc
- pop af
- pop de
- ld (iy),frontBuffer2
- call putScaledSprite
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement