;====================================== ; MakeDung- Random dungeon generator ;====================================== MakeDung: ;=================== ; Choose Tileset: ;=================== ;Get room ld a,(room) ;Divide by 4 rra rra and 00111111b ;Mod 8, 8 tilesets in all and 7 ;Multiply a by 32 add a,a add a,a add a,a add a,a add a,a ;Add 64*tileset to tile pointer ld b,0 ld c,a ld hl,sprites add hl,bc add hl,bc ;Set the new tileset ld (spritepoint),hl ;=================== ; Other prep work ;=================== ;Set first map on so portal can be generated ld ixh,$70 ;Boss every 4th level ld a,(room) inc a ld b,a and %11111100 cp b jr nz,skipprepboss ld ixh,$80 skipprepboss: ;================= ; Clear the map ;================= ; ;Load map loaction ld hl,map ;Load size (64) ld b,255 ;Start a loop ClearMapLoop: ;Clear the byte ld (hl),0 ;Increment pointer inc hl ;Loop 64 times djnz ClearMapLoop ;============================= ; Make the map initilzation ;============================= ; ;Initalize XY coordinates ld a,7 ld (row),a ld (col),a ;Set number of tunnels (room/4+3) ld a,(room) rra rra rra and 00011111b add a,3 ;Load it into D ld d,a ;===================== ; Make the map loop ;===================== MakeLoop1: ;Set length of tunnel (room mod 8+2) ld a,(room) and 7 add a,2 ld e,a ;=========== ; subloop ;=========== MakeLoop2: ;Get Map Byte call GetMapByte ;Finally store it into c ld c,a ;call Random number routine ;Old Version: ; ld b,4 ; call ionrandom ;New Version: call dq_rand ;Filter result and 3 ;If 0, make it right or a jr z,mkRight ;If 1, make it down... dec a jr z,mkDown ;If 2...left dec a jr z,mkLeft ;If 3, Up! No jump necessary... ;Code for up: ;Load byte from map ld a,c ;force up bit or 8 ;Put the changed byte back ld (hl),a ;Decrease row ld hl,row dec (hl) ;Get byte again call GetMapByte ;force down bit or 2 ;Put the changed byte back ld (hl),a ;Done, contiune on to MakeEnd jr MakeEnd ;Code for Right: ;Similar comments than those above, I'm just too lazy to write them out. mkRight: ld a,c or 1 ld (hl),a ld hl,col inc (hl) call GetMapByte or 4 ld (hl),a jr MakeEnd ;Code for Down: mkDown: ld a,c or 2 ld (hl),a ld hl,row inc (hl) call GetMapByte or 8 ld (hl),a jr MakeEnd ;Code for Right: ;Similar comments than those above, I'm just too lazy to write them out. mkLeft: ld a,c or 4 ld (hl),a ld hl,col dec (hl) call GetMapByte or 1 ld (hl),a ;The MakeEnd point: MakeEnd: ;==================== ; Add item to room ;==================== ;Room already has item? and $F0 ;Skip the item addition code then! jr nz,skipitem ;Add random item: (0-6) ;ld b,7 ;call ionrandom call DQRand and 7 sub 1 jr nc,skipitem255 xor a skipitem255: ;move to upper nib add a,a add a,a add a,a add a,a ;or existing data with item data or (hl) ld (hl),a skipitem: ;============= ; Next room ;============= ;Tunnel gets more complete dec e ;Keep going till tunnel is complete jr nz,MakeLoop2 ;====================== ; Tunnel is complete ;====================== ;Check if first tunnel ld a,ixh or a jr z,skipexit ;and give last room the portal! ld a,(hl) and 15 or ixh ld (hl),a ld ixh,0 skipexit: ;================================ ; Choose a new tunnel location ;================================ ;Row=rand(0-3)+2 ld b,4 call ionrandom add a,6 ld (row),a ;Col=rand(0-3)+2 ld b,4 call ionrandom add a,6 ld (col),a ;=================== ; Tunnel finished ;=================== ;Dec number of tunnels left. dec d ;Any left, coutinue making tunnels. jp nz,MakeLoop1 ret ;CODE COMMENTED OUT /* ; ;;=========================================== ;; BrowseAround- Walk around panning rooms ;;=========================================== ;BrowseAround: ; ;Decompess Cave ; call decompcave ; ;Display Cave ; call displaycave ; ;Draw Screen ; call ionFastCopy ;brKeyLoop: ; ;Get Key ; call waitkey ; ; ;Down? ; cp GDown ; jr z,brMoveDown ; ;Up? ; cp GLeft ; jr z,brMoveLeft ; ;Left? ; cp GRight ; jr z,brMoveRight ; ;Right? ; cp GUp ; jr z,brMoveUp ; ;Clear? ; cp GClear ; ret z ; jr brkeyloop ;brMoveDown: ; ld a,(row) ; inc a ; ld (row),a ; jr BrowseAround ;brMoveUp: ; ld a,(row) ; dec a ; ld (row),a ; jr BrowseAround ;brMoveLeft: ; ld a,(col) ; dec a ; ld (col),a ; jr BrowseAround ;brMoveRight: ; ld a,(col) ; inc a ; ld (col),a ; jr BrowseAround ; */