Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- max_render_distance=15
- slender_render:
- ;;HL points to the object list
- ld a,(hl) ;\
- cp -1 ; |If the first item is the EOL, there is nothing to draw, so just RET
- ret z ;/
- checkObjLoop:
- inc hl ; |Get the y-coord
- ld e,(hl) ;/
- inc hl ; |Get the x-coord
- ld d,(hl) ;/
- push hl
- push af
- call isObj_in_view ;check if the object is in view
- pop bc
- jr c,checkObjloop
- ex de,hl
- ld hl,render_queue
- inc (hl)
- ld a,(hl)
- add a,a
- add a,(hl)
- scf
- adc a,l
- ld l,a
- jr nc,$+3
- ld h,a
- ld (hl),e ;Save the on-screen Y coordinate
- inc hl
- ld (hl),d ;save the on-screen X coordinate
- inc hl
- ld (hl),b ;save the object ID
- pop hl
- inc hl ;\
- ld a,(hl) ; |Check if next object is EOL, if not, reloop
- cp -1 ;/
- jp nz,checkObjLoop
- sortQueue:
- ;;These will be small lists, so bubble sort is sufficient
- ;;Sort furthest to closest
- ld hl,render_queue
- ld a,(hl)
- or a
- ret z
- dec a
- ret z
- ld b,a
- inc hl
- sortloop_outer:
- ld a,(hl)
- push hl
- push bc
- ld de,3
- sortloop_inner:
- add hl,de
- cp (hl)
- jr nc,$+6
- ld (max),hl
- ld a,(hl)
- djnz sortloop_inner
- ;swap first element with max element
- pop bc
- pop hl
- max=$+1
- ld de,0
- ld e,(hl) \ ld (hl),a \ ld a,e \ ld (de),a \ inc hl \ inc de
- ld a,(de) \ ld e,(hl) \ ld (hl),a \ ld a,e \ ld (de),a \ inc hl \ inc de
- ld a,(de) \ ld e,(hl) \ ld (hl),a \ ld a,e \ ld (de),a \ inc hl
- djnz sortloop_outer
- ret
- renderQueue:
- ;;draw the objects in the render queue
- ;;Objects are listed by their on-screen coordinate and ID
- ;=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%
- ;Need To Do
- ;=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%
- ret
- isObj_in_view:
- ;;Input: DE=(x,y) of the obj
- ;;Output: If the object is not in view, return c flag set.
- ;; Otherwise c flag reset, (H,L) are the on-screen (x,y) coordinates of the object
- ld hl,(playerY)
- ld a,d \ sub h \ ld c,a
- ld a,e \ sub l \ ld b,a ;c=x, b=y
- call rotate
- ld c,a
- ld a,b
- add a,a
- ret c
- cp max_render_distance*2
- cpl
- ret c ;B is the Y
- ld a,c
- rla
- rra
- jr z,$+6 \ neg \ ld h,48*4
- add a,a \ ret c
- add a,a \ ret c
- sub b
- ccf
- ret c
- add a,b
- ;px =48+4r/s*3
- ; =48+3a/c-h/4
- ld d,0
- add a,a \ cp b \ jr nc,$+5 \ sub b \ ld d,2
- add a,a \ cp b \ jr nc,$+4 \ sub b \ inc d
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ jr nc,$+3 \ add a,b \ rl e
- add a,a \ sub b \ ld a,e \ rla \ cpl \ ld e,a
- ;px=(DE*3-H+48*4)/4
- ld a,48*4 \ sub h
- ld h,d
- ld l,e
- add hl,hl
- add hl,de
- add a,l
- jr nc,$+4
- inc h
- rr h \ rra
- rr h \ rra ;px=a
- ld h,a ;px
- calc_py:
- #if max_render_distance==10
- ;py=64/10*B
- ;b<10
- ;py=6.4*B
- ld a,b
- add a,a
- add a,b
- add a,a
- ld l,a
- ld a,b
- add a,a
- add a,a
- inc l \ sub 10 \ jr nc,$-2
- dec l
- #endif
- #if max_render_distance==15
- ;py=64/15*B
- ;b<15
- ;py=(4+4/15)*B
- ld a,b
- add a,a
- add a,a
- ld l,a
- inc l \ sub 15 \ jr nc,$-2
- dec l
- #endif
- #if max_render_distance==16
- ;py=64/16*B
- ;b<16
- ;py=4*B
- ld a,b
- add a,a
- add a,a
- ld l,a
- #endif
- if calc_py==$
- .echo "this max_render_distance is not supported in computing py=64/max_render_distance*C"
- #endif
- or a
- ret
- rotate:
- ;;Input:
- ;; B is the Y coordinate in respect to the user
- ;; C is the X coorinate in respect to the user
- ;;Output:
- ;; B = Y, rotated
- ;; A = X, rotated
- ;;x=xcos+ysin = C*(playervector+1)+B*(playervector)
- ;;y=ycos-xsin =
- ld a,(playervector) \ xor b ;\
- push af \ xor b \ ld h,b \ ld d,0 ; |
- ld l,d \ and $7F \ res 7,h \ ld e,a ; |
- sla h \ sla h \ jr nc,$+3 \ ld l,e ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |ysin
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- sla l \ jr nc,$+3 \ inc h ; |
- pop af \ ld a,h \ jp p,$+5 \ neg ; |
- ld (ysin),a ;/
- ld a,(playervector)
- xor c
- push af
- ld h,c
- ld l,d
- sla h \ sla h \ jr nc,$+3 \ ld l,e ;\
- add hl,hl \ jr nc,$+3 \ add hl,de ; |xsin
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- sla l \ jr nc,$+3 \ inc h ; |
- pop af \ ld a,h \ jp p,$+5 \ neg ; |
- ld (xsin),a ;/
- ld a,(playervector+1) \ xor b ;\
- push af \ xor b \ ld h,b \ ld d,0 ; |
- ld l,d \ and $7F \ res 7,h \ ld e,a ; |
- sla h \ sla h \ jr nc,$+3 \ ld l,e ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |ycos
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- sla l \ jr nc,$+3 \ inc h ; |
- pop af \ ld a,h \ jp p,$+5 \ neg ;/
- xsin=$+1
- ld h,0
- sub h
- ld b,a ;new Y
- ld a,(playervector+1)
- xor c
- push af
- ld h,c
- ld l,d
- sla h \ sla h \ jr nc,$+3 \ ld l,e ;\
- add hl,hl \ jr nc,$+3 \ add hl,de ; |xcos
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- add hl,hl \ jr nc,$+3 \ add hl,de ; |
- pop af \ ld a,h \ jp p,$+5 \ neg ;/
- sla l
- ysin=$+1
- ld h,0
- adc a,h
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement