Gamasutra: The Art & Business of Making Gamesspacer
Games Demystified: Rolando
View All     RSS
May 22, 2018
arrowPress Releases
May 22, 2018
Games Press
View All     RSS






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Games Demystified: Rolando


June 3, 2009 Article Start Previous Page 2 of 3 Next
 

Touch the World

Let's begin with the simplest technique: touch. This is a sensation we almost take for granted because it's so innate. Touch has always been a component in video game play. It's actually the joint that hinges our audio-visual experience to the rest of our body and makes a game feel tangible. Though it is widely perceived that touching a flat screen somehow produces a less tangible game, Rolando proves otherwise.

In Rolando, players can call upon characters -- the rolandos -- by touching or drag-box selecting them. When this happens the character is ready to go and then reacts to the tilt mechanism. In addition players can touch and move additional objects like elevators and gears.

In these instances players are directly manipulating objects that the rolandos are either too "weak" or lack the proper appendages to manipulate themselves. It is in these instances that the rolandos' worship sessions of the finger are most appropriate.

Let's have a look at some touch code. Though the original game was not written in this engine, the samples provided for this segment of Games Demystified -- downloadable here in a package -- are written in JavaScript for the Unity Engine, which is a fantastic component based engine.

The first component we'll examine is camera and the touch functionality of the device. In the game you can select a single rolando by tapping on them or you can select an entire gang of rolandos with an RTS-style selection box. Below is the code responsible for the highlight and selection of a rolando.

Camera Component:

var rolando : Transform;

private var debug : String;

private var initialSelection : Vector2 = Vector2( 0, 0 );
private var hit : RaycastHit;
private var selected : boolean = false;
private var touch : iPhoneTouch;

function FixedUpdate()
{
var ray = Camera.main.ScreenPointToRay( Vector2( touch.position.x, touch.position.y ) );
var layerMask = 1 << 2;
layerMask = ~layerMask;
if ( Physics.Raycast( ray, hit, 100 ) )
{
if ( hit.collider == rolando.collider )
{
selected = true;
rolando.SendMessage( "select", true );
rolando.SendMessage( "highlight", true );
}
else
{
selected = false;
rolando.SendMessage( "select", false );
rolando.SendMessage( "highlight", false );
}
}
}

function LateUpdate()
{
if ( !selected )
{
if ( iPhoneInput.touchCount == 2 )
{
touch = iPhoneInput.GetTouch( 0 );
transform.position == Vector3( transform.position.x, transform.position.y, -20 );
transform.position -= Vector3( touch.positionDelta.x, touch.positionDelta.y, 0 );
}
}
else
transform.position = Vector3( rolando.transform.position.x, rolando.transform.position.y, -10);
}

function OnGUI()
{
useGUILayout = false;
GUI.Box( Rect( 0, 0, 480, 20 ), "Debug - " + debug );

var screenPos : Vector2;
if ( iPhoneInput.touchCount == 1 )
{
touch = iPhoneInput.GetTouch( 0 );

if ( initialSelection == Vector2( 0, 0 ) )
initialSelection = touch.position;

if ( touch.position.x > initialSelection.x && initialSelection.y > touch.position.y )
GUI.Box( Rect( initialSelection.x, 320 - initialSelection.y, touch.position.x - initialSelection.x, initialSelection.y - touch.position.y ), "" );
if ( touch.position.x < initialSelection.x && initialSelection.y > touch.position.y )
GUI.Box( Rect( touch.position.x, 320 - initialSelection.y, initialSelection.x - touch.position.x, initialSelection.y - touch.position.y ), "" );
if ( touch.position.x > initialSelection.x && initialSelection.y < touch.position.y )
GUI.Box( Rect( initialSelection.x, 320 - touch.position.y, touch.position.x - initialSelection.x, touch.position.y - initialSelection.y ), "" );
if ( touch.position.x < initialSelection.x && initialSelection.y < touch.position.y )
GUI.Box( Rect( touch.position.x, 320 - touch.position.y, initialSelection.x - touch.position.x, touch.position.y - initialSelection.y ), "" );

if ( initialSelection != touch.position )
{
screenPos = Camera.main.WorldToScreenPoint( rolando.position );
if ( ( ( screenPos.x > initialSelection.x && screenPos.x < touch.position.x ) || ( screenPos.x < initialSelection.x && screenPos.x > touch.position.x ) ) && ( ( screenPos.y > initialSelection.y && screenPos.y < touch.position.y ) || ( screenPos.y < initialSelection.y && screenPos.y > touch.position.y ) ) )
rolando.SendMessage( "highlight", true );
else
rolando.SendMessage( "highlight", false );
}
}

if ( iPhoneInput.touchCount == 0 )
{
if ( initialSelection != Vector2( 0, 0 ) || ( initialSelection - touch.position ).magnitude < 5 )
{
screenPos = Camera.main.WorldToScreenPoint( rolando.position );
if ( ( ( screenPos.x > initialSelection.x && screenPos.x < touch.position.x ) || ( screenPos.x < initialSelection.x && screenPos.x > touch.position.x ) ) && ( ( screenPos.y > initialSelection.y && screenPos.y < touch.position.y ) || ( screenPos.y < initialSelection.y && screenPos.y > touch.position.y ) ) )
{
selected = true;
rolando.SendMessage( "select", true );
rolando.SendMessage( "highlight", true );
}
else
{
selected = false;
rolando.SendMessage( "select", false );
rolando.SendMessage( "highlight", false );
}
}
initialSelection = Vector2( 0, 0 );
}
}


Article Start Previous Page 2 of 3 Next

Related Jobs

Oath: A Verizon Company
Oath: A Verizon Company — Seattle, Washington, United States
[05.21.18]

Principal Engineer, HTML5 Games
Oath: A Verizon Company
Oath: A Verizon Company — Seattle, Washington, United States
[05.21.18]

Manager of Engineering, Full Stack
Oath: A Verizon Company
Oath: A Verizon Company — Seattle, Washington, United States
[05.21.18]

Manager of Engineering, Cloud Architecture
Cold Iron Studios
Cold Iron Studios — San Jose, California, United States
[05.18.18]

Infrastructure Engineer





Loading Comments

loader image