+ All Categories
Home > Technology > How to build Kick Ass Games in the Cloud

How to build Kick Ass Games in the Cloud

Date post: 21-Jan-2015
Category:
Upload: chris-schalk
View: 4,639 times
Download: 0 times
Share this document with a friend
Description:
This is a presentation given by Googlers Chris Schalk and Johan Euphrosine (Proppy) at GDD Sydney 2011 on how to build multi-platform video games using PlayN.
Popular Tags:
45
How to Build Kick Ass Games in the Cloud Christian Schalk Google Developer Advocate With special guest speaker, Proppy!
Transcript
Page 1: How to build Kick Ass Games in the Cloud

How to Build Kick Ass Games in the Cloud

Christian SchalkGoogle Developer Advocate

With special guest speaker, Proppy!

Page 2: How to build Kick Ass Games in the Cloud

About the Speaker

Christian Schalk

Day Job● Developer Advocate for Google's Cloud Technology

○ App Engine, Google Storage, Prediction API, BigQuery ...

● Mostly Server-Side Java Background○ "JavaServer Faces: The Complete Reference" Co-Author

● Haven't developed video games since the Commodore-64!

Yes, I'm old school ;-)

Page 3: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 4: How to build Kick Ass Games in the Cloud

First, Some Questions...

● Thinking of building a game for the Web?○ Would you use Flash?○ or HTML5?

● What if you wanted to port your game to Mobile?○ Do you need an entirely separate code base?

?

Page 5: How to build Kick Ass Games in the Cloud

● Thinking of building a game for the Web?○ Would you use Flash?○ or HTML5?○ Answer: Doesn't Matter!! Can do both!

● What if you wanted to port your game to Mobile?○ Do you need an entirely separate code base?○ Answer: NO!

First, Some Questions... ?

Page 6: How to build Kick Ass Games in the Cloud

● Thinking of building a game for the Web?○ Would you use Flash?○ or HTML5?○ Answer: Doesn't Matter!! Can do both!

● What if you wanted to port your game to Mobile?○ Do you need an entirely separate code base?○ Answer: NO!

First, Some Questions... ?

How is this Possible!??

Page 7: How to build Kick Ass Games in the Cloud

Introducing PlayN!!

One Game.Many Platforms.

Formerly known as "ForPlay"

Page 8: How to build Kick Ass Games in the Cloud

What is PlayN?

● An open source technology for building cross-platform games

● Core game code is platform agnostic

● Develop games in Java○ Familiar language/toolset

● Leverages Google Web Toolkit○ Compiles to JS/HTML5, (among other platforms)

● Free and Open Source (alpha)○ http://code.google.com/p/playn

Page 9: How to build Kick Ass Games in the Cloud

PlayN API Structure

Implementations for Java, HTML5(GWT/JS), Android, Flash

PlayN API

Flash impl.

Page 10: How to build Kick Ass Games in the Cloud

Components of PlayN

Fully generic gaming components. Core game logic is fully platform independent!

Extend PlayN.Game PlayN.*

Page 11: How to build Kick Ass Games in the Cloud

PlayN Cross Platform Magic

● Game uses core PlayN abstractions, is unaware of which platform is running

● The only platform-specific code is in the entry point for each platform:

PlayN.run(new MyGame()); PlayN.run(new MyGame());

Page 12: How to build Kick Ass Games in the Cloud

Other PlayN Benefits

● Built-in physics engine based on proven OpenSource technologies

● Box2D○ C++ 2D Physics engine by Erin Catto

● JBox2D○ A port of Box2D from C++ to Java

● GWTBox2D○ A port of JBox2D from Java to JavaScript

Page 13: How to build Kick Ass Games in the Cloud

Benefits of GWT Abstraction

● GWT Compiler optimizes code for size○ Removes unused code○ Evaluates when possible at compile time○ Heavily obfuscated result code

● Smaller compiled code - faster load time

● Optimized caching, avoids unnecessary network IO

