Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
54 views45 pages

Chapter 02 0

creacion de juegos

Uploaded by

eduardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views45 pages

Chapter 02 0

creacion de juegos

Uploaded by

eduardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Creating Games on the Java™ Platform with

the jMonkeyEngine

Joshua Slack, Rikard Herlitz


jMonkeyEngine
jMonkeyEngine.com
TS-5711
Our Goal:
To get you started on the path to creating
professional quality 3D games and
applications in Java™ technology today!

2008 JavaOneSM Conference | java.sun.com/javaone | 2


Our other jobs…

NCsoft Corp
Makers of popular online
games such as Guild Wars,
Lineage, City of Heroes,
and Tabula Rasa
Started hiring
jMonkeyEngine developers
in 2006
Demonstrated a strong
commitment to the Java
gaming community by
actively contributing back to
the jMonkeyEngine

2008 JavaOneSM Conference | java.sun.com/javaone | 3


Agenda:

Myths and Realities


Getting Your Feet Wet
Taking it to the Next Level
Trail Blazers
Q&A

2008 JavaOneSM Conference | java.sun.com/javaone | 4


Myths and Realities

#1 - Speed
• Myth: Java technology is too slow for games
• Reality: Since 1.4.2, Java technology has closed the speed gap.
Besides, much of the heavy lifting in games can be left to the
hardware.

#2 - Visual Quality
• Myth: Java technology-based games are ugly. Just look at [game X]
• Reality: With jMonkeyEngine, quality is limited by the art assets you
have available and your skill as a graphics programmer –not the
language.

2008 JavaOneSM Conference | java.sun.com/javaone | 5


Myths and Realities

Is this what Java based games have to look like?

2008 JavaOneSM Conference | java.sun.com/javaone | 6


Myths and Realities

Here’s an example of what can be done!

2008 JavaOneSM Conference | java.sun.com/javaone | 7


Let’s get our feet wet!

What is the jMonkeyEngine?

jMonkeyEngine is a 3D scene graph that empowers you to


create high quality games and applications with engaging
graphics and sound.

The engine is written 100% in Java programming language


and uses a thin JNI layer to communicate directly with your
audio, video and input device hardware.

2008 JavaOneSM Conference | java.sun.com/javaone | 8


The 10,000 Foot View
Your Code

jMonkeyEngine Core

Scene Input Resource Graphics


Management Management Management Utils

Model Collision / Audio Community


Importers Boundings Management Extensions

LWJGL jME-physics

OpenGL OpenAL jInput ODE, PhysX, …

2008 JavaOneSM Conference | java.sun.com/javaone | 9


Making a Simple Game

“MonkeyPong”

Why?
• We aren’t artists
• Everyone knows the mechanics of the game
• Everything we need is right there in the engine API

2008 JavaOneSM Conference | java.sun.com/javaone | 10


First Step – the framework

We can get up and running very quickly by using one of


jME’s application classes:
• AbstractGame, SimpleGame, SimplePassGame, StandardGame

We’ll use SimpleGame for this game.

public class MonkeyPong extends SimpleGame {


protected void simpleInitGame() {
}
}

2008 JavaOneSM Conference | java.sun.com/javaone | 11


Next – the game elements

We use jME’s primitives for our ball, walls and paddles


ball = new Sphere("Ball", 8, 8, 2);
ball.setModelBound(new BoundingSphere());
ball.updateModelBound();

player1 = new Box("Player1", new Vector3f(), 2, 5, 10);


player1.setModelBound(new BoundingBox());
player1.updateModelBound();
player1.getLocalTranslation().set(-100, 0, 0);

2008 JavaOneSM Conference | java.sun.com/javaone | 12


Now – input control

The simplest way of getting keyboard input is through the


KeyBindingManager
simpleInitGame() {
KeyBindingManager.getKeyBindingManager().set("MOVE_UP", KeyInput.KEY_W);
}

simpleUpdate() {
if (KeyBindingManager.getKeyBindingManager()
.isValidCommand("MOVE_UP", true)) {
player1.getLocalTranslation().z -=
player1Speed * timer.getTimePerFrame();
}
}

2008 JavaOneSM Conference | java.sun.com/javaone | 13


Mix in some collision…

Bounding box collision is more


than enough for us
simpleUpdate() {
if (player1.hasCollision(ball, false)) {
ballVelocity.x *= -1f;
}

if (sideWalls.hasCollision(ball, false)) {
ballVelocity.z *= -1f;
}

if (player1GoalWall.hasCollision(ball, false)) {
player2Score++;
}
}
2008 JavaOneSM Conference | java.sun.com/javaone | 14
Monkey Pong Live Demo #1

2008 JavaOneSM Conference | java.sun.com/javaone | 15


That was too easy, let’s add sound!

First we setup a track in our init section:


