alot of code changed; first try to move level loader out of C engine; not working yet
[awish.git] / asm / game / dodie.awa
blob43467646329e52813c85c56ede5a5c542fca9e47
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 ; in:
16 ;  monster_tid: monster tid
17 game_do_die_monster:
18   set [rst_result], entry_die_monster
19   jmp game_do_die
22 game_do_die_fall:
23   set [monster_tid], -1
24   set [rst_result], entry_die_fall
25   jmp game_do_die
28 ; in:
29 ;  monster_tid: monster thread id or -1
30 ;  rst_result: new thread PC
32 proc: game_do_die
33 locals: .tid
34   ; create and init animation thread
35   new [rst_result], [.tid]
36   set monster_tid, [monster_tid], [.tid]
37   set pos_x, [pos_x], [.tid]
38   set pos_y, [pos_y], [.tid]
39   set spr_bank, [spr_bank], [.tid]
40   set spr_num, [spr_num], [.tid]
41   set spr_dir, [spr_dir], [.tid]
42   ;
43   set [spr_num], -1 ; hide 'original' prof
44   ;
45 .waitthread:
46   bsr game_next_frame
47   sta [.tid]
48   jeq .waitthread, THREAD_STATE_RUNNING
49   ;
50   set [game_state], GAME_STATE_DEAD
51   jmp game_wait_and_restart
52 endp: game_do_die
55 proc: game_wait_and_restart
56   bsr clear_stack
57   set [key_use], 0
58   set [key_start], 0
59   set [key_take], 0
60   ;
61 .waitrestart:
62   bsr game_next_frame
63   jne .dorestart, [key_use], 0
64   jne .dorestart, [key_start], 0
65   jne .dorestart, [key_take], 0
66   jmp .waitrestart
67   ;
68 .dorestart:
69   jmp entry_game_restart_level
70 endp: game_wait_and_restart
73 /* thread: prof blinks and falls dead */
74 proc: entry_die_fall
75 locals: .f, .c
76   jeq .facing, [spr_num], PSPR_FACING
77   ; turnning
78   set [spr_num], PSPR_TURNING
79   brk
80   brk
81   set [spr_dir], DIR_LEFT
82   set [spr_num], PSPR_FACING
83   brk
84   brk
85 .facing:
86   ; blinking
87   set [.f], 2
88 .deadloop:
89   set [spr_num], PSPR_CLOSED_EYES
90   psh 10
91   bsr wait_some_frames
92   set [spr_num], PSPR_FACING
93   psh 10
94   bsr wait_some_frames
95   sub [.f], 1
96   jgt .deadloop, [.f], 0
97   ;
98   set [spr_num], PSPR_CLOSED_EYES
99 .animloop:
100   brk
101   brk
102   add [spr_num], 1
103   jle .animloop, [spr_num], PSPR_LYING_DEAD
104   ;
105   set spr_num, PSPR_LYING_DEAD, 0
106   end
107 endp: entry_die_fall
110 /* thread: prof eaten by Harry */
111 proc: entry_die_monster
112   jeq .facing, [spr_num], PSPR_FACING
113   ; turnning
114   set [spr_num], PSPR_TURNING
115   brk
116   brk
117   set [spr_dir], DIR_LEFT
118   set [spr_num], PSPR_FACING
119   brk
120   brk
121 .facing:
122   ; suspend monster thread (so Harry will not be drawn)
123   sus [monster_tid]
124   ;
125   set [spr_num], PSPR_HARRY_EATS_PROF_START
126 .animloop:
127   brk
128   brk
129   brk
130   add [spr_num], 1
131   jle .animloop, [spr_num], PSPR_HARRY_EATS_PROF_END
132   ; resume monster thread (so Harry will be drawn again)
133   res [monster_tid]
134   end
135 endp: entry_die_monster
138 proc: wait_some_frames
139 arg: .cnt
140 .loop:
141   jlt .done, [.cnt], 1
142   brk
143   sub [.cnt], 1
144   jmp .loop
145 .done:
146   ret
147 endp: wait_some_frames