?login_element?

Subversion Repositories NedoOS

Rev

Rev 1107 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.         module LEVEL
  2. ;------------------------------------------------------------
  3. build:
  4.         call POP_UP_INFO.reset
  5.         call clearData
  6.         call buildLevel
  7.         ret
  8. ;------------------------------------------------------------
  9. clearData:
  10.         ; clear objects data
  11.         xor a
  12.         ld hl,objectsData
  13.         ld de,objectsData + 1
  14.         ld bc,(OBJECT_DATA_SIZE * MAX_OBJECTS) - 1
  15.         ld (hl),a
  16.         ldir
  17.         ; clear level cells data
  18.         ld hl,levelCells
  19.         ld de,levelCells + 1
  20.         ld bc,(MAP_WIDTH * MAP_HEIGHT) - 1
  21.         inc a
  22.         ld (hl),a
  23.         ldir
  24.         dec a
  25.         ld (isLevelPassed),a
  26.         ld (rebuildLevel),a
  27.         ld (global_direction),a         ; set direction NONE
  28.         ret
  29. ;------------------------------------------------------------
  30. buildLevel:
  31.         ; parse level walls
  32.         ; level walls data = 24 bytes
  33.         ; displayed wall cells = 192 pcs.
  34.         xor a                   ; cell ID
  35.         exa
  36.         ld ix,levelCells
  37.  
  38.         call getCurrentLevelAddress     ; HL = level data address (walls)
  39.         ld (levelAddr),hl
  40.         ld (globalSeedTmp),hl   ; set random seed for this level
  41.         ld (globalSeed),hl
  42.         push hl
  43.         call fillWalls
  44.         pop hl
  45.  
  46.         ld b,24                 ; 12 rows, 2 columns
  47. .nextHalf:
  48.         push bc
  49.         ld a,(hl)
  50.         ; half screen line (8 cells 16x16 from byte)
  51.         ld b,8
  52. .byteToHalfLine:
  53.         push bc
  54.         rlca
  55.         push af
  56.         jr nc,.emptyCell        
  57.         ld (ix),255             ; fill cells for collision
  58.         push hl
  59.         exa
  60.         ld c,a
  61.         exa
  62.         ld hl,BLOCK_PBM         ; TODO render random walls by seed
  63.         call rnd16
  64.         and 3
  65.         jr nz,.notBlockD
  66.         ld hl,BLOCK_D_PBM
  67. .notBlockD:
  68.         call printSpr
  69.         pop hl
  70. .emptyCell:
  71.         inc ix
  72.         exa
  73.         inc a
  74.         exa
  75.         pop af
  76.         pop bc
  77.         djnz .byteToHalfLine
  78.         inc hl
  79.         pop bc
  80.         djnz .nextHalf
  81.         push hl
  82.        
  83.         call cutInsideRooms
  84.         ld b,7
  85. .paint:
  86.         push bc
  87.         ld hl,(globalSeedTmp)
  88.         ld de,ATTR_ADDR
  89.         ld hl,levelCells
  90.         ld b,12
  91. .rows:
  92.         push bc
  93.         push de
  94.         ld b,16
  95. .columns:
  96.         push bc
  97.         push de
  98.         push hl
  99.        if !EGA
  100.         call .paintWall
  101.        endif
  102.         pop hl
  103.         inc l
  104.         pop de
  105.         inc e
  106.         inc e
  107.  
  108.         pop bc
  109.         djnz .columns
  110.  
  111.         pop de
  112.         ex de,hl
  113.         ld bc,64
  114.         add hl,bc
  115.         ex de,hl
  116.         pop bc
  117.         djnz .rows
  118.         ei
  119.         halt
  120.         halt
  121.         halt
  122.         halt
  123.         pop bc
  124.         djnz .paint
  125.         pop hl
  126.         ret
  127. .paintWall:
  128.  
  129.         ld a,(hl)
  130.         inc a
  131.         jr z,.pwn
  132.         dec a
  133.         cp 1
  134.         jr z,.setColor
  135.         xor a
  136. .pwb:
  137.         ex de,hl
  138.         jp fillAttr2x2
  139. .setColor:
  140.         ld a,(globalSeedTmp)
  141.         rrca
  142.         and 3
  143.         jr nz,.pwb
  144.         inc a
  145.         jr .pwb
  146. .pwn:
  147.         push de
  148.         call rnd16
  149.         pop hl
  150.         and 7
  151.         rlca
  152.         rlca
  153.         add a,low wallColors
  154.         ld e,a
  155.         adc a,high wallColors
  156.         sub e
  157.         ld d,a
  158. .pw2:
  159.         ld b,2
  160. .pw:
  161.         push bc
  162.         ld a,(de)
  163.         dec a
  164.         cp (hl)
  165.         jr c,.ns1
  166.         inc (hl)
  167. .ns1:
  168.         inc de
  169.         inc hl
  170.         ld a,(de)
  171.         dec a
  172.         cp (hl)
  173.         jr c,.ns2
  174.         inc (hl)
  175. .ns2
  176.         dec hl
  177.         inc de
  178.         ld bc,32
  179.         add hl,bc
  180.         pop bc
  181.         djnz .pw
  182.         ret
  183. ;----------------------------------------------
  184. cutInsideRooms:
  185.         ; put plugs on all doors so that the fill does not go beyond the level
  186.         ; put stubs on all heroes as start points of the fill
  187.         ; filling starts from the place where the hero is located.
  188.         push hl
  189.         push hl
  190.         ; install door plugs on the card.
  191.         ld c,#FD
  192.         ld e,EXIT_DOOR_PBM_ID
  193.         call .blockDoors
  194.         pop hl
  195.         ; entering on the card all heroes under the set value.
  196.         ld c,#FE
  197.         ld e,HERO_FACE_00_PBM_ID
  198.         call .blockDoors
  199.         call .fill
  200.         pop hl
  201.         ret
  202. .fill:
  203.         ; look for a value, replace it with 1 and fill the area with zeros from the found value until the map runs out of the desired values.
  204.         ld hl,levelCells
  205.         ld a,#FE
  206.         ld bc,#C0
  207.         cpir
  208.         xor a
  209.         cp c
  210.         ret z
  211.         dec l
  212.         ld (hl),1
  213.         call fillInsideLevel
  214.         jr .fill
  215.         ret
  216. .blockDoors:   
  217.         ; C > value
  218.         ; E > id of the desired sprite
  219.         ; HL > objects (after 24 level bytes)
  220. .nextDoor:
  221.         ld a,(hl)
  222.         cp #FF
  223.         ret z
  224.         inc hl
  225.         ld a,(hl)       ; first byte = cell id, second byte = sprite id
  226.         inc hl
  227.         cp e
  228.         jr nz,.nextDoor
  229.         push hl
  230.         dec hl
  231.         dec hl
  232.         ld l,(hl)
  233.         ld h,high levelCells
  234.         ld (hl),c
  235.         pop hl
  236.         jr .nextDoor
  237. ;----------------------------------------------
  238. fillWalls:
  239.         ld c,#C0
  240.         call getFloorSprite
  241. .loop:
  242.         push bc
  243.         push hl
  244.         dec c
  245.         call printSpr
  246.         pop hl
  247.         pop bc
  248.         dec c
  249.         jr nz,.loop
  250.         ld a,l
  251.         cp low FLOOR_0004_PBM
  252.         ret nz
  253.  
  254.         ld b,24
  255. .loop2:
  256.         push bc
  257.         call rnd16
  258.         and #BF
  259.         ld c,a
  260.         call rnd16
  261.        if EGA
  262.         ld hl,FLOOR_0001_PBM
  263.         and 1
  264.         jr z,.noadd128
  265.         ld hl,FLOOR_0002_PBM
  266. .noadd128
  267.        else
  268.         and 1
  269.         rrca
  270.         rrca
  271.         rrca
  272.         add a,low FLOOR_0001_PBM
  273.         ld l,a
  274.         adc a,high FLOOR_0001_PBM
  275.         sub l
  276.         ld h,a 
  277.        endif
  278.         call printSpr ;tile
  279.         pop bc
  280.         djnz .loop2
  281.         ret
  282. ;----------------------------------------------
  283. wallColors:
  284.         db 4,6,6,6
  285.         db 6,4,4,4
  286.         db 5,4,4,4
  287.         db 4,5,5,5
  288.  
  289.         db 6,6,6,6
  290.         db 5,5,5,5
  291.         db 4,4,4,4
  292.         db 3,3,3,3
  293. ;----------------------------------------------
  294. getFloorSprite:
  295.         ; A - number 0-3
  296.         ld hl,FLOOR_0003_PBM
  297.         call rnd16
  298.         rrca
  299.         ret c
  300.         ld hl,FLOOR_0004_PBM
  301.         ret
  302. ;----------------------------------------------
  303.  
  304.  
  305.  
  306.         endmodule