Ouya controls

Monkey Forums/Monkey Programming/Ouya controls

Sensei(Posted 2013) [#1]
Hi guys,

I've searched and found a few discussions on the Ouya controller support here in the forums, but there's too many variations and old discussions about how it's done.

Basically, I'm running Monkey v73b and have my game compiling fine on the Ouya. The only problem is I am unable to control it due to lack of controller support. I don't care about multiple controllers at this point, I just want the first one to work!

So, saying that, what's the easiest solution to get Ouya controller support into my game?

As an additional related question: If I needed to or wanted to run/test a newer version of Monkey and be able to use the same working Targets, do I just copy the Targets folder over to the newer Monkey version or is it unneccessary? The reason for my question, is because I am aware that Mark included official Ouya support in one of the newer versions of Monkey, so I wonder if I just try running that instead.

I'm still very new with Monkey, so please excuse the idiotic questions.


AdamRedwoods(Posted 2013) [#2]
looks like the Ouya target has gamepad turned off, which probably shouldn't be:
#ANDROID_GAMEPAD_ENABLED=False

turn that to true, or add it to the top of your file.

THen use JoyX(0) and JoyY(0) to get the directional float numbers.

If I needed to or wanted to run/test a newer version of Monkey and be able to use the same working Targets, do I just copy the Targets folder over to the newer Monkey version or is it unneccessary?

i don't think so. sometimes new versions have fixes in the target files. the file to copy is usually the bin/config.txt files.

did you make modifications to the target files? if so, it's better to make a copy of the target folder, and name it to something else, then make modifications. the newer versions will automatically pick up the new folder.


computercoder(Posted 2013) [#3]
@Sensei:

If you want to use the OFFICIAL Ouya Target, get Monkey v75d. It has FULL support for OUYA in it, including IAP and multiple controllers - PLUS it has mappings now to include the left and right stick buttons and proper functioning of the MENU button. It is VERY easy to use.

Mark's version of OUYA works just like the Android target.

Here is some code to get you using all four of the OUYA controllers, plus the mappings I made to make it easier to get at the OUYA controls using Mark's commands.

#ANDROID_GAMEPAD_ENABLED=True

Import mojo

Class MyApp Extends App

	Method OnCreate()
		SetUpdateRate 15
	End
	
	Method OnUpdate()
	End
	
	Method OnRender()
		Scale DeviceWidth/800.0,DeviceHeight/460.0
		Cls
		For Local port:=0 Until 4
			PushMatrix
			Translate port*200,0
			DrawText "Port             " + port,0,0
			DrawText "LeftStickX       " + OuyaController.LeftStickX( port ),0,20
			DrawText "LeftStickY       " + OuyaController.LeftStickY( port ),0,40
			DrawText "LeftTrigger      " + OuyaController.LeftTrigger( port ),0,60
			DrawText "RightStickX      " + OuyaController.RightStickX( port ),0,80
			DrawText "RightStickY      " + OuyaController.RightStickY( port ),0,100
			DrawText "RightTrigger     " + OuyaController.RightTrigger( port ),0,120
			DrawText "O                " + OuyaController.O( port ),0,140
			DrawText "U                " + OuyaController.U( port ),0,160
			DrawText "Y                " + OuyaController.Y( port ),0,180
			DrawText "A                " + OuyaController.A( port ),0,200
			DrawText "LeftBumper       " + OuyaController.LeftBumper( port ),0,220
			DrawText "RightBumper      " + OuyaController.RightBumper( port),0,240
			DrawText "DPadUp           " + OuyaController.DPadUp( port ),0,260
			DrawText "DPadDown         " + OuyaController.DPadDown( port ),0,280
			DrawText "DPadLeft         " + OuyaController.DPadLeft( port ),0,300
			DrawText "DPadRight        " + OuyaController.DPadRight( port ),0,320
			DrawText "LeftStickButton  " + OuyaController.LeftStickButton( port ),0,340
			DrawText "RightStickButton " + OuyaController.RightStickButton( port ),0,360
			DrawText "MenuButton       " + OuyaController.MenuButton( port ),0,380
			DrawText "TouchpadButton   " + OuyaController.TouchpadButton(),0,400
			DrawText "TouchpadX        " + OuyaController.TouchpadX(),0,420
			DrawText "TouchpadY        " + OuyaController.TouchpadY(),0,440		
			PopMatrix
		Next
	End

End

Function Main()

	New MyApp
	
End


Class OuyaController
	Const OUYA_O:Int = JOY_A
	Const OUYA_U:Int = JOY_X
	Const OUYA_Y:Int = JOY_Y
	Const OUYA_A:Int = JOY_B
	
	Const OUYA_LB:Int = JOY_LB
	Const OUYA_RB:Int = JOY_RB
	Const OUYA_LSB:Int = JOY_LSB
	Const OUYA_RSB:Int = JOY_RSB
	
	Const OUYA_MENU:Int = JOY_MENU
	
	Const OUYA_DPAD_UP:Int = JOY_UP
	Const OUYA_DPAD_DOWN:Int = JOY_DOWN
	Const OUYA_DPAD_LEFT:Int = JOY_LEFT
	Const OUYA_DPAD_RIGHT:Int = JOY_RIGHT

	Function O:Int(port:Int=0)
		Return JoyDown(OUYA_O,port)
	End Function

	Function U:Int(port:Int=0)
		Return JoyDown(OUYA_U,port)
	End Function

	Function Y:Int(port:Int=0)
		Return JoyDown(OUYA_Y,port)
	End Function

	Function A:Int(port:Int=0)
		Return JoyDown(OUYA_A,port)
	End Function

	Function LeftBumper:Int(port:Int=0)
		Return JoyDown(OUYA_LB,port)
	End Function

	Function RightBumper:Int(port:Int=0)
		Return JoyDown(OUYA_RB,port)
	End Function

	Function DPadUp:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_UP,port)
	End Function

	Function DPadDown:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_DOWN,port)
	End Function

	Function DPadLeft:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_LEFT,port)
	End Function

	Function DPadRight:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_RIGHT,port)
	End Function

	Function LeftTrigger:Float(port:Int=0)
		Return JoyZ(0,port)
	End Function
		 
	Function LeftStickX:Float(port:Int=0)
		Local x:Float = JoyX(0,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function LeftStickY:Float(port:Int=0)
		Local y:Float = JoyY(0,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
		 
	Function LeftStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_LSB,port)
	End Function
	
	Function RightTrigger:Float(port:Int=0)
		Return JoyZ(1,port)
	End Function
		 
	Function RightStickX:Float(port:Int=0)
		Local x:Float = JoyX(1,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function RightStickY:Float(port:Int=0)
		Local y:Float = JoyY(1,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
	
	Function RightStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_RSB,port)
	End Function
	
	Function MenuButton:Int(port:Int=0)
		Return JoyDown(OUYA_MENU,port)
	End Function
	
	Function TouchpadButton:Int()
		Return TouchDown(0)
	End Function
	
	Function TouchpadX:Float()
		Return TouchX(0)
	End Function
	
	Function TouchpadY:Float()
		Return TouchY(0)
	End Function
	
End 


[EDIT] Forgot the Scale and Push/PopMatrix commands to format it right :P

[EDIT #2] Updated the scale and translate to correctly show all of the contents


Sensei(Posted 2013) [#4]
Wow! Thanks a ton guys! This is exactly what I was looking for. Good clear up-to-date info on Ouya controller use :-)

I'll test this later tonight!


Sensei(Posted 2013) [#5]
Well, I tested this out on Monkey73b.
Firstly, the LSB, RSB and Menu buttons throw errors, so had to comment them out.

Secondly I ran this both in HTML5, where you can see the mouse reacting and displaying a port, button and x/y positions:
www.dropbox.com/s/ozhetrs6l63xpjd/IMAG0571.jpg

On the ouya, I just get this:
www.dropbox.com/s/bwcgubbcrrod341/IMAG0572.jpg

(Sorry, not sure how to directly link images in this forum!)
So from what I can tell, it's not finding the controller.
I did make sure to have #ANDROID_GAMEPAD_ENABLED=True at the top of the page (above Import mojo)

The reason I haven't tested this in Monkey75d is simply because the ouya target doesn't appear in the drop-down list in Ted or Mollusk. I'm guessing something needs to be set/configured, so I'll dig around to see why it's not coming up as a compiler option.

Other than the above, anyone else tried this and got it working?

PS. If I were to save out the Ouya controller class into a separate file for future usage in other apps, do I just save it as ie. ouya_controller.monkey and at the top of my main code page do:
import mojo
import ouya_controller


Edit:
Just discovered an examples folder on the Ouya target I built from the Git version.
It works with that!
Obv the top left and right paddles don't respond, and neither do A, Y and U, but O does, so it's a start. :)


computercoder(Posted 2013) [#6]
The reason it is not showing up in the newer version of Monkey 75d is because the new version isn't setup to see where your android sdk is located at.

There is a little information in Monkey's HELP for the Android Target for how/what to setup.

You can just copy and paste the following section from your config.winnt.txt, or config.macos.txt or config.linux.tx files in Monkey v73b to v75d. Don't copy from this post, as these are the defaults Monkey has for each of the config files.

If you are using Mac OS X:
'--------------------
'Android SDK and tool paths.
'
'Must be set to a valid for for ANDROID target support
'
'Android SDK
ANDROID_PATH="${HOME}/android-sdk-macosx"
'--------------------


If you are using Windows:
'--------------------
'Ant build tool path
'
'Must be set to a valid dir for ANDROID target support
'
'Ant is currently available here: 
'	http://ant.apache.org/bindownload.cgi
'
ANT_PATH="${SYSTEMDRIVE}\monkey_sdks\apache-ant-1.8.4"
ANT_PATH="${SYSTEMDRIVE}\apache-ant-1.8.4"
ANT_PATH="${SYSTEMDRIVE}\apache-ant-1.8.2"
ANT_PATH="${SYSTEMDRIVE}\ant"
'--------------------


If you are using Linux:
'--------------------
'Android SDK and tool paths.
'
'Must be set to a valid for for ANDROID target support.
'
ANDROID_PATH="${HOME}/android-sdk-linux"
'--------------------

Once you have the proper path set, Ted and Mollusk with find both "Android Game" and "Android (Ouya) Game" targets.

Try using the code I supplied above with 75d and the "Android (Ouya) Game" target.

Hope this helps! :)


Sensei(Posted 2013) [#7]
Sweet thanks a lot! I'll try this tonight.

Sometimes I do wish these type of things were better documented and clearer. It's things like these that'll stop more people from adopting Monkey, IMHO.


computercoder(Posted 2013) [#8]
You're welcome :)

I agree. The documents seemingly are constantly in need of updating. Guess it helps that these forums can provide the parts that are missing. :)

Also, you *may* be able to just simply copy and paste the config files from v73b to v75d. They are located in the "bin" folder. I'd suggest backing up v75d's config files first (in case you need to go back) then copy over the ones from v73b and have a go with that. The problem is that I am unsure of what changes have been made to the files, and what else will be disturbed in doing so. Best bet is to just copy the android related parts over individually.


computercoder(Posted 2013) [#9]
I just noticed the links to the pics you provided! Sorry about not noticing them earlier, but I think I need to make a correction to the scale. I'll update my code. I'm not with my OUYA at the moment, so my appologies for not having it right. I whipped up the controller class example on the fly, but used my actual controller class that works.

o O
-

It may be a few hours before I can make sure it work properly when I return home. I'll try it out here with HTML5 to see if I can get the scale right there as well.

[EDIT] I updated the post above to reflect the changes. I tested it on HTML5 and now all values show correctly on-screen. Something else worth noting: The "Touchpad" on the OUYA for all controllers control the SAME mouse. So every controller moves the mouse around. I don't see a way to separate which controller does what with each mouse independently in the OUYA ODK either. I'd love to determine which controller did what with the mouse, and allow a primary controller to utilize the on-screen mouse. Perhaps eventually OUYA will make this change? Either that, or I missed something there and it does separate them?


Sensei(Posted 2013) [#10]
You're a bit of a legend, aren't you just?
Might have to buy you a beer sometime :-)


computercoder(Posted 2013) [#11]

You're a bit of a legend, aren't you just?


I just enjoy what I do. If I can help and I know how to do what you need done, I'll provide what I can :)


Might have to buy you a beer sometime :-)


Since I don't drink, I'll catch up with a good Ice Cold Coke :) You can have the beer mate. Cheers!


Sensei(Posted 2013) [#12]
Well matey, many thanks for your help so far. I updated my windows config.winnt.txt file. The only difference was the Ant path, which I duplicated from my 73b config. Still not seeing Ouya option in 75d. I'll dig around some more to see what I might be missing.
I'm guessing there's no recompiling of transcc involved I hope!


computercoder(Posted 2013) [#13]
Hmmm. Do you see Android? I'll recheck my settings here (I'm on a Mac, so I will be of limited help on Windows)

You will not need to recompile the Transcc for the Official OUYA Target.

It should just work if you have the same settings as 73b has.

I'll investigate on my end and post back. :)


computercoder(Posted 2013) [#14]
Ok, what I see in the config.winnt.txt file is this for v75d:


'--------------------
'Java dev kit path
'
'Must be set to a valid dir for ANDROID and FLASH target support
'
'Make sure to install the 32 bit JDK, even on 64 bit Windows!
'
'The Java JDK is currently available here:
'	http://www.oracle.com/technetwork/java/javase/downloads/index.html
'
JDK_PATH="${PROGRAMFILES}\Java\jdk1.7.0_17"
JDK_PATH="${PROGRAMFILES}\Java\jdk1.7.0_02"
JDK_PATH="${PROGRAMFILES}\Java\jdk1.6.0_23"
JDK_PATH="${PROGRAMFILES}\Java\jdk1.6.0_21"
JDK_PATH="${PROGRAMFILES}\Java\jdk1.6.0_19"
'--------------------

'--------------------
'Android SDK and tool paths.
'
'Must be set to a valid dir for ANDROID target support
'
ANDROID_PATH="${SYSTEMDRIVE}\monkey_sdks\android-sdk-windows"
ANDROID_PATH="${SYSTEMDRIVE}\android-sdk-windows"
'--------------------

'--------------------
'Android NDK
'
'Must be set to a valid dir for ANDROID NDK target support
'
ANDROID_NDK_PATH="${SYSTEMDRIVE}\android-ndk-r9"
'--------------------


All I can think of here is that the path you used for ANDROID_PATH, JDK_PATH, or ANDROID_NDK is off.

Have you tried simply copying the file from 73b to 75d? Its strange that 73b works, but 75d does not.


Sensei(Posted 2013) [#15]
I've not copied it across yet but I did check to make sure android, jdk etc are the same, which they are. I don't see android on the drop-down list in 75d either, funnily enough.
I'll investigate more this evening.


Sensei(Posted 2013) [#16]
Hi @computercoder
So.. turns out all the targets work on Monkey 75d today. It didn't last night. Then it hit me. The paths needed updating which was resolved after effectively rebooting the pc.
Since I also took the liberty of installing 32bit MinGW, I can now compile C++ tool target too. \o/
And ofcourse, I can now see Android and Android_Ouya targets :)
Now I'll put together something small to see what type of key controls trigger on this version of Monkey for Ouya then, out of the box..


computercoder(Posted 2013) [#17]
Sweet! Amazing what a reboot will do :)


Sensei(Posted 2013) [#18]
Hehe yeah. Only problem now is, with the "stock" Ouya code for 75d, I'm getting zero control.
I have #ANDROID_GAMEPAD_ENABLED=True above Strict and Import mojo.
I also have tried the following of which none seem to be working:
 #If TARGET="Android (Ouya) Game"
        DrawText("Android (Ouya) Game!", 10, 10)
        #End
        #If TARGET="android_ouya"
        DrawText("android_ouya!", 10, 30)
        #End
        #If TARGET="ouya"
        DrawText("ouya!", 10, 50)
        #End
        #IF TARGET="ouya"
        DrawText("ouya ++!", 10, 50)
        #END


I'm confused as to what exactly I'm targetting. The folder is called android_ouya, the target name in the drop-down in monkey is "Android (Ouya) Game" and the TARGET.Monkey file has:

#TARGET_NAME="Android (Ouya) Game"
#TARGET_SYSTEM="android"
#TARGET_BUILDER="android"

As I said, none of these display on the Ouya screen (it's all under the OnRender method, which displays when I test on html5 build- by which I mean the "standard" Ouya KeyDown names like Key_O triggers, etc.)

So, until I have 100% certainty on targetting the Ouya, I am unable to get controls working.

PS. Your example code above, only has the touchX, touchY and touchButton responding.. (I thought I'd try it as a last resort)

PPS. Off to bed now but going to give your code from here a try tomorrow:
http://www.monkeycoder.co.nz/Community/post.php?topic=4760&post=65451


computercoder(Posted 2013) [#19]
You only get #If TARGET=android because its the Android platform that OUYA is based on. There is not another preprocessor directive you can use to distinguish this.

HOWEVER, AdamRedwoods pointed out that you CAN add #OUYA=True to the CONFIG.MONKEY file for the OUYA target. Also, while you are in there, add the #ANDROID_GAMEPAD_ENABLED=True along with it. You will no longer have to remember to add it for each app you make. Then you simply can do the following:

	#If OUYA	        
		DrawText("OUYA is True",0,0) 
	#Else
		DrawText("OUYA is False",0,0)
	#End


I'll take a few minutes after dinner (yeah we eat late) and set down on the the OUYA and my Mac to sort this out :)


computercoder(Posted 2013) [#20]
I played around with the code I posted with the OUYA and everything works for all four controllers. I did the following:

1) copied and pasted the code from here into TED
2) saved it
3) selected the "Android (Ouya) Game" target
4) hit the build and run button

I tried both Release and Debug with both working identically.

I just updated tonight to Build Number 1.0.561_r1 on the OUYA.

Re-reading what you posted, make sure you use my controller mappings with the "Android (Ouya) Game" target in v75d. The Community Edition (from GitHub) will not map correctly as that one uses KeyDown(), not JoyDown(). And ALL of those mappings will not map correctly into the JoyDown mappings.


Sensei(Posted 2013) [#21]
Thanks once again mate! It's becoming clearer now how this all works, hoho.
Pretty sure I'll have it cracked tonight.
I like the idea of Adam's #If OUYA code. Will this be useful to distinguish between regular Android and Ouya I wonder?
Something like:

#If TARGET="android"
   #If OUYA
      ' Do this
   #Else
      ' Do something else
   #End
#End


I'm guessing by your mappings, you mean the code in this thread higher up?
I tried that and it didn't work. However, I wonder why, as I tried both your mappings and the "standard" mappings as I said, of which neither worked.
I'll do a clean simple program test again tonight and once I have it sorted, I'll integrate it into my game.


computercoder(Posted 2013) [#22]

I like the idea of Adam's #If OUYA code. Will this be useful to distinguish between regular Android and Ouya I wonder?
Something like:

#If TARGET="android"
   #If OUYA
      ' Do this
   #Else
      ' Do something else
   #End
#End




Almost. You can't nest the directive tags that way. You would need to do something like this:
' This will actually be in the CONFIG.MONKEY for the android_ouya target
' For demonstration purposes I added it here
#OUYA=True

Import mojo

Class MyApp Extends App

	Method OnCreate()
		SetUpdateRate 15
	End
	
	Method OnUpdate()
	End
	
	Method OnRender()
		Scale DeviceWidth/400.0,DeviceHeight/440.0
		Cls
		#If OUYA
			DrawText "OUYA is True",20,20
		#Elseif TARGET="android"
			DrawText "Android is True",20,20
		#Else
			DrawText "Default is met",20,20
		#End
	End

End

Function Main()

	New MyApp
	
End


You need to check for the special directive first, because otherwise the main ones will be met and the OUYA directive will never be checked.


I'm guessing by your mappings, you mean the code in this thread higher up?


Yes! Just copy and paste that code into a fresh file. save it and compile it against "Android (Ouya) Game". It should work right out of the box. I'm not sure if having the controllers on first makes any difference. Try turning them on before you launch it.


Sensei(Posted 2013) [#23]
Cool, thanks a mil!
I'll give this a bash tonight. This direction is looking very promising :)

My mate's been harping on about me wasting time with these target issues instead of more coding time on the game, but IMO, if I deal with these problems now, it means I won't need to come back into the game code later and hack it to bits to get the targets and functionality working as they should, so I'm sticking by my guns..


ElectricBoogaloo(Posted 2013) [#24]
It's good to get your targets all sorted before you start..
.. trust me on this..
Having written 28 games over the past 10 months, I now have to go right back to the beginning again, and "fix" the whole bunch of them to get them working right on OUYA.
GAH!
Coding is fun, Monkey makes it a whole lot easier, but as soon as you try to add something new into the mix, it all goes to pot!


computercoder(Posted 2013) [#25]
Agreed. What I think everyone will eventually learn is how to make the changes as minimal as possible through really good coding practices and software design. Even with all that, you'll always need to make tweeks.

[EDIT] When you make the changes to CONFIG.MONKEY, delete the project's BUILD folder first, and then have a go. This way the CONFIG.MONKEY gets processed and the #OUYA directive will(should) work.


Sensei(Posted 2013) [#26]
Superb matey. I tested the example again tonight and the Ouya controls all work, even the menu button.
Weird thing is when I try import the Ouya class in a seperate file, it errors out on compile with "Unable to find JOY_LEFT", but works perfectly fine when the class is directly in the main source code!?
Maybe I need to instantiate it first, like:
Field ouyaControl := new OuyaController()


I added the #Ouya = TRUE in the config.monkey as you suggested, along with enabling the controller.
I made a new folder, copied the test.monkey file and did a build and it still reports as Android, not Ouya in:
#If TARGET="android"
   #If OUYA
      ' Do this
   #Else
      ' Do something else
   #End
#End



computercoder(Posted 2013) [#27]
You don't need to do all that for the OuyaController Class. Just add the following line to the very top of the file:
Import mojo.input

Class OuyaController
.
.
.
End

Once you have that, it'll work just fine.

As far as the #OUYA directive. I was not able to get it to work like it was suggested to me. I merely tried using it with my OUYA in the CONFIG.MONKEY and it doesn't know anything about it... BUT I am able to get it working on the main game file.

In fact, here's a nice example using #OUYA.

I called this "ouyatest.monkey"
#OUYA=True

Import mojo
Import ouyatestrender

Class MyApp Extends App

	Method OnCreate()
		SetUpdateRate 15
	End
	
	Method OnUpdate()
	End
	
	Method OnRender()
		Draw.Render()
	End

End

Function Main()

	New MyApp
	
End


I called this one "ouyatestrender.monkey"
Import mojo
Import ouyacontroller

Class Draw

	Function Render()
	
		Scale DeviceWidth/800.0,DeviceHeight/460.0
		Cls
		For Local port:=0 Until 4
			PushMatrix
			Translate port*200,0
			
			DrawText "Port             " + port,0,0
			DrawText "LeftStickX       " + OuyaController.LeftStickX( port ),0,20
			DrawText "LeftStickY       " + OuyaController.LeftStickY( port ),0,40
			DrawText "LeftTrigger      " + OuyaController.LeftTrigger( port ),0,60
			DrawText "RightStickX      " + OuyaController.RightStickX( port ),0,80
			DrawText "RightStickY      " + OuyaController.RightStickY( port ),0,100
			DrawText "RightTrigger     " + OuyaController.RightTrigger( port ),0,120
			DrawText "O                " + OuyaController.O( port ),0,140
			DrawText "U                " + OuyaController.U( port ),0,160
			DrawText "Y                " + OuyaController.Y( port ),0,180
			DrawText "A                " + OuyaController.A( port ),0,200
			DrawText "LeftBumper       " + OuyaController.LeftBumper( port ),0,220
			DrawText "RightBumper      " + OuyaController.RightBumper( port),0,240
			DrawText "DPadUp           " + OuyaController.DPadUp( port ),0,260
			DrawText "DPadDown         " + OuyaController.DPadDown( port ),0,280
			DrawText "DPadLeft         " + OuyaController.DPadLeft( port ),0,300
			DrawText "DPadRight        " + OuyaController.DPadRight( port ),0,320
			DrawText "LeftStickButton  " + OuyaController.LeftStickButton( port ),0,340
			DrawText "RightStickButton " + OuyaController.RightStickButton( port ),0,360
			DrawText "MenuButton       " + OuyaController.MenuButton( port ),0,380
			DrawText "TouchpadButton   " + OuyaController.TouchpadButton(),0,400
			DrawText "TouchpadX        " + OuyaController.TouchpadX(),0,420
			DrawText "TouchpadY        " + OuyaController.TouchpadY(),0,440		

			#If OUYA 
				DrawText ":)", 30,0
			#Else 
				DrawText ":(", 30,0
			#End
			 
			PopMatrix
		Next
	
	End
	
End


And finally, I called this one "ouyacontroller.monkey"
Import mojo.input

Class OuyaController
	Const OUYA_O:Int = JOY_A
	Const OUYA_U:Int = JOY_X
	Const OUYA_Y:Int = JOY_Y
	Const OUYA_A:Int = JOY_B
	
	Const OUYA_LB:Int = JOY_LB
	Const OUYA_RB:Int = JOY_RB
	Const OUYA_LSB:Int = JOY_LSB
	Const OUYA_RSB:Int = JOY_RSB
	
	Const OUYA_MENU:Int = JOY_MENU
	
	Const OUYA_DPAD_UP:Int = JOY_UP
	Const OUYA_DPAD_DOWN:Int = JOY_DOWN
	Const OUYA_DPAD_LEFT:Int = JOY_LEFT
	Const OUYA_DPAD_RIGHT:Int = JOY_RIGHT

	Function O:Int(port:Int=0)
		Return JoyDown(OUYA_O,port)
	End Function

	Function U:Int(port:Int=0)
		Return JoyDown(OUYA_U,port)
	End Function

	Function Y:Int(port:Int=0)
		Return JoyDown(OUYA_Y,port)
	End Function

	Function A:Int(port:Int=0)
		Return JoyDown(OUYA_A,port)
	End Function

	Function LeftBumper:Int(port:Int=0)
		Return JoyDown(OUYA_LB,port)
	End Function

	Function RightBumper:Int(port:Int=0)
		Return JoyDown(OUYA_RB,port)
	End Function

	Function DPadUp:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_UP,port)
	End Function

	Function DPadDown:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_DOWN,port)
	End Function

	Function DPadLeft:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_LEFT,port)
	End Function

	Function DPadRight:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_RIGHT,port)
	End Function

	Function LeftTrigger:Float(port:Int=0)
		Return JoyZ(0,port)
	End Function
		 
	Function LeftStickX:Float(port:Int=0)
		Local x:Float = JoyX(0,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function LeftStickY:Float(port:Int=0)
		Local y:Float = JoyY(0,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
		 
	Function LeftStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_LSB,port)
	End Function
	
	Function RightTrigger:Float(port:Int=0)
		Return JoyZ(1,port)
	End Function
		 
	Function RightStickX:Float(port:Int=0)
		Local x:Float = JoyX(1,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function RightStickY:Float(port:Int=0)
		Local y:Float = JoyY(1,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
	
	Function RightStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_RSB,port)
	End Function
	
	Function MenuButton:Int(port:Int=0)
		Return JoyDown(OUYA_MENU,port)
	End Function
	
	Function TouchpadButton:Int()
		Return TouchDown(0)
	End Function
	
	Function TouchpadX:Float()
		Return TouchX(0)
	End Function
	
	Function TouchpadY:Float()
		Return TouchY(0)
	End Function
	
End 


So the idea here was to see if #OUYA=True is visible on Imported code files, plus to show you how to include the OuyaController class :)

Save each file as I labeled them so they will work properly, or change the Import names to what you want to call them. Compile and run them against the Android (Ouya) Game target on v75d.

When it executes, you should see :) just to the right of each Port number.


Sensei(Posted 2013) [#28]
Ahhhh. Now I'm starting to understand how functions are used in classes and I wasn't including Mojo.input at the top of the imported file. Makes so much sense now.

Thanks once again computercoder.


Sensei(Posted 2013) [#29]
Happy to report my game is working with the Ouya controller!
Super happy, thanks computercoder!

Only thing that I'm still confused with is the #OUYA=True aspect. Since my game will be multi-platform, how will I be able to distinguish between my regular Android specific touch and other related things and the Ouya?
When I add #OUYA=True to the config.monkey in the target/template folder, the code doesn't appear to pick it up:
#ADMOB_PUBLISHER_ID="abcdabcdabcdabc"							'from your admod account
#ADMOB_ANDROID_TEST_DEVICE1="TEST_EMULATOR"
#ADMOB_ANDROID_TEST_DEVICE2="ABCDABCDABCDABCDABCDABCDABCDABCD"	'your device's admob ID for test mode
#ADMOB_ANDROID_TEST_DEVICE3=""
#ADMOB_ANDROID_TEST_DEVICE4=""

#MOJO_HICOLOR_TEXTURES=True
#MOJO_IMAGE_FILTERING_ENABLED=True

#ANDROID_APP_LABEL="SpaceWhale"
#ANDROID_APP_PACKAGE="com.monkeycoder.monkeygame"
#ANDROID_SCREEN_ORIENTATION="landscape"					'"user", "portrait", "landscape"
#ANDROID_GAMEPAD_ENABLED=False
#ANDROID_VERSION_CODE="1"
#ANDROID_VERSION_NAME="1.0"

#ANDROID_KEY_STORE="../../release-key.keystore"
#ANDROID_KEY_ALIAS="release-key-alias"
#ANDROID_KEY_STORE_PASSWORD="password"
#ANDROID_KEY_ALIAS_PASSWORD="password"
#ANDROID_SIGN_APP=False

#OPENGL_GLES20_ENABLED=False

#ANDROID_NATIVE_GL_ENABLED=False

#ANDROID_OUYA_DEVELOPER_UUID="xxxxxxxx-yyyy-zzzz-yyyy-xxxxxxxxxxxx"	'from the main developer portal page

#TEXT_FILES="*.txt|*.xml|*.json"
#IMAGE_FILES="*.png|*.jpg|*.gif|*.bmp"
#SOUND_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#MUSIC_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#BINARY_FILES="*.bin|*.dat"

#OUYA=True
#ANDROID_GAMEPAD_ENABLED=True


It does pick it up when in the main source file, obviously, but then it leaves me back to my question.


ElectricBoogaloo(Posted 2013) [#30]
Indeed. Alarming amount of misinformation, there! Guys, if you're going to suggest something, TEST IT FIRST!!!!

And, for absolute testing, there's nothing better than failure. If you can reproduce a failure, then it means your little bit of code is indeed doing something. If your code "happily compiles with my new code" then it's no guarantee it's doing anything at all, since Monkey (without Strict mode enabled) will quite happily compile any old garbage!! Heck, it compiles MY code!! Failure should be your first test.


Sensei(Posted 2013) [#31]
Yeah I get many failures at this point in time. God, it's amazing how little you know at the start and how many points of failure there are. It's great fun though!
Looking at the included examples, I'm learning a lot more. Especially how to go about seperating code, classes, functions, how to use them in Monkey, etc. Very cool stuff.
For now, I'll leave these Ouya specific niggles (just this one #Ouya thing anyway) as it's not important now.

Very happy with all the help I've received here so far. @computercoder: I owe you a couple of cokes :)


computercoder(Posted 2013) [#32]
I agree misinformation does some terrible things. I wish I tried the #OUYA thing prior to "thinking" it'd work since it DID work when I added it to my main app file, but not the CONFIG.MONKEY file. My bad, and my apologies there.

As for the rest of any of the code I supplied here, it was tested and was working prior to posting it. Nothing is worse than giving help and providing bad or non-working examples!

@Sensei: in any of your games that you also wish to make them for OUYA as well, just set the #OUYA=True to #OUYA=False, comment it out, or remove it entirely. I'd suggest just setting it to False.

As for the CONFIG.MONKEY file, See my comments below:
#ADMOB_PUBLISHER_ID="abcdabcdabcdabc"							'from your admod account
#ADMOB_ANDROID_TEST_DEVICE1="TEST_EMULATOR"
#ADMOB_ANDROID_TEST_DEVICE2="ABCDABCDABCDABCDABCDABCDABCDABCD"	'your device's admob ID for test mode
#ADMOB_ANDROID_TEST_DEVICE3=""
#ADMOB_ANDROID_TEST_DEVICE4=""

#MOJO_HICOLOR_TEXTURES=True
#MOJO_IMAGE_FILTERING_ENABLED=True

#ANDROID_APP_LABEL="SpaceWhale"
#ANDROID_APP_PACKAGE="com.monkeycoder.monkeygame"
#ANDROID_SCREEN_ORIENTATION="landscape"					'"user", "portrait", "landscape"
#ANDROID_GAMEPAD_ENABLED=False             <------------ Here is the Android gamepad, just set it to True
#ANDROID_VERSION_CODE="1"
#ANDROID_VERSION_NAME="1.0"

#ANDROID_KEY_STORE="../../release-key.keystore"
#ANDROID_KEY_ALIAS="release-key-alias"
#ANDROID_KEY_STORE_PASSWORD="password"
#ANDROID_KEY_ALIAS_PASSWORD="password"
#ANDROID_SIGN_APP=False

#OPENGL_GLES20_ENABLED=False

#ANDROID_NATIVE_GL_ENABLED=False

#ANDROID_OUYA_DEVELOPER_UUID="xxxxxxxx-yyyy-zzzz-yyyy-xxxxxxxxxxxx"	'from the main developer portal page

#TEXT_FILES="*.txt|*.xml|*.json"
#IMAGE_FILES="*.png|*.jpg|*.gif|*.bmp"
#SOUND_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#MUSIC_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#BINARY_FILES="*.bin|*.dat"

--- REMOVE THESE BELOW HERE ---
#OUYA=True
#ANDROID_GAMEPAD_ENABLED=True


With classes, in Monkey, Functions are static - you can access them without creating an object for it first. Methods are not static and require you to create an object before accessing them.

It gets easier with time :)

I'm glad I could help you. Congrats on getting your game working WITH OUYA! :)


Sensei(Posted 2013) [#33]
I think I'm probably not being clear and apologise for that.
I was hoping I could do Ouya specific logic in the same game so I could have something like:

#If TARGET="android"
  doAndroidControls()
    #If OUYA
      doOuyaControls()
    #EndIf
#ElseIf TARGET="html5"
  doKeyboardControls
#Else
  doJoystickControls()
#End


At the end of the day, they all change the same variables so it keeps the control logic elsewhere in the game short and consistent.


computercoder(Posted 2013) [#34]
You can:
#If OUYA
  doOuyaControls()
#ElseIf TARGET="android"
  doAndroidControls()
#ElseIf TARGET="html5"
  doKeyboardControls
#Else
  doJoystickControls()
#End


The ONLY thing is that on your main game file at the top, you need to include #OUYA=True (for OUYA compiled) or #OUYA=False (For anything else)

You will easily be able to detect the OUYA being your target this way. Its not as nice as if it were able to be added into CONFIG.MONKEY where you would not need to change the value of it.


Sensei(Posted 2013) [#35]
Aaaah. Now I get it. I'll just need to remember to change between false and true when I compile for testing on the various devices.
Good call. I'll not bother you anymore now, hehe.