Java For The Fun of It!

skatechildrenΛογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

48 εμφανίσεις

Session #3322

Java For The Fun of It!

Jack Frosch

Frosch Enterprises, Inc.

jfrosch@froschenterprises.com

Overview


Introduction


Game Development Overview


Air Campaign Commander Demo


How It Was Done


Resources

Introduction


About Me


Why Game Development At All?


Game Development in Java?


Disclaimers & Caveats

Jack Frosch

Founder & President

Frosch Enterprises, Inc.


Just 'cause they're paying us doesn't
mean we can't have fun!


About Me

Why Game Development At All?


Games Are Fundamental to Our
Nature


Helps You To Stretch Your Thinking


To Balance Technical and Natural


We All Need A Break

Game Development in Java??

Why Not?


Since JDK 1.02


Java APIs have come a long way


Java VMs have come a long way


Java is showing up everywhere


Hardware has come a long way


Linux + Java = Sony's PS2


Doing Java For The Fun of It!


Disclaimers and Caveats


You know you have to learn to walk before
you can run; this session is to teach you how
to crawl before you learn to walk!


The session is about the basic elements of
game development and doesn't address AI,
multi
-
player, or network gaming. My game is a
beta of a prototype to an alpha version of a
"real" game!


Legal Disclaimers: Java is a registered
trade
mark of Sun Microsystems; Borland is a
registered
trademark of Borland Inc; IBM is a
registered trade
mark of International Business Machines;
PS2 is a registered trade
mark of Sony Corporation; JavaOne
is a registered trade
mark of Sun Microsystems; JBuilder is a
registered trade
mark of Borland Inc; StartOffice is a registered trade
mark of Sun
Microsystems; Magic Draw UML is a trademark of No Magic, Inc.; Websphere is a registered
trademark of International Business Machines, Inc.; PalmPilot is a registered trade
mark of
Palm, Inc.; these slides are Copyright 2001, Frosch Enterprise, Inc. All other trade
marks and copyrights are
retained by their respective owners.

..........................................

You Are Here…


Introduction


Game Development Overview


Air Campaign Commander


How It Was Done


Resources

Game Development Overview


General Game Design


The Java Technology Platform


Java APIs Useful For Gaming


Development Tools

General Game Design

Elements of A Game

Some central theme

A Beginning and End

Fits
Into A
Genre

A Sense of Drama

An
Unknowable

Outcome

Fun and/or
Entertaining

A Setting Somewhere Else

Characters or
players, either
human, machine, or
animal

Suspension of Disbelief

Java Technology Platform

Prospects for Game Development


J2ME


Cell phones & PDAs


Game development exploding on this
platform


J2EE


Back
-
end servers


Support for multi
-
player games on Internet


J2SE


Desktops & Consoles


Game development is growing

Java APIs Useful For Gaming


Java Swing (included in JDK 1.3)


JavaSound (included in JDK 1.3)


Java2D (included in JDK 1.3)


Collections (included in JDK 1.3)


Java Media Framework (add
-
on)


Java 3D (add
-
on)


Others (JAXn, Batik)

Development Tools


Java SDK and add
-
on APIs are free


Here's What I Used


JDK 1.3.0 / 1.3.1 and JMF 2.1.1 (WPK)


JBuilder 4.0 / 5.0 Enterprise


Sonic Foundry Acid Style 1.0c and Sound
Forge XP 4.5b (for Sound Editing)


No Magic's MagicDraw 4.5 (beta)


MS PowerPoint 2002 (Presentation)

You Are Here…


Introduction


Game Development Overview


Air Campaign Commander


How It Was Done


Resources

Air Campaign Commander

Air Campaign Commander


Theme


Design of The Game


Demo


Configuring Forces


Game Play Demos

Air Campaign Commander

Theme


Capture The Flag


Two combatants wage war using
modern aircraft for attack and
missiles, anti
-
aircraft artillery, and
radar for defense


As Air Campaign Commander, you
get to acquire and organize assets
into operational units

Air Campaign Commander

Design Overview


Java 1.3 Standard Edition


Swing Based UI


Custom drawing using Java2D


Persistence Using JDataStore


Sound via JavaSound (through JMF)


Media via Java Media Framework 2.1.1

Air Campaign Commander

OO Design Overview


Asset Classes


GUI Classes


Miscellaneous Classes


Collections API

Air Campaign Commander

OO Design: Asset Classes

Air Campaign Commander

OO Design: GUI Classes

Air Campaign Commander

OO Design: Miscellaneous Classes

Air Campaign Commander

Demo: Configuring Forces


Combatant Editor


Asset Editor


Building Units


Deploying Units

Air Campaign Commander

Demo: Game Play


The Ultimate Irony


No Sound Effects, Video, or Music


Sound Effects Only


Background Music Track

You Are Here…


Introduction


Game Development Overview


Air Campaign Commander


How It Was Done


Resources

How It Was Done

An Overview of Key APIs


Java Swing / Java2D


Collections API


JDBC/JDataStore


JavaSound


Java Media Framework


Noteworthy Core Language Elements

How It Was Done

Java Swing Overview


Classes in javax.swing.** & java.awt.**


The Modified MVC Model


Containers


Controls


Layout Managers

How It Was Done

Java Swing: Modified MVC


MVC = Model
-
View
-
Controller


In this architecture, the presentation layer (View) is
separated from the data (Model). The management of
messages between the two is handled by a Controller


For better performance, Swing uses a Modified MVC
architecture.


The Swing approach is to put the Controller
functionality in the GUI control, but still keep a separate
Model for storing the data


For Swing developers, the pattern is simple:


Construct and populate the proper model


Construct the GUI component


Add xxxListener(s) to the component


Bind the model to the component


Don't be afraid to subclass models!