...
AudioTrack collideSound =
audio.createAudioTrack("/jmetest/data/sound/laser.ogg", false);
collideSound.setRelative(true);

Then we’ll simply play the track when we detect a collision:


...
collideSound.play();

Finally, make sure we update the AudioSystem in our


game loop:
...
AudioSystem.getSystem().update();

2008 JavaOneSM Conference | java.sun.com/javaone | 16


More spice…

Creating a particle system is easy through


the factory
ParticleMesh particles =
ParticleFactory.buildParticles("particles", 30);

Setup particle system lifetime, sizes, colors, etc.


particles.setInitialVelocity(.05f);
particles.setStartSize(3f);
...

Add an optional influence like gravity, wind or swarming


SwarmInfluence swarm = new SwarmInfluence(new
Vector3f(particles.getWorldTranslation()), .001f);
particles.addInfluence(swarm);

2008 JavaOneSM Conference | java.sun.com/javaone | 17


Adding water…

Realistic water with reflections and refraction is just a few


lines of code
waterEffectRenderPass = new WaterRenderPass(cam, 4, false, true);
waterQuad = new Quad("waterQuad", 1, 1);
waterEffectRenderPass.setWaterEffectOnSpatial(waterQuad);

2008 JavaOneSM Conference | java.sun.com/javaone | 18


Terrain…

Generate a terrain from image data or through our


heightmap generators
RawHeightMap heightMap = new RawHeightMap(MonkeyPong.class
.getClassLoader().getResource(
"jmetest/data/texture/terrain/heights.raw").getFile(),
129, RawHeightMap.FORMAT_16BITLE, false)
TerrainPage page = new TerrainPage("Terrain", 33, heightMap.getSize(),
terrainScale, heightMap.getHeightMap(), false);

2008 JavaOneSM Conference | java.sun.com/javaone | 19


Monkey Pong Live Demo #2

2008 JavaOneSM Conference | java.sun.com/javaone | 20


Let’s recap…

jMonkeyEngine provides a lot of foundational


classes and examples to get you started
You can use jME’s supplied special effects to add
extra punch to your game
Even with a programmer’s eye for art, you can build
a fun game

Get a closer look at the source for this example


from the jME project svn

2008 JavaOneSM Conference | java.sun.com/javaone | 21


Taking it to the Next Level

Production quality games require a whole new level of


effort
To make such a game we need to work together with other
creative types:
• Artists
• Level builders
• Game designers
Collaboration is achieved through good pipeline and tools
Tool installation and start-up needs to be fast and hassle-
free

2008 JavaOneSM Conference | java.sun.com/javaone | 22


Pipeline

Your game’s pipeline is the path that artist generated


content takes to get from their mind into the game

jME has support for most popular image formats and some
standard audio formats:
• tga, png, jpg, gif, bmp, dds.
• wav, ogg

We also have support for several standard model formats:


• Ase, Obj, 3ds, Md2-Md5, X3d, Milkshape and Collada

2008 JavaOneSM Conference | java.sun.com/javaone | 23


Pipeline (continued)

But jME needs to improve in this area:


• Improved Collada support
• Community is working on better md5 support.
• Create an XML equivalent to our binary import/export process and
let the community create their own exporters (or tools.)

2008 JavaOneSM Conference | java.sun.com/javaone | 24


Tools

Tools turn your pipeline assets into a game environment

Options Include:
• MonkeyWorld 3D – Built using SWT and Eclipse RCP
• Various small utilities in jME – Particle Editor, Control Editor, etc.
• Rolling your own tool

2008 JavaOneSM Conference | java.sun.com/javaone | 25


Tools

Roll Your Own - An Example: NCsoft’s World Builder


• Swing + jME Canvas
• Created by a small team in short time
• Some features include:
• Asset integration with Perforce, terrain generation/painting, lighting,
lightmap generation, LOD setup, etc.

2008 JavaOneSM Conference | java.sun.com/javaone | 26


NCsoft’s
Java technology-based
World Builder

2008 JavaOneSM Conference | java.sun.com/javaone | 27


Tools continued…

Not many cons


• Direct memory handling
• Native buffer performance

But lots of pros


• Your tool runs anywhere (many artists prefer Macs)
• Swing GUI development
• Exception handling (not many hard crashes)
• Logging (console, file, mail)
• Scripting (Lua or JavaScript™ programming language, etc.)

2008 JavaOneSM Conference | java.sun.com/javaone | 28


Client

Things to consider on your game client:


• Aim for min spec, next-gen, or use fallbacks to handle both?
• Give users controls – give as many configuration options as you
can to allow the user to tweak things for their platform. (But use
smart default settings.)
• User Interface – several options: BUI, FengGUI, jMEDesktop or
your own
• Deploying your game:
• Format: Applet or application
• Java technology installation and min version
• Delivery: Webstart, GetDown, etc.
• Crash reporting and bootstrapping
• Future options: Java Consumer JRE

