Subversion Repositories NedoOS

Rev

Rev 772 | Rev 1620 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. tkeyangle=$-5
  2.               ;LRDU
  3.        ;DB -1 ;0000
  4.        ;DB 128;0001
  5.        ;DB 0  ;0010
  6.        ;DB -1 ;0011
  7.        ;DB 64 ;0100
  8.         DB 96 ;0101
  9.         DB 32 ;0110
  10.         DB 64 ;0111
  11.         DB 192;1000
  12.         DB 160;1001
  13.         DB 224;1010
  14.         DB 192;1011
  15.         DB -1 ;1100
  16.         DB 128;1101
  17.         DB 0  ;1110
  18.         DB -1 ;1111
  19. tkeyangleend
  20.  
  21. ;в 0x4000 включена pgmap
  22. CONTROL
  23. ;режимы двери:
  24. ;0: дверь закрыта
  25. ;1: дверь открывается, doortimer увеличивается
  26. ;2: дверь открыта, dooropentimer уменьшается
  27. ;3: дверь закрывается, doortimer уменьшается
  28. doortimer=$+1
  29.         ld a,0
  30. doortimermode=$+1
  31.         ld b,0
  32.         djnz control_door_noopening
  33.         add a,2
  34.         ld (doortimer),a
  35.         jr nz,control_doorq
  36.         dec a ;-1
  37.         ld (doortimer),a ;stay opened
  38.         ld a,50 ;a=door open time
  39.         ld (dooropentimer),a
  40.         ld a,2
  41.         ld (doortimermode),a
  42.         jr control_doorq
  43. control_door_noopening
  44.         djnz control_door_noopened
  45. dooropentimer=$+1
  46.         ld a,0
  47.         dec a
  48.         ld (dooropentimer),a
  49.         jr nz,control_doorq
  50.         ;call closecurrentdoor ;keeps hl
  51.         ld a,-2
  52.         ld (doortimer),a ;stay opened
  53.         ld a,3
  54.         ld (doortimermode),a
  55.         jr control_doorq
  56. control_door_noopened
  57.         djnz control_door_noclosing
  58. ;если игрок стоит в дверях, то не закрываем, а открываем
  59.         LD HL,(IMcurXx+1)
  60.         LD a,(IMcurYy+1)
  61.         ld h,a
  62.         ld a,ID_DOOR
  63.         cp (hl)
  64.         jr z,control_door_setopened
  65.         inc h
  66.         cp (hl)
  67.         jr z,control_door_setopened
  68.         dec h
  69.         set mapdifbit,l
  70.         cp (hl)
  71.         jr z,control_door_setopened
  72.         inc l
  73.         cp (hl)
  74.         jr z,control_door_setopened
  75.         ld a,(doortimer)
  76.         sub 2
  77.         ld (doortimer),a
  78.         jr nz,control_doorq
  79.         ;xor a
  80.         ld (doortimermode),a
  81.         call closecurrentdoor ;keeps hl
  82.         jr control_doorq
  83. control_door_setopened
  84.         ld a,1
  85.         ld (doortimermode),a
  86. control_door_noclosing
  87. control_doorq
  88.  
  89.        IF kempston
  90.         LD C,#FF
  91.         IN A,(#1F)
  92.         LD B,A
  93.         AND #E0
  94.         jr NZ,nKEMPSTON
  95.         LD A,B
  96.         RRA
  97.         jr NC,$+4
  98.         RES 1,C
  99.         RRA
  100.         jr NC,$+4
  101.         RES 0,C
  102.         RRA
  103.         jr NC,$+4
  104.         RES 3,C
  105.         RRA
  106.         jr NC,$+4
  107.         RES 2,C
  108.         RRA
  109.         jr NC,$+4
  110.         RES 6,C
  111. nKEMPSTON
  112. ;C=%1f11durl
  113.        ENDIF
  114.        IF autostrafe
  115.         BIT 3,C ;down
  116.         jr NZ,nAUTOSTRAFE
  117.         LD A,C
  118.         BIT 1,A
  119.         jr NZ,$+6
  120.         AND %01101111 ;strafe + rotate flag
  121.         OR %00001011 ;block down & rotate
  122.         BIT 0,A
  123.         jr NZ,$+6
  124.         AND %01011111 ;strafe + rotate flag
  125.         OR %00001011 ;block down & rotate
  126.         LD C,A
  127. nAUTOSTRAFE
  128.        ENDIF
  129.         LD B,#FF
  130.         ld a,#fe
  131.         in a,(#fe)
  132.         rra
  133.         rl b ;cs (open)
  134.         LD A,#7F
  135.         IN A,(#FE)
  136.         RRA
  137.         RL B ;space (fire)
  138.         LD A,#FD
  139.         IN A,(#FE)
  140.         RRA
  141.         RL B ;A
  142.         RRA
  143.         RRA
  144.         RL B ;D
  145.         RLA
  146.         RL B ;S (down)
  147.         LD A,#FB
  148.         IN A,(#FE)
  149.         RRA
  150.         RRA
  151.         RL B ;W (up)
  152.         LD A,#DF
  153.         IN A,(#FE)
  154.         RRA
  155.         RL B ;P (right)
  156.         RRA
  157.         LD A,B
  158.         RLA ;O (left)
  159.        IF kempston
  160.         AND C
  161.        ENDIF
  162.  
  163. ;A=%ofADdurl
  164.  
  165.        IF demoplay
  166. demoplayoff=$
  167.         OR A
  168.         jr C,demoplayQ
  169.        BIT 4,A ;"D"
  170.        jr NZ,demoplaynOFF
  171.         LD A,#37 ;scf
  172.         LD (demoplayoff),A
  173.         LD A,#91 ;sub c
  174.         LD (mouseon),A
  175.         LD A,#FF
  176. demoplaynOFF
  177. democursor=$+1
  178.         LD HL,demobegin
  179. demokey=$+1
  180.         LD A,%00111111
  181. demokeytime=$+1
  182.         LD C,1
  183.         DEC C
  184.         jr NZ,CnNEWKEY
  185.         LD A,(HL)
  186.         LD (demokey),A
  187.         INC HL
  188.         LD C,(HL)
  189.         INC HL
  190.         LD (democursor),HL
  191. CnNEWKEY
  192.         LD HL,demokeytime
  193.         LD (HL),C
  194. demoplayQ
  195.        ELSE
  196.        IF demorec
  197. democursor=$+1
  198.         LD HL,demobegin
  199. demokeytime=$+1
  200.         LD C,0
  201.         INC C
  202.         jr Z,CNEWKEY
  203.         CP (HL)
  204.         jr Z,CnNEWKEY
  205. CNEWKEY
  206.         INC HL
  207.         LD (HL),C
  208.         LD C,0
  209.         INC HL
  210. CnNEWKEY
  211.         LD (HL),A
  212.         LD (democursor),HL
  213.         LD HL,demokeytime
  214.         LD (HL),C
  215.        ENDIF
  216.        ENDIF
  217.  
  218. ;a=%ofADdurl
  219.        PUSH AF
  220.         bit 7,a
  221.         jr nz,noopendoor
  222.         ;call closecurrentdoor ;keeps hl
  223.  
  224.         LD HL,(IMcurXx+1)
  225.         LD a,(IMcurYy+1)
  226.         ld h,a
  227.         ld c,ID_DOOR*2
  228.         ld a,(hl)
  229.         add a,a
  230.         cp c
  231.         jr z,opendoor_h_dec
  232.         inc h ;dec h
  233.         ld a,(hl)
  234.         add a,a
  235.         cp c
  236.         jr z,opendoor_h_inc
  237.         dec h ;inc h
  238.         set mapdifbit,l
  239.         ld a,(hl)
  240.         add a,a
  241.         cp c
  242.         jr z,opendoor_l_dec
  243.         inc l
  244.         ld a,(hl)
  245.         add a,a
  246.         cp c
  247.         ;jr z,opendoor
  248.         jr nz,noopendoor
  249. opendoor_l_inc
  250.         push hl
  251.         res 7,(hl)
  252.         inc l
  253.         res 7,(hl)
  254.         jr opendoorok
  255. opendoor_l_dec
  256.         push hl
  257.         res 7,(hl)
  258.         dec l
  259.         res 7,(hl)
  260.         jr opendoorok
  261. opendoor_h_dec
  262.         push hl
  263.         res 7,(hl)
  264.         dec h
  265.         res 7,(hl)
  266.         jr opendoorok
  267. opendoor_h_inc
  268.         push hl
  269.         res 7,(hl)
  270.         inc h
  271.         res 7,(hl)
  272. opendoorok
  273. ;ничего не делать, если hl==(oldopendooraddr2)
  274.        ld de,(oldopendooraddr2)
  275.        or a
  276.        sbc hl,de
  277.        add hl,de
  278.         pop de
  279.        jr z,noopendoor
  280.         call closecurrentdoor ;keeps hl,de
  281.         ld (oldopendooraddr2),hl
  282.         ld (oldopendooraddr),de
  283.         xor a
  284.         ld (doortimer),a
  285.         inc a
  286.         ld (doortimermode),a
  287.         ld a,5
  288.         call sfxplay
  289. noopendoor
  290.        pop af
  291. ;a=%ofADdurl
  292.        bit 6,a
  293.        jp nz,nofire
  294.        push af
  295.        
  296.         call RAYPREPXY
  297.         LD A,SCRWIDPIX/2;0x40;TODO связано с scrwid/2
  298.         ld l,a
  299.         LD (cura),A
  300.         CALL RAYCAST
  301. ;C=dist(scale#)
  302. ;B=texx
  303.         ld a,c
  304.         ld (fire_walldist),a
  305.        call getuser_scr_high_cur
  306.        SETPG32KLOW
  307.        ld a,(fire_walldist)
  308.        ld hl,0x8000
  309.        ld bc,40
  310.        dup 8
  311.        ld (hl),7
  312.        rla
  313.        rr (hl)
  314.        add hl,bc
  315.        edup
  316.        
  317.         call SCANMONS      
  318. ;в cursprites лежат данные о видимых спрайтах (от задних к передним)
  319. ;ID 8 (0=end)
  320. ;dist 16
  321. ;xscr 8
  322. ;monster index
  323.         ld hl,cursprites
  324. fire_scan0
  325.         ld a,(hl)
  326.         or a
  327.         jp z,fire_scan0q
  328.         inc l
  329.         ld c,(hl)
  330.         inc l
  331.         ld b,(hl) ;bc=dist
  332.         ld d,b
  333.         ld e,c
  334.         inc l
  335.         dup 3;4
  336.         srl d
  337.         rr e
  338.         edup
  339.         ld a,d
  340.         or a
  341.         jr z,$+4
  342.          ld e,255
  343.         or e
  344.         jr nz,$+3
  345.          inc e
  346.         ld d,t1x/256
  347.         ld a,(de) ;width*k (for typical sprite width)
  348.         ld e,a
  349.         ld a,(hl) ;xscr (центр = 0x40)
  350.         sub e
  351.         jr nc,$+3
  352.          xor a ;a=sprite left margin
  353.         cp SCRWIDPIX/2;0x40;TODO связано с scrwid/2
  354.         jr nc,fire_miss
  355.         ld a,(hl) ;xscr
  356.         add a,e
  357.         jr nc,$+3
  358.          sbc a,a ;a=sprite right margin
  359.         cp SCRWIDPIX/2;0x40;TODO связано с scrwid/2
  360.         jr c,fire_miss
  361.         push hl
  362. ;не убивать, если стена впереди закрывает монстра (т.е. стена ближе)
  363. ;bc=dist
  364. ;приводим к 128..255
  365.         LD DE,#000
  366.         INC B
  367.         DEC B
  368.         LD A,C
  369.         jr Z,fire_MOTOLOGRLQ
  370.        DUP 5;6
  371.         INC D
  372.         SRL B
  373.         RRA
  374.         jr Z,fire_MOTOLOGRLE
  375.        EDUP
  376. fire_MOTOLOGRLQ ;
  377. fire_MOTOLOGRLE ;
  378.         LD C,A ;128..255 ;D=0..5
  379.         LD B,tlogd/256
  380.         LD A,(BC) ;log(dist) = 128..255 for arg>=128
  381.        if atm==0
  382.        SUB 16;64                 ;0..127 for arg=64..127 ;???
  383.        endif
  384.         LD C,A                ;0 for arg<64
  385.         LD B,tlogd2sca/256
  386.          SRA D
  387.          RR E ;DE=+0,+#80,..+#300
  388.         EXD
  389.         ADD HL,BC
  390.         LD a,(HL) ;scale#
  391.         pop hl
  392. fire_walldist=$+1
  393.         cp 0
  394.         jr c,fire_miss
  395.         push hl
  396.        
  397. ;найти этого монстра в таблице монстров
  398.         inc l
  399.         ld l,(hl) ;monster index
  400.         ld h,0
  401.         add hl,hl
  402.         add hl,hl
  403.         add hl,hl ;*8
  404.         ld bc,MONSTRS+1 ;Xx,Yy,TYPEphase,TIMEenergy
  405.         add hl,bc
  406.         ld (hl),0xc0 ;impossible X
  407.         ld a,0;5
  408.         call sfxplay
  409.         pop hl
  410. fire_miss
  411.        if CURSPRITES_RECSZ == 5
  412.        inc l
  413.        endif
  414.         inc l
  415.         jp fire_scan0
  416. fire_scan0q
  417.        
  418.        pop af
  419. nofire
  420.        push af
  421.  
  422. IMavision=$+1
  423.         LD HL,32*256
  424. IMdavision=$+1
  425.         LD DE,100
  426.         AND %10110011
  427.         CP 0
  428.         LD ($-1),A
  429.         jr Z,$+4
  430.         LD E,50 ;key just pressed/released
  431.        IF kempston&autostrafe
  432.         BIT 7,A
  433.         jr NZ,nAUTOROTATE
  434.         BIT 4,A
  435.         jr NZ,$+3
  436.         ADD HL,DE
  437.         BIT 5,A
  438.         jr NZ,$+4
  439.         SBC HL,DE
  440. nAUTOROTATE
  441.        ENDIF
  442.        IF doublerotate
  443.         RRA
  444.         jr C,$+4
  445.         ADD HL,DE
  446.         ADD HL,DE
  447.         RRA
  448.         jr C,$+6
  449.         SBC HL,DE
  450.         SBC HL,DE
  451.        ELSE
  452.         RRA
  453.         jr C,$+3
  454.         ADD HL,DE
  455.         RRA
  456.         jr C,$+4
  457.         SBC HL,DE
  458.        ENDIF
  459.  
  460.         LD A,E
  461.         ADD A,12;10
  462.         jr C,$+3
  463.          LD E,A ;key held: increase rotspd
  464.         LD (IMdavision),DE
  465.        IF mouse
  466.         LD BC,#FBDF
  467.         IN A,(C)
  468. mouseoldx=$+1
  469.         LD C,0
  470.         LD ($-1),A
  471. mouseon=$
  472.        IF demoplay
  473.         XOR A
  474.        ELSE
  475.         SUB C
  476.        ENDIF
  477.         NEG
  478.         LD E,A
  479.         RLA
  480.         SBC A,A
  481.         LD D,A
  482.         EXD
  483.         DUP 6
  484.         ADD HL,HL
  485.         EDUP
  486.         ADD HL,DE
  487.        ENDIF
  488.         LD (IMavision),HL
  489.  
  490. ;делим вектор на коэфф замедления
  491. IMcurDX=$+1
  492.         LD HL,0
  493.         LD B,H
  494.         ld A,L
  495.         SRA B
  496.         RRA
  497.        IF doublespeed
  498.         SRA B
  499.         RRA
  500.        ENDIF
  501.         LD C,A
  502.         CP B
  503.        jr NZ,$+3
  504.        LD C,L
  505.         SBC HL,BC
  506.         LD B,H
  507.         ld C,L
  508. CSLOWXQ
  509. IMcurDY=$+1
  510.         LD HL,0
  511.         LD D,H
  512.         ld A,L
  513.         SRA D
  514.         RRA
  515.        IF doublespeed
  516.         SRA D
  517.         RRA
  518.        ENDIF
  519.         LD E,A
  520.         CP D
  521.        jr NZ,$+3
  522.        LD E,L
  523.         SBC HL,DE
  524.         LD D,H
  525.         ld E,L
  526. CSLOWYQ
  527.        POP AF ;%00ADSWPO
  528.        RRCA
  529.        RRCA
  530.        AND 15
  531.         LD HL,tkeyangle
  532.         ADD A,L
  533.         LD L,A
  534.        IF (tkeyangle^tkeyangleend)&256
  535.         ADC A,H
  536.         SUB L
  537.         LD H,A
  538.        ENDIF
  539.         LD A,(HL)
  540. ;прибавляем вектор направления
  541. ;sin и cos (IMavision+32*N), где N=0..7 в зав. от клавиш
  542. ;0=forth
  543. ;64=left
  544.        CP -1
  545.        JP Z,CTRLnspeed
  546.         LD HL,IMavision+1
  547.         ADD A,(HL)
  548.         LD L,A
  549.         LD H,tcos/256 ;-pi/4..+pi/4
  550.         LD A,(HL)
  551.        ADD A,C
  552.        LD C,A
  553.        BIT 7,(HL)
  554.        jr NZ,$+3
  555.        INC B
  556.        jr C,$+3
  557.        DEC B
  558.         LD A,64
  559.         SUB L
  560.         LD L,A
  561.         LD A,(HL)
  562.        ADD A,E
  563.        LD E,A
  564.        BIT 7,(HL)
  565.        jr NZ,$+3
  566.        INC D
  567.        jr C,$+3
  568.        DEC D
  569. CTRLnspeed
  570.         LD (IMcurDX),BC
  571.         LD (IMcurDY),DE
  572.        DUP 2
  573.         SRA D
  574.         RR E
  575.         SRA B
  576.         RR C
  577.        EDUP
  578.  
  579.         LD HL,(IMcurXx)
  580.         ADD HL,BC
  581.         BIT 7,B
  582.        PUSH DE,HL
  583.         LD HL,(IMcurXx)
  584.         LD DE,256-mindist ;dx>0
  585.         jr Z,$+4
  586.         LD  E,mindist ;dx<0
  587.         ADD HL,DE
  588.         LD A,H
  589.         LD HL,(IMcurYy)
  590.         LD  E,mindist
  591.         SBC HL,DE
  592.         LD B,H
  593.         ADD HL,DE
  594.         ADD HL,DE
  595.         LD L,A
  596.         SET mapdifbit,L
  597.         LD A,(HL)
  598.         LD H,B
  599.         OR (HL)
  600.        POP HL,DE
  601.         RLA ;проходимо?
  602.         jr C,CTRLnX
  603.         LD (IMcurXx),HL
  604.         ;jr CTRLnXq
  605. CTRLnX
  606. ;непроходимо
  607. ;CTRLnXq
  608.         LD HL,(IMcurYy)
  609.         ADD HL,DE
  610.         BIT 7,D
  611.        PUSH HL
  612.         LD HL,(IMcurYy)
  613.         LD DE,256-mindist ;dx>0
  614.         jr Z,$+4
  615.         LD  E,mindist ;dx<0
  616.         ADD HL,DE
  617.         LD A,H
  618.         LD HL,(IMcurXx)
  619.         LD  E,mindist
  620.         SBC HL,DE
  621.         LD B,H
  622.         ADD HL,DE
  623.         ADD HL,DE
  624.         LD L,H
  625.         LD H,A
  626.         LD A,(HL)
  627.         LD L,B
  628.         OR (HL)
  629.        POP HL
  630.         RLA ;проходимо?
  631.        RET C
  632.         LD (IMcurYy),HL ;H!=0
  633.         RET
  634.  
  635. closecurrentdoor
  636. ;keeps hl,de
  637.         ld a,128+ID_DOOR;(hl)
  638. oldopendooraddr=$+1
  639.         ld (killablebyte),a
  640. oldopendooraddr2=$+1
  641.         ld (killablebyte),a
  642.        ld bc,killablebyte
  643.        ld (oldopendooraddr),bc
  644.        ld (oldopendooraddr2),bc
  645.         ret
  646. killablebyte
  647.         db 0
  648.