Page 14: How to build Kick Ass Games in the Cloud

The PlayN Game Loop

public class MyGame implements Game { public void init() { // initialize game. } public void update(float delta) { // update world. } public void paint(float alpha) { // render world. } }

Similar to other gaming platforms

Page 15: How to build Kick Ass Games in the Cloud

PlayN Rendering

// Resize to the available resolution on the current device.graphics().setSize( graphics().screenWidth(), graphics().screenHeight());// Keep the same aspect ratio.float sx = graphics().screenWidth() / (float) WIDTH;float sy = graphics().screenHeight() / (float) HEIGHT;

// Fit to the available screen without stretching.graphics().rootLayer().setScale(Math.min(sx, sy));

Can easily with different screen parameters

Page 16: How to build Kick Ass Games in the Cloud

PlayN Drawing API

Page 17: How to build Kick Ass Games in the Cloud

PlayN Layer System

Page 18: How to build Kick Ass Games in the Cloud

Layer Types

● Layers have distinct sizes and transforms● Used to optimize

Page 19: How to build Kick Ass Games in the Cloud

IO System: Platform Abstractions

● Pointer○ Most general screen event○ Works everywhere

● Mouse○ Left, right, mid buttons & wheel

● Touch○ Pressure, size, multitouch

Page 20: How to build Kick Ass Games in the Cloud

IO System: Input Devices

pointer().setListener(new Pointer.Adapter() { public void onPointerStart(Pointer.Event event) { // Handle mouse down event. } // ...Same pattern for onPointerEnd, onPointerDrag});

keyboard().setListener(new Keyboard.Adapter() { public void onKeyDown(Event event) { // Handle key down event. } // ... Same pattern for onKeyUp});

Page 21: How to build Kick Ass Games in the Cloud

Asset Management

public interface AssetManager {

Image getImage(String path); Sound getSound(String path); void getText(String path, ResourceCallback callback); boolean isDone(); int getPendingRequestCount();}

Page 22: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 23: How to build Kick Ass Games in the Cloud

Requirements for getting started with PlayN

● Core Requirements○ Java 6 SDK○ Apache Ant○ Maven○ App Engine SDK○ Android SDK

● Requirements with Eclipse○ Eclipse IDE Indigo 3.7 (Or earlier version w/

Maven)○ Google Plugin for Eclipse○ Android Plugin for Eclipse

Page 24: How to build Kick Ass Games in the Cloud

Building/Installing PlayN

● PlayN 1.0 is now available in Maven Central!○ Wiki will be updated soon, but can simply create a Maven project

● Or can clone a copy of PlayN○ git clone https://code.google.com/p/playn

● Then...○ cd playn (directory where your copy is location)○ mvn install (or 'ant install')

● Running 'showcase' sample app with Mvn○ cd playn/sample/showcase/core○ mvn compile exec:java

● Running 'showcase' sample app with Ant○ cd playn/sample/showcase○ ant run-java

Page 25: How to build Kick Ass Games in the Cloud

Demo: How to get started w/ PlayN

http://code.google.com/p/playn

Page 26: How to build Kick Ass Games in the Cloud

Building a new project in PlayN

● From the command line:○ mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn

-DarchetypeArtifactId=playn-archetype○ ...

● From Eclipse○ Select File → New → Project..., then select Maven →

Maven Project in the dialog that pops up, then click Next.

■ Click Next again unless you wish to specify a custom workspace location.■ Check Include snapshot archetypes in the dialog and then double click

on the playn-archetype in the list of archetypes○ ...

Page 27: How to build Kick Ass Games in the Cloud

Demo: Building a new Game in PlayN

Page 28: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

■ http://proppy-playn101.appspot.com/● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 29: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 30: How to build Kick Ass Games in the Cloud

Deploy your HTML project to the Cloud

● For Google App Engine Deployment, you can easily convert the project to an App Engine Project

Page 31: How to build Kick Ass Games in the Cloud

Deploy your HTML project to the Cloud

● After converting your HTML project to an App Engine project you will have to do...

● Add a 'WEB-INF/lib/appengine-web.xml' file○ Note: Click 'Quick Fix' in the Errors console of

Eclipse

● Before deployment make sure your 'WEB-INF/lib' has the necessary runtime App Engine jar files.

Page 32: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 33: How to build Kick Ass Games in the Cloud

Setting up an RPC mechanism

● Building your client code○ You can use PlayN's Net().Post() call to send data to

a server

● Building Your Server○ PlayN comes with a preliminary Server example

code that uses Jetty■ Is not needed if deploying to App Engine■ Instead, you can implement your own server by

adding an HttpServlet to your project■ Have it implement the doPost() method■ Can map it to url: '/rpc' in web.xml

Page 34: How to build Kick Ass Games in the Cloud

Setting up an RPC mechanism● Example: A client method to persist a score

private void postScore(String payload) { net().post("/rpc", payload, new Callback<String>() { @Override public void onSuccess(String response) { // TODO } @Override public void onFailure(Throwable error) { // TODO } }); }

Page 35: How to build Kick Ass Games in the Cloud

Setting up an RPC mechanism● Example: Server method to persist score sent from client

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

String payload = readFully(req.getReader()); Json.Object data = json().parse(payload); String score = data.getString("score"); if (score != null){ persistScore(score, id); } }private void persistScore(String score) {...}

Page 36: How to build Kick Ass Games in the Cloud

Agenda

● PlayN Technology● Hands on with PlayN

○ Getting Started○ Building a game from scratch w/ Proppy

● Deploying your game to the cloud● Setting up an RPC mechanism● Integrating w/ Google Plus ● Summary

Page 37: How to build Kick Ass Games in the Cloud

Integrating your game with Google+

Visit http://developers.google.com/+

Download the Java Starter App

Page 38: How to build Kick Ass Games in the Cloud

Integrating your game with GooglePlus

Sample Starter App contains...

● README.txt with steps on:○ Visiting https://code.google.com/apis/console to

enable Google Plus API access for your app ■ To generate your

■ oauth_client_id, ■ oauth_client_secret,■ google_api_key

● Sample Java classes to redirect game users for OAuth authentication

Page 39: How to build Kick Ass Games in the Cloud

Integrating your game with GooglePlus

To access GooglePlus profile data..

Person profile;

try { profile = plus.people.get("me").execute(); } catch (HttpResponseException e) { log.severe(Util.extractError(e)); return; }

Page 40: How to build Kick Ass Games in the Cloud

Integrating your game with GooglePlus

Accessing GooglePlus profile data in a JSP page...

<a href="<%= profile.getUrl() %>">

<img src="<%= profile.getImage().getUrl() %>?sz=100"/></a>Welcome, <%= profile.getDisplayName() %>

Page 41: How to build Kick Ass Games in the Cloud

Demo: Introducing 'Cloud Warrior'

Google Storage

Game Assets(images/sounds)

Game ScoresProfile Data

App Engine

http://ae-cloudwarrior.appspot.com

Page 42: How to build Kick Ass Games in the Cloud

PlayN Summary

● Open source, cross-platform game abstraction layer○ Core game logic is platform agnostic

● ForPlay abstracts away the core components of a game○ The game loop, I/O system, and asset management

● Write in familiar Java, get performance on multiple platforms

○ Superior Java development/debug○ GWT allows compilation to fast JavaScript/HTML5

● Your assignment:○ Install PlayN and build a game! ○ http://code.google.com/p/playn/

Page 43: How to build Kick Ass Games in the Cloud

Announcing the New PlayN Developer Site!

http://developers.google.com/playn/

Page 44: How to build Kick Ass Games in the Cloud

Q&A

profiles.google.com/proppyprofiles.google.com/cschalk

Page 45: How to build Kick Ass Games in the Cloud

Thank You!


Recommended