fixed game logic bug with jumping; fixed demo saving
[awish.git] / asm / game / loops_main.awa
blob85a5c4a143a0ebb0c46d65f87ae780ba0890563a
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 /* cheat: fly up */
16 game_cheat_up:
17   set [pos_ty], -3
18   bsr game_next_frame
19   set [pos_ty], -6
20   bsr game_next_frame
21   set [pos_ty], 0
22   sub [pos_y], 1
23   bsr prof_fix_position
24   bsr game_do_scrolls
25   ret
27 /* cheat: fly down */
28 game_cheat_down:
29   set [pos_ty], 3
30   bsr game_next_frame
31   set [pos_ty], 6
32   bsr game_next_frame
33   set [pos_ty], 0
34   add [pos_y], 1
35   bsr prof_fix_position
36   bsr game_do_scrolls
37   ret
40 /* stand facing, wait 2 frames before any action */
41 game_facing_loop_w2f:
42   set [spr_num], PSPR_FACING
43   set [spr_dir], DIR_LEFT
44   set [prof_dir], PDIR_FACING
45   bsr game_next_frame
46   bsr game_next_frame
48 game_facing_loop:
49   deflvar: .tid
50   ;
51   bsr clear_stack
52   set [spr_num], PSPR_FACING
53   set [spr_dir], DIR_LEFT
54   set [prof_dir], PDIR_FACING
55   bsr game_do_scrolls
56   bsr game_check_fall
57   ;
58   ; fans?
59   mgf [pos_x], [pos_y]
60   jne .nofan, FTILE_ICE
61   bsr game_check_fans
62   jeq .nofan, [game_fan_dx_v], 0
63   set [prof_dir], [game_fan_dx_v]
64   bsr prof_turn_to_dir
65   jmp game_check_do_slide_move
66 .nofan:
67   ;
68 .facing_loop:
69   bsr game_do_scrolls
70   bsr game_check_fall
71   bsr game_is_on_exit
72   jne game_do_door_exit, 0
73   bsr game_check_monster_eating
74   set [game_want_key], 1
75   bsr game_next_frame
76   ; if we are still here, there was no falling
77   jne .pick_facing, [key_take], 0
78   ;
79   jeq .nouse, [prof_item], 0
80   jne .use_facing, [key_use], 0
81 .nouse:
82   ;
83   jeq .nowc, [key_walk_cheat], 0
84   psh game_facing_loop
85   jne game_cheat_up, [key_up], 0
86   jne game_cheat_down, [key_down], 0
87   drp
88   ;
89 .nowc:
90   mgf [pos_x], [pos_y]
91   jne .no_lift, FTILE_LIFT
92   jne .lift_up, [key_up], 0
93   jne .lift_down, [key_down], 0
94   ;
95 .no_lift:
96   jne game_turning_right, [key_right], 0
97   jne game_turning_left, [key_left], 0
98   jmp .facing_loop
99   ;
100 .lift_up:
101   jle .no_lift, [pos_y], 4
102   ; have space at up?
103   bsr get_tile_at_dy, -5
104   /*
105   psh [pos_x]
106   psh [pos_y]
107   psh 5
108   sub
109   mgf
110   */
111   jne .no_lift, 0
112   ;
113   bsr game_lift_all_items, -1  ; kick up all items on lift
114   ;
115   new entry_lift, [.tid]
116   set pos_x, [pos_x], [.tid]
117   set pos_y, [pos_y], [.tid]
118   set pos_ty, -2, [.tid]
119   ; move prof
120   set [pos_ty], -2
121   bsr game_next_frame
122   set [pos_ty], -4
123   bsr game_next_frame
124   set [pos_ty], -6
125   bsr game_next_frame
126   set [pos_ty], -8
127   bsr game_next_frame
128   set [pos_ty], 0
129   sub [pos_y], 1
130   msf [pos_x], [pos_y], FTILE_LIFT
131   jmp .facing_loop
132   ;
133 .lift_down:
134   set [.tid], [map_height]
135   sub [.tid], 1
136   jge .no_lift, [pos_y], [.tid]
137   ; have space at bottom?
138   psh [pos_x]
139   psh [pos_y]
140   psh 1
141   add
142   mgf
143   jne .no_lift, 0
144   ;
145   bsr game_lift_all_items, 1
146   ;
147   new entry_lift, [.tid]
148   set pos_x, [pos_x], [.tid]
149   set pos_y, [pos_y], [.tid]
150   set pos_ty, 2, [.tid]
151   ; move prof
152   set [pos_ty], 2
153   bsr game_next_frame
154   set [pos_ty], 4
155   bsr game_next_frame
156   set [pos_ty], 6
157   bsr game_next_frame
158   set [pos_ty], 8
159   bsr game_next_frame
160   set [pos_ty], 0
161   add [pos_y], 1
162   msf [pos_x], [pos_y], FTILE_LIFT
163   jmp .facing_loop
164   ;
165 .use_facing:
166   get [prof_item], item_id
167   jne .nouse, ITEM_DRILL
168   ; use drill
169 @facing_drill_use:
170   ;FIXME: can we drill lift?
171   mgf [pos_x], [pos_y]
172   jeq game_no_no, FTILE_LIFT
173   mgf [pos_x], [pos_y]
174   jge game_no_no, FTILE_STEEL
175   ;
176   new entry_drill, [.tid]
177   set pos_x, [pos_x], [.tid]
178   set pos_y, [pos_y], [.tid]
179   rst FRST_PLAY_SOUND, SND_DRILL
180   ;
181 .loop:
182   set [spr_num], PSPR_DRILLING0
183   bsr game_next_frame
184   set [spr_num], PSPR_DRILLING1
185   bsr game_next_frame
186   sta [.tid]
187   jeq .loop, 0
188   set [spr_num], PSPR_FACING
189   jmp .facing_loop
190   ;
191 .pick_facing:
192   bsr game_do_pick, PDIR_FACING
193   jmp .facing_loop
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 game_do_pick_lr:
198   psh [prof_dir]
199   bsr prof_turn_to_player
200   dup ; arg to game_do_pick
201   bsr game_do_pick
202   pop [prof_dir]
203   bsr prof_turn_to_dir
204   ret
207 game_turning_left:
208   set [prof_dir], PDIR_LEFT
209   jmp game_do_turnings
210 game_turning_right:
211   set [prof_dir], PDIR_RIGHT
212 game_do_turnings:
213   bsr prof_turn_to_dir
216 game_lr_stand_loop:
217   deflvar: .type
218   ;
219   bsr game_do_scrolls
220   bsr game_check_fall
221   bsr game_is_on_exit
222   jne game_do_door_exit, 0
223   bsr game_check_monster_eating
224   set [game_want_key], 1
225   bsr game_next_frame
226   ; if we are still here, there was no falling
227   jeq .nopickup, [key_take], 0
228   bsr game_do_pick_lr
229   jmp game_lr_stand_loop
230 .nopickup:
231   ;
232   jeq .nouse, [prof_item], 0
233   jne .use_item, [key_use], 0
234 .nouse:
235   ;
236   jeq .nowc, [key_walk_cheat], 0
237   psh game_lr_stand_loop
238   jne game_cheat_up, [key_up], 0
239   jne game_cheat_down, [key_down], 0
240   drp
241   ;
242 .nowc:
243   jeq .nojump, [key_up], 0
244   bsr game_do_jump
245   jne game_lr_stand_loop, 0  ; do it all again if there were no jump
246   ; returns? can't jump
247 .nojump:
248   jeq .noturnface, [key_down], 0
249   set [prof_dir], PDIR_FACING
250   bsr prof_turn_to_dir
251   jmp game_facing_loop
252 .noturnface:
253   jne .walk_right, [key_right], 0
254   jne .walk_left, [key_left], 0
255 .nowalk:
256   bsr game_next_frame
257   jmp game_lr_stand_loop
258   ;
259 .walk_right:
260   jeq .walk, [prof_dir], PDIR_RIGHT
261   set [prof_dir], PDIR_RIGHT
262   bsr prof_turn_to_dir
263   jmp game_lr_stand_loop
264   ;
265 .walk_left:
266   jeq .walk, [prof_dir], PDIR_LEFT
267   set [prof_dir], PDIR_LEFT
268   bsr prof_turn_to_dir
269   jmp game_lr_stand_loop
270   ;
271 .walk:
272   bsr game_can_walk
273   jeq .nowalk, 0
274   jmp game_do_side_move
276 include: use.awa