1 @ 3 ! ( init )
6 3 pick * 2 @ + 8 3 pick * 1 @ + 3 @ color putpixel
2 drop repeat ( endfor )
1 drop repeat ( endfor )
drop drop drop ; ( ret )
: Fill ( x y w h c -- )
4 pick ! ( init )
begin @ 5 pick 4 pick + <<> while ( for )
3 pick 1 ! ( init )
begin 1 @ 4 pick 3 pick + <<> while ( for )
@ 1 @ 2 pick SetTile
1 drop repeat ( endfor )
drop repeat ( endfor )
drop drop drop drop drop ; ( ret )
:: ClearVsyncFlag ( -- )
; ( ret )
:: GetVsyncFlag ( -- n )
1 ( forth )
; ( ret )
1 textx ( var )
0 textx ! ( init )
1 texty ( var )
0 texty ! ( init )
: chr6x8 ( n -- )
fonts 48 2 pick * 1 * + ! ( init )
0 1 ! ( init )
begin 1 @ 8 <<> while ( for )
0 2 ! ( init )
begin 2 @ 6 <<> while ( for )
1 @ 3 ! ( init )
textx @ 2 @ + texty @ 1 @ + 3 @ color putpixel
2 drop repeat ( endfor )
1 drop repeat ( endfor )
drop ; ( ret )
: printc ( c -- )
dup 0x20 - chr6x8
textx 6 <+=> drop
drop ; ( ret )
: printd ( d -- )
0x0F & dup 10 < if 0x30 else 0x37 then + printc ( forth )
; ( ret )
: PrintByte ( b x y -- )
textx 6 3 pick * <=> drop
texty 8 2 pick * <=> drop
2 pick 4 >> printd
2 pick printd
drop drop drop ; ( ret )
: Print ( s x y -- )
textx 6 3 pick * <=> drop
texty 8 2 pick * <=> drop
0 ! ( init )
begin 2 pick @ chr while ( while )
2 pick chr printc
repeat ( endwhile )
drop drop drop ; ( ret )
: DrawMap ( m -- )
dup ! ( init )
0 1 ! ( init )
begin 1 @ 28 <<> while ( for )
0 2 ! ( init )
begin 2 @ 40 <<> while ( for )
2 @ 1 @ 1 @ SetTile
2 drop repeat ( endfor )
1 drop repeat ( endfor )
drop ; ( ret )
1 mode ( var )
1 upd ( var )
1 strPress ( var )
"PRESS" strPress ! ( init )
1 strStart ( var )
"START" strStart ! ( init )
1 strWinner ( var )
"WINNER!" strWinner ! ( init )
1 strLoser ( var )
"LOSER!" strLoser ! ( init )
1 strWin ( var )
"WIN" strWin ! ( init )
20 current_pill ( var )
20 next_pill ( var )
1 gravity ( var )
60 gravity ! ( init )
1 round_time ( var )
1 auto_repeat_counter ( var )
0 auto_repeat_counter ! ( init )
286 bottle ( var )
1 virus_anim_counter ( var )
0 virus_anim_counter ! ( init )
1 drop_floater_timer ( var )
0 drop_floater_timer ! ( init )
1 x ( var )
1 y ( var )
1 j ( var )
1 k ( var )
1 saved_state ( var )
1 z ( var )
0 z ! ( init )
2 difficulty_level ( var )
1 difficulty_level ! ( init )
1 difficulty_level 1 + ! ( init )
2 round_lost ( var )
2 rounds_won ( var )
1 move_type ( var )
0 move_type ! ( init )
1 long_timer ( var )
: SetStageSettings ( -- )
upd @ if ( if )
main_board SetTileTable
drmario_map_stage_select DrawMap
"2 PLAYER GAME" 14 5 Print
"LEVEL" 7 7 Print
upd 0 <=> drop
button 0 <=> drop
then ( endif )
difficulty_level 0 + @ 31 9 PrintByte
difficulty_level 1 + @ 31 11 PrintByte
difficulty_level 0 + @ 8 + 9 54 SetTile
difficulty_level 1 + @ 8 + 11 55 SetTile
0 ReadJoypad <=> if ( if )
then ( endif )
@ 4 & if difficulty_level 0 + @ 20 <<> else 0 then if ( if )
difficulty_level 0 + 8 + 9 0 SetTile
button 0 <=> drop
else ( else )
@ 2 & if difficulty_level 0 + @ 1 <>> else 0 then if ( if )
difficulty_level 0 + 8 + 9 0 SetTile
button 0 <=> drop
then ( endif )
then ( endif )
@ 8 & if ( if )
mode 2 <=> drop
upd 1 <=> drop
rounds_won 0 + 0 <=> drop
rounds_won 1 + 0 <=> drop
then ( endif )
; ( ret )
2 holdKey ( var )
: grab_input ( player -- n )
dup ReadJoypad ! ( init )
@ 1 & if ( if )
holdKey over + 0 <=> drop
then ( endif )
auto_repeat_counter 4 <<> if ( if )
0 nip return ( ret )
then ( endif )
auto_repeat_counter 0 <=> drop
@ 1 & if holdKey over + @ 0 <==> else 0 then if ( if )
holdKey over + 1 <=> drop
4 nip return ( ret )
else ( else )
@ 4 & if ( if )
2 nip return ( ret )
else ( else )
@ 2 & if ( if )
1 nip return ( ret )
else ( else )
@ 8 & if ( if )
3 nip return ( ret )
then ( endif )
then ( endif )
then ( endif )
then ( endif )
0 nip return ( ret )
; ( ret )
: DissapearAnim ( player -- )
bottle over 143 <[]> 140 + 0 <=> drop
dup if 28 else 4 then ! ( init )
x 0 <=> drop
begin x @ 8 <<> while ( for )
y 0 <=> drop
begin y @ 17 <<> while ( for )
bottle over 143 <[]> x @ 17 <[]> y @ + @ 22 <>=> if bottle over 143 <[]> x @ 17 <[]> y @ + @ 24 <<=> else 0 then if ( if )
@ x @ + 8 y @ + bottle 3 pick 143 <[]> x @ 17 <[]> y @ + <++i> SetTile
bottle over 143 <[]> 140 + 1 <=> drop
else ( else )
bottle over 143 <[]> x @ 17 <[]> y @ + @ 25 <==> if ( if )
@ x @ + 8 y @ + bottle 3 pick 143 <[]> x @ 17 <[]> y @ + 0 <=> SetTile
bottle over 143 <[]> 140 + 1 <=> drop
then ( endif )
then ( endif )
y drop repeat ( endfor )
x drop repeat ( endfor )
drop ; ( ret )
: NextPill ( player -- )
next_pill over 10 <[]> 2 + 24 2 pick * 7 + <=> next_pill 2 pick 10 <[]> 3 + 8 2 - <=> next_pill 3 pick 10 <[]> 8 + rand 3 <%> 2 * 1 + <=> SetTile
next_pill over 10 <[]> 2 + @ 1 + next_pill 2 pick 10 <[]> 3 + @ next_pill 3 pick 10 <[]> 9 + rand 3 <%> 2 * 2 + <=> SetTile
drop ; ( ret )
: NewPill ( player -- )
bottle over 143 <[]> 3 17 <[]> 0 + @ if 1 else bottle over 143 <[]> 4 17 <[]> 0 + @ then if ( if )
round_lost over + 1 <=> drop
drop return ( ret )
then ( endif )
current_pill over 10 <[]> 2 + 24 2 pick * 7 + <=> drop
current_pill over 10 <[]> 4 + 3 <=> drop
current_pill over 10 <[]> 3 + 8 <=> drop
current_pill over 10 <[]> 5 + 0 <=> drop
current_pill over 10 <[]> 0 <=> drop
current_pill over 10 <[]> 1 + 2 <=> drop
current_pill over 10 <[]> 8 + next_pill 2 pick 10 <[]> 8 + @ <=> drop
current_pill over 10 <[]> 9 + next_pill 2 pick 10 <[]> 9 + @ <=> drop
current_pill over 10 <[]> 2 + @ current_pill 2 pick 10 <[]> 3 + @ current_pill 3 pick 10 <[]> 8 + @ SetTile
current_pill over 10 <[]> 2 + @ 1 + current_pill 2 pick 10 <[]> 3 + @ current_pill 3 pick 10 <[]> 9 + @ SetTile
dup NextPill
drop ; ( ret )
: LockPill ( player -- )
current_pill over 10 <[]> @ if ( if )
bottle over 143 <[]> current_pill 2 pick 10 <[]> 4 + @ 17 <[]> current_pill 2 pick 10 <[]> 5 + @ 1 - + current_pill 2 pick 10 <[]> 6 + @ <=> drop
bottle over 143 <[]> current_pill 2 pick 10 <[]> 4 + @ 17 <[]> current_pill 2 pick 10 <[]> 5 + @ + current_pill 2 pick 10 <[]> 7 + @ <=> drop
else ( else )
bottle over 143 <[]> current_pill 2 pick 10 <[]> 4 + @ 17 <[]> current_pill 2 pick 10 <[]> 5 + @ + current_pill 2 pick 10 <[]> 8 + @ <=> drop
bottle over 143 <[]> current_pill 2 pick 10 <[]> 4 + @ 1 + 17 <[]> current_pill 2 pick 10 <[]> 5 + @ + current_pill 2 pick 10 <[]> 9 + @ <=> drop
then ( endif )
bottle over 143 <[]> 137 + 1 <=> drop
drop ; ( ret )
: MovePill ( player move_type -- n )
0 ! ( init )
dup switch ( switch )
3 case ( case )
current_pill 3 pick 10 <[]> 3 + @ 24 <==> if ( if )
2 pick LockPill
bottle 3 pick 143 <[]> 142 + 1 <=> drop
break ( break )
then ( endif )
current_pill 3 pick 10 <[]> @ if ( if )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 + + @ if ( if )
2 pick LockPill
bottle 3 pick 143 <[]> 142 + 1 <=> drop
else ( else )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 1 + @ - 1 + 0 SetTile
current_pill 3 pick 10 <[]> 3 + drop
current_pill 3 pick 10 <[]> 5 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - current_pill 5 pick 10 <[]> 6 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 7 + @ SetTile
1 <=> drop
then ( endif )
else ( else )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 + + @ if 1 else bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 + 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 + + @ then if ( if )
2 pick LockPill
bottle 3 pick 143 <[]> 142 + 1 <=> drop
else ( else )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 1 + @ 1 0 Fill
current_pill 3 pick 10 <[]> 3 + drop
current_pill 3 pick 10 <[]> 5 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 8 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ 1 + current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 9 + @ SetTile
1 <=> drop
then ( endif )
then ( endif )
break ( break )
1 case ( case )
current_pill 3 pick 10 <[]> 4 + @ 0 <==> if ( if )
break ( break )
then ( endif )
current_pill 3 pick 10 <[]> @ if ( if )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 - 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ if 1 else bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 - 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 - + @ then if ( if )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - 1 current_pill 6 pick 10 <[]> 1 + @ 0 Fill
current_pill 3 pick 10 <[]> 2 + drop
current_pill 3 pick 10 <[]> 4 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - current_pill 5 pick 10 <[]> 6 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 7 + @ SetTile
1 <=> drop
then ( endif )
else ( else )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 - 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ if ( if )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 1 + @ 1 0 Fill
current_pill 3 pick 10 <[]> 2 + drop
current_pill 3 pick 10 <[]> 4 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 8 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ 1 + current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 9 + @ SetTile
1 <=> drop
then ( endif )
then ( endif )
break ( break )
2 case ( case )
current_pill 3 pick 10 <[]> @ if ( if )
current_pill 3 pick 10 <[]> 4 + @ 8 1 - <==> if ( if )
break ( break )
then ( endif )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 + 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ if 1 else bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 + 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 - + @ then if ( if )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - 1 current_pill 6 pick 10 <[]> 1 + @ 0 Fill
current_pill 3 pick 10 <[]> 2 + drop
current_pill 3 pick 10 <[]> 4 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - current_pill 5 pick 10 <[]> 6 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 7 + @ SetTile
1 <=> drop
then ( endif )
else ( else )
current_pill 3 pick 10 <[]> 4 + @ 8 2 - <==> if ( if )
break ( break )
then ( endif )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 2 + 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ if ( if )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 0 SetTile
current_pill 3 pick 10 <[]> 2 + drop
current_pill 3 pick 10 <[]> 4 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 8 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ 1 + current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 9 + @ SetTile
1 <=> drop
then ( endif )
then ( endif )
break ( break )
4 case ( case )
current_pill 3 pick 10 <[]> @ if ( if )
current_pill 3 pick 10 <[]> 4 + @ 8 1 - <==> if 1 else bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 + 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ then if ( if )
2 pick 1 MovePill if ( if )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 1 - 17 <[]> current_pill 4 pick 10 <[]> 5 + @ + @ 0 <==> if ( if )
current_pill 3 pick 10 <[]> 4 + @ 0 <==> if ( if )
break ( break )
then ( endif )
current_pill 3 pick 10 <[]> 8 + current_pill 4 pick 10 <[]> 6 + @ <=> drop
current_pill 3 pick 10 <[]> 9 + current_pill 4 pick 10 <[]> 7 + @ <=> drop
current_pill 3 pick 10 <[]> 8 + 7 <-=> drop
current_pill 3 pick 10 <[]> 9 + 5 <-=> drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - 0 SetTile
current_pill 3 pick 10 <[]> 2 + drop
current_pill 3 pick 10 <[]> 4 + drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 8 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ 1 + current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 9 + @ SetTile
current_pill 3 pick 10 <[]> 0 <=> drop
1 <=> drop
then ( endif )
break ( break )
then ( endif )
then ( endif )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - 1 2 0 Fill
current_pill 3 pick 10 <[]> 8 + current_pill 4 pick 10 <[]> 6 + @ <=> drop
current_pill 3 pick 10 <[]> 9 + current_pill 4 pick 10 <[]> 7 + @ <=> drop
current_pill 3 pick 10 <[]> 8 + 7 <-=> drop
current_pill 3 pick 10 <[]> 9 + 5 <-=> drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 8 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ 1 + current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 9 + @ SetTile
current_pill 3 pick 10 <[]> 0 <=> drop
1 <=> drop
else ( else )
current_pill 3 pick 10 <[]> 5 + @ 0 <==> if ( if )
2 pick 3 MovePill if ( if )
break ( break )
then ( endif )
then ( endif )
bottle 3 pick 143 <[]> current_pill 4 pick 10 <[]> 4 + @ 17 <[]> current_pill 4 pick 10 <[]> 5 + @ 1 - + @ if ( if )
2 pick 3 MovePill if ( if )
break ( break )
then ( endif )
then ( endif )
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 2 1 0 Fill
current_pill 3 pick 10 <[]> 7 + current_pill 4 pick 10 <[]> 8 + @ <=> drop
current_pill 3 pick 10 <[]> 6 + current_pill 4 pick 10 <[]> 9 + @ <=> drop
current_pill 3 pick 10 <[]> 6 + 6 <+=> drop
current_pill 3 pick 10 <[]> 7 + 6 <+=> drop
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ 1 - current_pill 5 pick 10 <[]> 6 + @ SetTile
current_pill 3 pick 10 <[]> 2 + @ current_pill 4 pick 10 <[]> 3 + @ current_pill 5 pick 10 <[]> 7 + @ SetTile
1 <=> drop
current_pill 3 pick 10 <[]> 1 <=> drop
then ( endif )
endswitch ( endswitch )
@ nip nip return ( ret )
; ( ret )
: SplitPill ( player x y -- )
2 pick if 28 else 4 then ! ( init )
bottle 3 pick 143 <[]> 137 + 0 <=> drop
bottle 3 pick 143 <[]> 2 pick 17 <[]> over + @ switch ( switch )
1 case ( case )
3 case ( case )
5 case ( case )
bottle 4 pick 143 <[]> 3 pick 1 + 17 <[]> 2 pick + @ switch ( switch )
2 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 + 17 <[]> 3 pick + 13 <=> drop
@ 4 pick + 1 + 8 4 pick + 13 SetTile
break ( break )
4 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 + 17 <[]> 3 pick + 14 <=> drop
@ 4 pick + 1 + 8 4 pick + 14 SetTile
break ( break )
6 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 + 17 <[]> 3 pick + 15 <=> drop
@ 4 pick + 1 + 8 4 pick + 15 SetTile
endswitch ( endswitch )
break ( break )
2 case ( case )
4 case ( case )
6 case ( case )
bottle 4 pick 143 <[]> 3 pick 1 - 17 <[]> 2 pick + @ switch ( switch )
1 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 - 17 <[]> 3 pick + 13 <=> drop
@ 4 pick + 1 - 8 4 pick + 13 SetTile
break ( break )
3 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 - 17 <[]> 3 pick + 14 <=> drop
@ 4 pick + 1 - 8 4 pick + 14 SetTile
break ( break )
5 case ( case )
bottle 5 pick 143 <[]> 4 pick 1 - 17 <[]> 3 pick + 15 <=> drop
@ 4 pick + 1 - 8 4 pick + 15 SetTile
endswitch ( endswitch )
break ( break )
7 case ( case )
9 case ( case )
11 case ( case )
bottle 4 pick 143 <[]> 3 pick 17 <[]> 2 pick 1 - + @ switch ( switch )
8 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 - + 13 <=> drop
@ 4 pick + 8 4 pick + 1 - 13 SetTile
break ( break )
10 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 - + 14 <=> drop
@ 4 pick + 8 4 pick + 1 - 14 SetTile
break ( break )
12 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 - + 15 <=> drop
@ 4 pick + 8 4 pick + 1 - 15 SetTile
endswitch ( endswitch )
break ( break )
8 case ( case )
10 case ( case )
12 case ( case )
bottle 4 pick 143 <[]> 3 pick 17 <[]> 2 pick 1 + + @ switch ( switch )
7 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 + + 13 <=> drop
@ 4 pick + 8 4 pick + 1 + 13 SetTile
break ( break )
9 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 + + 14 <=> drop
@ 4 pick + 8 4 pick + 1 + 14 SetTile
break ( break )
11 case ( case )
bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 + + 15 <=> drop
@ 4 pick + 8 4 pick + 1 + 15 SetTile
endswitch ( endswitch )
endswitch ( endswitch )
drop drop drop ; ( ret )
: CheckColorMatch ( tile1 tile2 -- n )
over switch ( switch )
1 case ( case )
2 case ( case )
7 case ( case )
8 case ( case )
13 case ( case )
16 case ( case )
17 case ( case )
over switch ( switch )
1 case ( case )
2 case ( case )
7 case ( case )
8 case ( case )
13 case ( case )
16 case ( case )
17 case ( case )
1 nip nip nip nip return ( ret )
endswitch ( endswitch )
break ( break )
3 case ( case )
4 case ( case )
9 case ( case )
10 case ( case )
14 case ( case )
18 case ( case )
19 case ( case )
over switch ( switch )
3 case ( case )
4 case ( case )
9 case ( case )
10 case ( case )
14 case ( case )
18 case ( case )
19 case ( case )
1 nip nip nip nip return ( ret )
endswitch ( endswitch )
break ( break )
default ( default )
over switch ( switch )
5 case ( case )
6 case ( case )
11 case ( case )
12 case ( case )
15 case ( case )
20 case ( case )
21 case ( case )
1 nip nip nip nip return ( ret )
endswitch ( endswitch )
endswitch ( endswitch )
0 nip nip return ( ret )
; ( ret )
: CheckMatching4 ( player -- )
1 ! ( init )
dup if 28 else 4 then 1 ! ( init )
dup if 21 else 17 then 2 ! ( init )
bottle over 143 <[]> 137 + 0 <=> drop
x 0 <=> drop
begin x @ 8 <<> while ( for )
y 0 <=> drop
begin y @ 17 <<> while ( for )
bottle over 143 <[]> x @ 17 <[]> y @ + @ if ( if )
1 <=> drop
j 0 <=> drop
begin j @ 17 <<> while ( for )
y @ j @ + 1 + 17 <>> if ( if )
break ( break )
then ( endif )
bottle over 143 <[]> x @ 17 <[]> y @ j @ + + @ bottle 2 pick 143 <[]> x @ 17 <[]> y @ j @ + 1 + + @ CheckColorMatch if ( if )
drop
else ( else )
@ 4 <>=> if ( if )
j 0 <=> drop
begin j @ @ <<> while ( for )
dup x @ y @ j @ + SplitPill
bottle over 143 <[]> 139 + 1 <=> drop
bottle over 143 <[]> x @ 17 <[]> y @ j @ + + @ 16 <>=> if bottle over 143 <[]> x @ 17 <[]> y @ j @ + + @ 21 <<=> else 0 then if ( if )
bottle over 143 <[]> 136 + <--i> 2 @ 23 PrintByte
then ( endif )
bottle over 143 <[]> x @ 17 <[]> y @ j @ + + 22 <=> drop
j drop repeat ( endfor )
1 @ x @ + 8 y @ + 1 @ 22 Fill
bottle over 143 <[]> 140 + 1 <=> drop
bottle over 143 <[]> 137 + 1 <=> drop
bottle over 143 <[]> 138 + drop
then ( endif )
break ( break )
then ( endif )
j drop repeat ( endfor )
1 <=> drop
j 0 <=> drop
begin j @ 8 <<> while ( for )
x @ j @ + 1 + 8 <>> if ( if )
break ( break )
then ( endif )
bottle over 143 <[]> x @ j @ + 17 <[]> y @ + @ bottle 2 pick 143 <[]> x @ j @ + 1 + 17 <[]> y @ + @ CheckColorMatch if ( if )
drop
else ( else )
@ 4 <>=> if ( if )
j 0 <=> drop
begin j @ @ <<> while ( for )
dup x @ j @ + y @ SplitPill
bottle over 143 <[]> 139 + 1 <=> drop
bottle over 143 <[]> x @ j @ + 17 <[]> y @ + @ 16 <>=> if bottle over 143 <[]> x @ j @ + 17 <[]> y @ + @ 21 <<=> else 0 then if ( if )
bottle over 143 <[]> 136 + <--i> 2 @ 23 PrintByte
then ( endif )
bottle over 143 <[]> x @ j @ + 17 <[]> y @ + 22 <=> drop
j drop repeat ( endfor )
1 @ x @ + 8 y @ + @ 1 22 Fill
bottle over 143 <[]> 140 + 1 <=> drop
bottle over 143 <[]> 137 + 1 <=> drop
bottle over 143 <[]> 138 + drop
then ( endif )
break ( break )
then ( endif )
j drop repeat ( endfor )
then ( endif )
y drop repeat ( endfor )
x drop repeat ( endfor )
drop ; ( ret )
: QueTrash ( sender trash_count -- )
bottle 2 pick 143 <[]> 141 + over <+=> drop
drop drop ; ( ret )
: FlingTrash ( sender -- )
1 over - ! ( init )
dup if 4 else 28 then 1 ! ( init )
z 0 <=> drop
begin z @ bottle 2 pick 143 <[]> 141 + @ <<> while ( while )
x rand 8 <%> <=> drop
y 1 <=> drop
bottle @ 143 <[]> x @ 17 <[]> y @ + @ if ( if )
bottle @ 143 <[]> x @ 17 <[]> y @ + 13 rand 3 <%> + <=> drop
z drop
1 @ x @ + 8 y @ + bottle @ 143 <[]> x @ 17 <[]> y @ + @ SetTile
then ( endif )
repeat ( endwhile )
bottle over 143 <[]> 141 + 0 <=> drop
bottle @ 143 <[]> 139 + 1 <=> drop
drop ; ( ret )
: DropFilledSpace ( player x y -- )
2 pick if 28 else 4 then ! ( init )
@ 2 pick + 8 2 pick + 1 + bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick 1 + + bottle 6 pick 143 <[]> 5 pick 17 <[]> 4 pick + @ <=> SetTile
@ 2 pick + 8 2 pick + bottle 5 pick 143 <[]> 4 pick 17 <[]> 3 pick + 0 <=> SetTile
drop drop drop ; ( ret )
: DropFloaters ( player -- )
bottle over 143 <[]> 139 + 0 <=> drop
y 17 2 - <=> drop
begin y @ 0 <>> while ( for )
x 0 <=> drop
begin x @ 8 <<> while ( for )
bottle over 143 <[]> x @ 17 <[]> y @ + @ switch ( switch )
13 case ( case )
14 case ( case )
15 case ( case )
bottle 2 pick 143 <[]> x @ 17 <[]> y @ 1 + + @ if ( if )
over x @ y @ DropFilledSpace
bottle 2 pick 143 <[]> 139 + 1 <=> drop
then ( endif )
break ( break )
3 case ( case )
1 case ( case )
5 case ( case )
bottle 2 pick 143 <[]> x @ 17 <[]> y @ 1 + + @ if bottle 2 pick 143 <[]> x @ 1 + 17 <[]> y @ 1 + + @ else 0 then if ( if )
over x @ y @ DropFilledSpace
over x @ 1 + y @ DropFilledSpace
bottle 2 pick 143 <[]> 139 + 1 <=> drop
then ( endif )
break ( break )
9 case ( case )
7 case ( case )
11 case ( case )
bottle 2 pick 143 <[]> x @ 17 <[]> y @ 1 + + @ if ( if )
over x @ y @ DropFilledSpace
over x @ y @ 1 - DropFilledSpace
bottle 2 pick 143 <[]> 139 + 1 <=> drop
then ( endif )
endswitch ( endswitch )
x drop repeat ( endfor )
y drop repeat ( endfor )
bottle over 143 <[]> 139 + @ if ( if )
dup CheckMatching4
bottle over 143 <[]> 138 + @ 1 <>> if ( if )
dup bottle 2 pick 143 <[]> 138 + @ QueTrash
then ( endif )
bottle over 143 <[]> 138 + 0 <=> drop
then ( endif )
drop ; ( ret )
: InitBottle ( player -- )
dup if 28 else 4 then 1