From WiiLi
//EDmouse Wiimote Rawforces Arcade [by marsuten @gmail.com-any improvement is welcome]
//Use the wiimote on vertical, like a joystick
if starting //Variables
var.topx = 7 //Maximum velocity X <->
var.topy = 7 //Maximum velocity Y /\-\/
var.death = 0,1 //Death zone where mouse works
var.rumble = true //Wiimote rumbles when reaches the end
var.freezetime = 300 ms
pie.FrameRate = 100 hz //Leave between 60 and 100 Hz
var.trimx = 10,5 //Put the wiimote on his IO port and write the,
var.trimy = -8 //debug values here
var.invertx = false //Invert the direction on X
var.inverty = true //Invert the direction on y
endif
if true //Debug for Trims
debug = "var.trimx: " + wiimote.RawForceX*-1 + " var.trimy: " + Wiimote.RawForceY*-1
wait 300 ms
endif
//Buttons
mouse.LeftButton = wiimote.A
mouse.RightButton = wiimote.B
//Freeze
var.freeze = KeepDown(Pressed(wiimote.A or wiimote.B),var.freezetime)
// Mouse
//Starts where is the pointer
if starting then var.x = MapRange(Mouse.x, 0, 1, 1, screen.Width)
if starting then var.y = MapRange(Mouse.y, 0, 1, 1, screen.Height)
//Rawforces maprange
var.rx=(maprange( Wiimote.RawForceX + var.trimx, 28, -28, -1 , 1))
var.ry=(maprange( Wiimote.RawForcey + var.trimy, 28, -28, -1 , 1))
if var.invertx then var.rx=-1*var.rx
if var.inverty then var.ry=-1*var.ry
//Movement
var.x=var.x+smooth(var.rx*var.topx)
var.y=var.y+smooth(var.ry*var.topy)
//Movement and death zone
if var.active and not var.freeze
mouse.x=smooth((1/(screen.Width/var.x)), 1)
mouse.y=smooth((1/(screen.Height/var.y)), 1)
else
var.x = MapRange(Mouse.x, 0, 1, 1, screen.Width)
var.y = MapRange(Mouse.y, 0, 1, 1, screen.Height)
endif
var.active=not(var.rx>-var.death and var.rx<var.death and var.ry>-var.death and var.ry<var.death)
//Rumble
if var.rumble and var.active then wiimote.Rumble = KeepDown(Pressed(var.x<0 or var.y<0 or var.x>screen.Width or var.y>screen.Height),80 ms)
//Limits
if var.x>screen.Width then var.x=screen.Width
if var.y>screen.Height then var.y=screen.Height
if var.x<0 then var.x=0
if var.y<0 then var.y=0