A dungeon delver roguelike using Pathfinder 2nd edition rules
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Working on the GenerateDungeon function

+48 -13
+48 -13
gb/src/dungeon.asm
··· 9 9 10 10 SECTION "DungeonCode", ROM0 11 11 12 + BIT_USED_ROOM:: db $01 13 + BIT_ENTRANCE:: db $02 14 + BIT_DOOR_NORTH:: db $04 15 + BIT_DOOR_EAST:: db $08 16 + BIT_DOOR_SOUTH:: db $10 17 + BIT_DOOR_WEST:: db $20 18 + BIT_STAIR_BELOW:: db $40 19 + BIT_STAIR_UP:: db $80 20 + 12 21 ; Params: 13 22 ; Starting Width: B 14 23 ; Starting Height: C 15 24 InitDungeon:: 16 - ld hl, current_width 25 + ld hl, current_width ; current_width = B 17 26 ld [hl], b 18 - ld hl, current_height 27 + ld hl, current_height ; current_height = C 19 28 ld [hl], c 20 29 ret 21 30 22 31 GenerateDungeon:: 23 - ; Dungeon Area = E 32 + ; Cache current register values to restore later 33 + ; In the event this is called with values in the 34 + ; registers to be used in an outer function 24 35 push de 25 36 push hl 26 37 push af 27 38 push bc 28 39 29 - ld hl, current_width 40 + ld hl, current_width ; dungeon_area = current_width * current_height 30 41 ld e, [hl] 31 42 ld d, 0 32 43 ld hl, current_height ··· 35 46 ld d, h 36 47 ld e, l 37 48 38 - ; Generated Cells Number = A 39 - ld a, 0 49 + ; generated_cells_number is stored in A 50 + ld a, 0 ; generated_cells_number = 0 40 51 41 - ; i = B 42 - ld b, 0 43 - .LoopCheck: 44 - cp a, e 45 - jp nz, GenerateDungeon.Loop_Skip 52 + ; i is stored in B 53 + ld b, 0 ; i = 0 54 + .LoopCheck: ; for loop begin 55 + cp a, e ; if (generated_cells_number < dungeon_area) && ((i == 0) || (i < generated_cells_number)) 56 + jp nz, GenerateDungeon.Loop_Skip ; Break Loop 46 57 jp nc, GenerateDungeon.Loop_Skip 47 - jp GenerateDungeon.LoopCheck2 48 58 .LoopCheck2: 49 59 push af 50 60 ld a, b ··· 62 72 jp nz, GenerateDungeon.Loop_Skip 63 73 jp nc, GenerateDungeon.Loop_Skip 64 74 .Loop_Body: 65 - push af 75 + push af ; if ((i == 0) && (generated_cells_number == 0)) 66 76 ld a, b 67 77 cp a, 0 68 78 pop af 69 79 jp nz, GenerateDungeon.Loop_Body2 70 80 cp a, 0 71 81 jp nz, GenerateDungeon.Loop_Body2 82 + push bc 83 + ld b, 0 84 + ld c, e 85 + call rand_range 86 + push hl 87 + ld hl, entrance_id 88 + ld [hl], b 89 + ld hl, generated_cells 90 + ld [hl], b 91 + ld hl, dungeon_grid 92 + push af 93 + ld a, l 94 + add a, b 95 + ld l, a 96 + ld a, BIT_ENTRANCE 97 + or a, BIT_USED_ROOM 98 + ld [hl], a 99 + pop af 100 + ld a, 1 101 + pop hl 102 + pop bc 72 103 .Loop_Body2: 104 + call GenerateRoom 73 105 .Loop_Skip: 74 106 pop bc 75 107 pop af 76 108 pop hl 77 109 pop de 78 110 111 + ret 112 + 113 + GenerateRoom:: 79 114 ret