Skip to content

error454/ShiVa-OUYA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ShiVa OUYA

An eclipse project for the ShiVa game engine that integrates the OUYA SDK.

Note on original code

This code is based on a project generated by the Stonetrip Unified Authoring Tool version 1.4.0.beta8. That exported project was taken and hacked a bit to create this.

What has changed from the default export

  • Remove Accelerometer
  • Remove vibrator
  • Remove GPS
  • Remove camera
  • Remove splash view
  • Remove wake lock
  • Remove lock screen handling
  • Set screen mode to default to fullscreen landscape
  • Add key handlers and motion event handlers for ouya joystick 1-4
  • Add stubs for Ouya purchasing
  • Only build for arm-v7a
  • Only compile for arm instruction set (not thumb)

How to get started

1. Acquire the Source

The first step is to get the source files, you can do this by forking or cloning the repository with a git client or you can download the repository as a zip above.

2. Rename the Project

The 2nd step is to rename the project. To do so I have provided a script that you need to modify, android/configure.sh which handles renaming all of the source files and build scripts for you. Note that if you're on a Mac, you should probably just expect this to fail since I'm building on windows with cygwin. Contact me, we can probably figure out the necessary changes to the build script.

3. Add the obj/ folder from your copy of the UAT

The obj/* folder is not included in this repository. This missing folder contains the S3DClient libs. To get these necessary libs, you should export a project from UAT 1.4.0 beta8 and copy the obj folder into the android/ folder. Until you do this, you won't be able to compile ;)

4. Import Into Eclipse

You can now import the project into eclipse, copy your STK file to assets/S3DMain.smf, build and deploy.

Project Organization

  • /android contains the eclipse project
  • /shiva contains all of the scripts you need to get OUYA controller input from inside of ShiVa

Controller Input in ShiVa

Joystick events are sent to OuyaController through 3 handlers:

  • onOuyaKeyEvent receives button events
  • onOuyaJoystick receives analog joystick events
  • onOuyaTouchpad receives touchpad events

You have 2 choices for handling input in ShiVa. But for either choice to work, you must import the OuyaController and add it your game as a User AI. Once you've done this you can choose between:

  1. You can delete the default implementations found in onOuyaKeyEvent and onOuyaMotionEvent and handle events right there. Note there are no constants defined for the OUYA controllers inside of ShiVa, so refer to the existing implementations for key value hints.
  2. You can use anytime-state-querying to grab controller info from other AIs. This implementation is described in detail. If you use this method, you will need to copy the 4 helper functions GameAI_Function_getOuya*.lua to whatever AIs you intend on querying key input from.

Example of anytime-state-querying:

local leftAX, leftAY, rightAX, rightAY, L1, L2, L3, R1, R2, R3, bA, bB, bX, bY, bSystem, dLeft, dRight, dUp, dDown, touchX, touchY

--The first input to these "0" is the player number

-- Analog joysticks are all -1 to 1, you may want to round anything <= .18 to 0 due to dead zone
leftAX = this.getOuyaAxis ( 0, "AXIS_LS_X" ) 
leftAY = this.getOuyaAxis ( 0, "AXIS_LS_Y" )
rightAX = this.getOuyaAxis ( 0, "AXIS_RS_X" )
rightAY = this.getOuyaAxis ( 0, "AXIS_RS_Y" )

--Bumpers
L1 = this.getOuyaKey ( 0, "L1" ) 
R1 = this.getOuyaKey ( 0, "R1" )

--analog triggers values from 0 > 1
L2 = this.getOuyaAxis ( 0, "AXIS_L2" ) 
R2 = this.getOuyaAxis ( 0, "AXIS_R2" )

--analog joystick buttons
L3 = this.getOuyaKey ( 0, "L3" ) 
R3 = this.getOuyaKey ( 0, "R3" )

--Buttons
bA = this.getOuyaKey ( 0, "O" )
bB = this.getOuyaKey ( 0, "A" )
bX = this.getOuyaKey ( 0, "U" )

--Example of getting Y button in latched state of down
bY = this.getOuyaKeyLatched ( 0, "Y", true )

--System button
bSystem = this.getOuyaKey ( 0, "SYSTEM" )

--Digital pad
dLeft = this.getOuyaKey ( 0, "LEFT" )
dRight = this.getOuyaKey ( 0, "RIGHT" )
dUp = this.getOuyaKey ( 0, "UP" )
dDown = this.getOuyaKey ( 0, "DOWN" )

--Touchpad
touchX = this.getOuyaAxis( 0, "TOUCHPAD_X" )
touchY = this.getOuyaAxis( 0, "TOUCHPAD_Y" )

--If you are querying latched button states, you need to call this at the end
--of your input query loop. It's important that you only call this from the AI
--that you're reading button events from.
user.sendEventImmediate ( hUser, "OuyaController", "onUpdateOldKeyStates", 0 )

Purchasing

There are 4 key handlers in the OuyaPurchase AI that let you deal with in-app purchases:

  • onRequestOuyaGamerID( )
  • onRequestOuyaProduct( )
  • onRequestOuyaPurchase( nIndex )
  • onRequestOuyaReceipts( )

Since these fire off async calls, each of these 5 handlers has a receiver counterpart to receive the callback:

  • onReceiveOuyaGamerID ( sID )
  • onReceiveOuyaProduct ( sID, sProductName, nCostInCents )
  • onReceiveOuyaPurchase ( bSuccess )
  • onReceiveOuyaReceipt ( sID, sDate, nPrice )

These 8 handlers together form the entire process of in-app purchases. To configure, you need to do the following in the main java file (yourgame.java if you haven't renamed it):

  1. Set bInAppPurchasingEnabled = true;
  2. Set DEVELOPER_ID to your OUYA developer ID
  3. Set PRODUCT_ID_LIST to your product IDs as defined in your OUYA dev portal. e.g public static final List<Purchasable> PRODUCT_ID_LIST = Arrays.asList(new Purchasable("long_sword"), new Purchasable("sharp_axe")

About

OUYA ODK integration for the ShiVa 3D Game Engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors