( Dev/Controller )

%++ { #0001 ADD2 } %-- { #0001 SUB2 }
%2/ { #0002 DIV2 }

%=>SC/ADDR { .Screen/addr IOW2 }
%->SC/COLR { .Screen/color IOW }

( devices )

|00 @System     [ &vector $2 &pad    $6 &r      $2 &g     $2 &b      $2 ]
|10 @Console    [ &pad    $8 &char   $1 &byte   $1 &short $2 &string $2 ]
|20 @Screen     [ &vector $2 &width  $2 &height $2 &pad   $2 &x      $2 &y $2 &addr $2 &color $1 ]
|40 @Controller [ &vector $2 &button $1 &key    $1 ]

( variables )

|0000

@slime $1

|0100
	
	( theme ) 
	#0daf .System/r IOW2 
	#02ff .System/g IOW2 
	#035f .System/b IOW2

	( vectors ) 
	;on-frame .Screen/vector IOW2
	
	( set origin )
	.Screen/width IOR2 2/ .Screen/x IOW2
	.Screen/height IOR2 2/ .Screen/y IOW2
	;default_icn =>SC/ADDR
	#31 ->SC/COLR
	#2a .slime POK

BRK

@on-frame

	#2a .slime POK
	;default_icn =>SC/ADDR

	( hold ctrl key to change slime color )
	.Controller/button IOR #0f AND
		DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl
		DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt
	POP

	( clear ) #30 ->SC/COLR

	( detect movement )
	.Controller/button IOR #f0 AND
		DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ 
			( move ) 
			.Screen/y IOR2 -- .Screen/y IOW2 
			;up_icn =>SC/ADDR &no-up
		DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ 
			( move ) 
			.Screen/y IOR2 ++ .Screen/y IOW2 
			;down_icn =>SC/ADDR &no-down
		DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ 
			( move ) 
			.Screen/x IOR2 -- .Screen/x IOW2 
			;left_icn =>SC/ADDR &no-left
		DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ 
			( move ) 
			.Screen/x IOR2 ++ .Screen/x IOW2 
			;right_icn =>SC/ADDR &no-right
	POP

	( draw face )
	#31 ->SC/COLR

	( draw slime )
	;slime_icn =>SC/ADDR
	.slime PEK ->SC/COLR

BRK

@default_icn [ 3c7e ffdb ffe7 7e3c ]
@up_icn      [ 2466 e7db ffff 7e3c ]
@down_icn    [ 3c7e ffff dbe7 6624 ]
@left_icn    [ 3c7e ef1f 1fef 7e3c ]
@right_icn   [ 3c7e f7f8 f8f7 7e3c ]
@slime_icn   [ 0000 183c 3c18 0000 ]