How It Was Done

Java Swing: Container Overview


Windows: JFrame and JDialog


The main application frame window is a
JFrame


The editor windows (AssetEditor,
CombatantEditor, etc.) are modal JDialog
windows


JPanel


A generic container for holding other
controls and custom drawing. The nesting
of panels is used to support more complex
layouts

How It Was Done

Java Swing: Window Tips


All windows use BorderLayout by default


When adding components, don't add directly
to window, but add to contentPane() instead;
e.g.


Windows have no size by default, so you must
call setSize() to initialize the size of the
window


Somewhat surprisingly, windows have no
close() method; call win.dispose() to send
WindowEvent to WindowListeners


How It Was Done

Java Swing: JPanel Tips


All JPanels use FlowLayout by default


JPanels are very lightweight, so don't be too
concerned about resource usage when nesting them.
They are NOT derived from awt.Panel, but are
lightweight JComponents


It's easy to create a border around a panel:
panel.setBorder(BorderFactory.createEtchedBorder());


Do custom painting using Java 2D in a panel that
subclasses JPanel. You usually only need to override
the paintComponent(Graphics) method. In this
method, you have to redraw all graphics that need to
be redrawn


Components are added directly to the panel

How It Was Done

Java Swing: Control Overview


Swing offers many rich controls for a game
developer; i.e. JButton, JCheckbox,
JComboBox, JLabel, JList, JRadioButton,
JTable, and JTree


JLabel is a wonderfully versatile control. Not
only does it display text, but it is used to
display graphics


Each control can dispatch one or more
message types to one or more listeners. This
allows a great deal of flexibility by promoting
"loose coupling". For instance, all
JComponents support mouse, keyboard, and
focus events, while buttons all support
ActionEvents, and JLists and JTables support
ListSelectionEvents, etc.

How It Was Done

Java Swing: Layout Managers


A Layout Manager enables the proper
presentation of controls in a container when
that container is redrawn


The key concept with most Layout Managers
is understanding how a control's
preferredSize dimensions will be dealt with:
honored, ignored, or resized


BorderLayout, used on windows by default,
divides the container into North, South, East,
West, and Center regions


FlowLayout is used on panels by default


CardLayout is good for stacking panels


XYLayout /null Layout makes prototyping
easy

How It Was Done

Collections API


The Collections API classes are in java.util.*.
Not thread
-
safe by default, but can be made
so easily


The game uses HashMap (and a derivative),
HashSet, TreeMap, and ArrayList


xxxMap collections have unique keys, but can
have duplicate (and null) values; xxxSet
collections store unique keys and no values


Hashxxx collections are unordered; Treexxx
collections are ordered


ArrayList is a great substitute for Vector

How It Was Done

JDBC & JDataStore


Data in the game is persisted locally in
Borland's JDataStore object database
management system


JBuilder provides a great set of JavaBeans
that hide most of the JDBC complexity. The
game uses the QueryDataSet (like
PowerBuilder DataStore), DataBase,
Connection, and TxManager beans.


Using an OO database generally made
persistence really easy since no OO
-
relational
mapping was needed, but it often got in the
way during development


Performance was surprisingly good

How It Was Done

JavaSound


The JavaSound API is included in JDK 1.3 and
the Java Media Framework


JavaSound supports playback, recording, and
MIDI


Since the game uses the JMF anyway, the
separate JavaSound API isn't used


JavaSound class files are in javax.sound.**


Note: When you download JDK 1.3, you won't
get a MIDI SoundBank and need to download
one separately


If Time Allows: JavaSoundDemo

How It Was Done

Java Media Framework


The Java Media Framework API is an add
-
on
API and handles time
-
synchronized rendering
of audio and video


It is an amazingly rich multimedia player
capable of capturing and playing audio and
video, clips and streams


The game uses
javax.media.bean.playerbean.MediaPlayer


Need to set up a ControllerListener to handle
events dispatched by the MediaPlayer


V2.1.1 is much better, but still has quirks.
Recommend playing large files in "static"
situations, not during game play

How It Was Done

Core Language Elements: Random


AirCampCdr.CustomRandom extends
java.util.Random to generate random
numbers, sometimes with bias


Math.random()


Seed set on first call


Math class is final


Probabilities calculated:


Radar Detection Probability


Firing Probability


Hit Probability


Damage Probability

How It Was Done

Core Language Elements: Arrays & Comparable


java.util.Arrays was used to sort Collection
data; i.e. Arrays.sort(arrayList.toArray() )


Objects in ArrayList must implement
java.lang.Comparable interface which
specifies a compareTo method


Classes implement the compareTo method to
specify how object's of that class are to be
compared to other objects

How It Was Done

Core Language Elements: Timer & TimerTask


java.util.Timer and java.util.TimerTask


GameTurn owns a Timer and GameInstance
owns a GameTurn


Subclass TimerTask and code your own run()
method. Then pass that task to one of the
timer.scheduleXXX methods


When the Timer fires at the interval specified,
the TimerTask subclass' run() method is
executed

Bonus Demos


Java 3D


Scalable Vector Graphics (Batik)


You Are Here…


Introduction


Game Development Overview


Air Campaign Commander


How It Was Done


Resources

Resources


JBuilder
(www.borland.com/jbuilder)


JMF
(java.sun.com/products/java
-
media/jmf/index.html)


Swing

(java.sun.com/products/jfc/tsc/index.html)


Acid Style and Sound Forge XP
(www.sonicfoundry.com)


Magic Draw UML
(www.nomagic.com)


Gaming:
(
www.javagaming.org; www.gamasutra.com)


Movie Trailers:

(
www.killermovies.com)

Thank You

Please fill out the speaker evaluation



You can contact me further at ...


jfrosch@froschenterprises.com