alot of code changed; first try to move level loader out of C engine; not working yet
[awish.git] / asm / game / use / key.awa
blob09527941201039cb947fbb175da065e0b87d30d2
1 /*
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
14  */
15 proc: game_use_key
16 deflvar: .dx, .t  ; don't change to locals!
17   ;
18   set frozen, 1, [prof_item]
19   set spr_dir, [spr_dir], [prof_item]
20   set pos_ty, -12, [prof_item]
21   mul [prof_dir], 8, [.dx]
22   res [prof_item]
23   ; 10
24   add [.dx], [prof_dir]
25   add [.dx], [prof_dir]
26   set pos_tx, [.dx], [prof_item]
27   bsr game_next_frame
28   ; 12
29   set [spr_num], PSPR_USING
30   add [.dx], [prof_dir]
31   add [.dx], [prof_dir]
32   set pos_tx, [.dx], [prof_item]
33   bsr game_next_frame
34   ; 14
35   add [.dx], [prof_dir]
36   add [.dx], [prof_dir]
37   set pos_tx, [.dx], [prof_item]
38   bsr game_next_frame
39   ; 16
40   add [.dx], [prof_dir]
41   add [.dx], [prof_dir]
42   set pos_tx, [.dx], [prof_item]
43   bsr game_next_frame
44   ;
45   ; check and open the door
46   ;
47   psh [pos_x]
48   psh [prof_dir]
49   add
50   psh [pos_y]
51   psh -2
52   add
53   mgb
54   jne .notdoor, BTILE_DOOR_LOCK
55   ;
56   psh [pos_x]
57   psh [prof_dir]
58   add
59   psh [pos_y]
60   psh -2
61   add
62   mgf
63   jne .notdoor, FTILE_EMPTY
64   ; open
65   set [.dx], -4
66 .openloop:
67   psh [pos_x]
68   psh [prof_dir]
69   add
70   psh [pos_y]
71   psh [.dx]
72   add
73   mgb [.t]
74   jlt .skip, [.t], BTILE_DOORS_CS
75   jgt .skip, [.t], BTILE_DOORS_CE
76   ;
77   psh [pos_x]
78   psh [prof_dir]
79   add
80   psh [pos_y]
81   psh [.dx]
82   add
83   add [.t], BTILE_DOOR_ADD_TO_OPEN
84   msb [.t]
85 .skip:
86   add [.dx], 1
87   jlt .openloop, [.dx], 0
88   ; key should disappear now
89   kil [prof_item]
90   set [prof_item], 0
91   bsr set_item_name_vars, [prof_item]
92   set [spr_num], PSPR_STANDING
93   ret
94   ;
95 .notdoor:
96   ; 14
97   sub [.dx], [prof_dir]
98   sub [.dx], [prof_dir]
99   set pos_tx, [.dx], [prof_item]
100   bsr game_next_frame
101   ; 12
102   sub [.dx], [prof_dir]
103   sub [.dx], [prof_dir]
104   set pos_tx, [.dx], [prof_item]
105   bsr game_next_frame
106   set [spr_num], PSPR_STANDING
107   ; 10
108   sub [.dx], [prof_dir]
109   sub [.dx], [prof_dir]
110   set pos_tx, [.dx], [prof_item]
111   bsr game_next_frame
112   ;
113   set pos_tx, 0, [prof_item]
114   set pos_ty, 0, [prof_item]
115   set spr_dir, 0, [prof_item]
116   set frozen, 0, [prof_item]
117   sus [prof_item]
118   ret
119 endp: game_use_key