0 Members and 1 Guest are viewing this topic.
So do you have the coordinates of the objects?
#define rayStart Op8#define rayEnd Op8+2#define renderDistance 10 ; change this to tweak render distance#define rcStack Op8+4 engine_rayCaster_Init: ld hl,smallEditCol ld (raycastStack),hl ; reset pointer to start of raycaster stack ld e,(playerPosY) ld (rayStart),e ld (rayEnd),e ; initialize player position as start and current end of ray ld d,(playerPosX) ld (rayStart+1),d ld (rayEnd+1),d ; initialize player position as start and current end of ray ld e,l ld d,h ; ray End temp (may delete ram if i can) de = ray start, hl = ray end ld bc,(playerVectorX) push bc_rc_loop: add hl,bc ld a,l push hl multAbyWidth ; out hl ld c,b ld b,0 add hl,bc ; offset in map to get jr _rc_loop_test_rc_test_exit: pop hl call _rc_push _rc_loop_test:; yes, i know i didnt actually put in the pointer to the map data. pretend, i did that. ld a,(hl) or a jr nz,{1@} pop bc jr _rc_loop@: jr _rc_test_exit _rc_push: ld de,(rcStack) ld (de),a ; map object pushed to stack inc de ld (de),hl ; object position push to stack ld hl,(rayStart) inc de inc de ld (de),hl ; your position pushed to stack (i will throw in a distance calc here, bc this is multiple data entries) inc de inc de ld (rcStack),de ret
for (a, from angle-5 to angle+5, 1 ) { calc (x,y) vectors of a figure out all points on line from player (x,y), in increments of above (x,y), till render distance push any objects found onto a stack }render stack
#define distance tempSwapArea ; 1 byte#define rayCurrent distance+1 ; 2 bytes#define angleCurrent rayEnd+2 ; 1 byte#define angleStart angleCurrent+1 ; 1 byte#define angleStop angleStart+1 ; 1 byte#define iterVector angleStop+1 ; 2 bytes#define rcStack iterVector+2 ; 2 bytes, a pointer to the start of the raycaster object stack#define renderDistance 10 ; adjust this to change the render distance#define priorAngle rcStack+2 ; 1 byte engine_raycaster_Init: ld hl,smallEditCol ld (rcStack),hl ; reset pointer to start of raycaster stack ld a,(playerDirection) ld hl,priorAngle cp (hl) jr z,{1@} ld a,b ld b,5 add a,b ld (angleStop),a ld b,-10 add a,b ld (angleStart),a@: ld a,(angleStart) ; sorry about this bit, but needs to be here for the jump to work ld (angleCurrent),a ; shouldnt be too time-consuming to do thatrc_loop_angle: call _getTempVector ld a,(playerPosX) ld h,a ld a,(playerPosY) ld l,a ld bc,(iterVector)rc_loop_ray: add hl,bc call rc_getDistance ld (distance),a ld a,l multAbyWidth ld c,h ld b,0 add hl,bc call rc_getMap ld a,(hl) or a jr z,rc_tilepush_skip; rc_tilepush: if tile is something, push this object onto rcStack, renderer will handle it ld de,(rcStack) ld (de),a ; object type Id inc de ld a,(distance) ld (de),a inc de ld (rcStack),de jr rc_skip_writeemptyrc_tiletest_skip: ld a,(distance) cp renderDistance jr z,rc_loop_angle_next jr c,rc_loop_angle_next jr rc_loop_rayrc_loop_angle_next: ld de,(rcStack) ld a,$ff ld (de),a inc de ld (rcStack),derc_skip_writeempty: ld a,(angleCurrent) inc a ld (angleCurrent),a jr rc_loop_angle rc_getTempVector:; using current angle, gets vectors. each vector is in 8.8 FP format, so we only save the .8 part; input: a = angle; output: new vectors loaded into (iterVector) word push af call calcSin ; a = angle ld (iterVector),l ; hl = 8.8 FP pop af call calcCos ld (iterVector+1),l retrc_getMap:; input: hl = offset in map; output: hl points to tile ld bc,(SlendMapPtr) add hl,bc retrc_getDistance:; input: hl = current testing location; output: a = distance from origin ret
ld a,(priorAngle) ld b,(playerDirection) cp b jr z,rc_loop_angle ld a,b ld b,5 add a,b ld (angleStop),a ld b,-10 add a,b ld (angleCurrent),a
ld a,(playerDirection) ld hl,priorAngle cp (hl) jr z,rc_loop_angle add a,5 ld (angleStop),a sub 10 ld (angleCurrent),a
That does what your code does (and will actually assemble). But i'm not sure if you really wanted to be using playerDirection to add those values to or priorAngle. Probably priorAngle. Shouldn't you at least try to assemble your code first?I can't comment on the code as a whole because i don't really understand raycasting or what you're trying to do, sorry...