2008 JavaOneSM Conference | java.sun.com/javaone | 29


To recap…

You can make use of existing model and asset formats


To make a professional game, you need artists and you
need to provide them with tools
There are some existing tools
It’s easy to make your own tools with jME embedded

2008 JavaOneSM Conference | java.sun.com/javaone | 30


Evaluating Java as a Game Platform:
Selling Points
Versatile deployment options
• Applet or application; fullscreen or windowed
Error handling is more elegant
• Easier than in traditional C/C++ frameworks
Cross Platform:
• OpenGL + Java platform means never having to say you’re sorry
The Power of Java technology:
• Easy to use, familiar, powerful
• Lots of open source code out there to make use of
• Easy integration into web-services, etc.

2008 JavaOneSM Conference | java.sun.com/javaone | 31


Evaluating Java as a Game Platform:
Issues
Major Problem Area – Infrastructure
• Lack of source materials (books, articles, code samples)‫‏‬
• Lack of existing games
• Lack of developer support (disbelief, inexperience)‫‏‬
• Lack of middleware support

ALL of these points can be turned around rather quickly


• This is still a fairly new area for Java technology
• Releasing one or two high quality games would change attitudes
and give inspiration (and create experienced developers)‫‏‬
• Use by companies or universities with money to spend will
encourage existing middleware to add Java technology support
• Will this happen?

2008 JavaOneSM Conference | java.sun.com/javaone | 32


It's Already Happening – Commercial Games

Hockey Heroes
Bang! Howdy Jadestone
Three Rings Ice hockey with an attitude.
Fast-paced wild west tactical strategy
game.

2008 JavaOneSM Conference | java.sun.com/javaone | 33


It's Already Happening - Commercial Games

Nord
Call of the Kings SLX Games
Gamalocus Your personal online social
experience.
Online fantasy strategy-roleplaying
game.

2008 JavaOneSM Conference | java.sun.com/javaone | 34


It's Already Happening - Commercial Games

JCRPG – Classic Project X


RPG NCsoft Corporation
JCRPG team Unannounced game under development…

Open source classic RPG framework.

2008 JavaOneSM Conference | java.sun.com/javaone | 35


It's Already Happening – Casual Gaming

Mad Skills Motorcross


BigFun Turborilla
Motorcycle Trials Race against the neural network
trained riders to prove you’re the best.
OurAwesomeGames
Perform dangerous feats of skill on
your trusty motorcycle.

2008 JavaOneSM Conference | java.sun.com/javaone | 36


It's Already Happening – Event Based Entertainment

Polyball 2007
Sail the high seas and do ship combat in front of a
ball room of nine thousand guests.

2008 JavaOneSM Conference | java.sun.com/javaone | 37


It's Already Happening – Student Projects

Lord of the Fjord


Matics Georgia Tech
Georgia Tech Viking boat bongo battle!
Puzzle based platformer with real
physics.

2008 JavaOneSM Conference | java.sun.com/javaone | 38


It's Already Happening – Research Applications

Multitouch Environment
Wubble World Durham University
USC Research into interactive learning
interfaces
Interactive playground for AI research.

2008 JavaOneSM Conference | java.sun.com/javaone | 39


It's Already Happening – Commercial

JPericia
Project Team Cadanus
Wonderland Scene visualizer for crime scene
investigation in Brazil.
Sun Microsystems
Toolkit for creating collaborative 3D
worlds.

2008 JavaOneSM Conference | java.sun.com/javaone | 40


It's Already Happening - Science

Intelligent Robotics Group - NASA


Ames
Giving scientists the tools to visualize the next Mars lander mission and
beyond.

2008 JavaOneSM Conference | java.sun.com/javaone | 41


jME 2.0 – The future

Planned features include:


• Easy/safe threading
• Separate game and render loop
• Visibility/space partitioning handling in core
• More Enumerations
• Latest in OpenGL features
• Refactoring / documentation
• Pipeline Improvements
• Community code process

The jME 2.0 Architecture group

2008 JavaOneSM Conference | java.sun.com/javaone | 42


jMonkeyEngine in action!

2008 JavaOneSM Conference | java.sun.com/javaone | 43


For More Information

Check us out on line:


• Home: www.jMonkeyEngine.com
• Wiki: www.jMonkeyEngine.com/wiki

Talk to the community!


• Forums: www.jMonkeyEngine.com/jmeforum

Check out the “MonkeyPong” source:


• jME’s SVN repository:
• http://code.google.com/p/jmonkeyengine/source/checkout

2008 JavaOneSM Conference | java.sun.com/javaone | 44


Rikard Herlitz, Joshua Slack
jMonkeyEngine
jMonkeyEngine.com

TS-5711

2008 JavaOneSM Conference | java.sun.com/javaone | 45

You might also like