~npisanti/scriptools

c87fcdc591fdb4fd2d7539871315f6d39721acef — Nicola Pisanti a month ago 85ce300
adds gamepad control to framescan
1 files changed, 28 insertions(+), 12 deletions(-)

M framescan/main.lua
M framescan/main.lua => framescan/main.lua +28 -12
@@ 9,6 9,13 @@ require "strict"
		e/spacebar = acquire 
--]]

da4 = { button_1=7, button_2=8, button_3=6, button_4=5,
        button_a=7, button_b=6, button_x=8, button_y=5,
		pad_up=1, pad_down=3, pad_left=4, pad_right=2,
		left_trigger=9, right_trigger=11, select=13, start=15, 
		left_axis_x=0, left_axis_y=1, right_axis_x=2, right_axis_y=3,
		left_axis_press=16, right_axis_press=17 }

local tilew = 200
local tileh = 200



@@ 56,6 63,8 @@ layer.create( "cam", camw, camh )
layer.create( "cut", tilew, tileh )
	layer.hide()

window.background( 0, 0, 0, 255 )

----------------------------------------------------
function loop()
	png.align_corner() 


@@ 141,7 150,7 @@ function loop()
		rl.pop()
	layer.close()	

	key_pressed()
	controls()
end

----------------------------------------------------


@@ 155,15 164,18 @@ function overlay( x, y, w, h )
	rl.pop()
end

function key_pressed()
function controls()

	if key.pressed( key.q ) or key.pressed( key.l ) then
	if key.pressed( key.q ) 
	or key.pressed( key.l ) 
	or pad.pressed( da4.select ) then
		lock_cam = not lock_cam
	end

	if key.pressed( key.e ) 
	or key.pressed( key.space )
	or key.pressed( key.c ) then
	or key.pressed( key.c ) 
	or pad.pressed( da4.start) then
		local filename = "output/frame_"
		if numsaved<10 then 
			filename = filename.."00"


@@ 177,13 189,13 @@ function key_pressed()
		numsaved = numsaved + 1 
	end

	if key.is_down( key.n1 ) then
	if key.is_down( key.n1 ) or pad.is_down( da4.button_1 ) then
		preview = 1
	elseif key.is_down( key.n2 ) then
	elseif key.is_down( key.n2 ) or pad.is_down( da4.button_2 ) then
		preview = 2
	elseif key.is_down( key.n3 ) then
	elseif key.is_down( key.n3 ) or pad.is_down( da4.button_3 ) then
		preview = 3
	elseif key.is_down( key.n4 ) then
	elseif key.is_down( key.n4 ) or pad.is_down( da4.button_4 ) then
		preview = 4
	else 
		preview = 0


@@ 198,13 210,17 @@ function key_pressed()
		cy = cy+faststep
	elseif key.is_down( key.w ) then
		cy = cy-faststep
	elseif key.pressed( key.left ) then
	elseif key.pressed( key.left ) or pad.pressed( da4.pad_left ) then
		cx = cx-1
	elseif key.pressed( key.right ) then
	elseif key.pressed( key.right ) or pad.pressed( da4.pad_right ) then
		cx = cx+1
	elseif key.pressed( key.up ) then
	elseif key.pressed( key.up ) or pad.pressed( da4.pad_up ) then
		cy = cy-1
	elseif key.pressed( key.down ) then
	elseif key.pressed( key.down ) or pad.pressed( da4.pad_down ) then
		cy = cy+1
	end

	cx = math.floor( cx + pad.axis( da4.left_axis_x ) * 3 )
	cy = math.floor( cy + pad.axis( da4.left_axis_y ) * 3 ) 
	
end