Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 4 ■ an IntroduCtIon to Game desIGn: Game desIGn ConCepts, Genres, enGInes, and teChnIques

simulation code will be triggered to show the game player how the objects need to react to each other after
that collision. So, let’s take a look at that next.


Physics Simulation: The Foundation of Gameplay Realism


Another important component, or attribute, to add to your gameplay is real-world physics simulation. The
addition of things like gravity, friction, bounce, drag, wind, acceleration, deceleration, and motion curves,
like the JavaFX Interpolator class provides, and similar forces, will each add an additional level of realism
on top of the already photorealistic sprites, your synchronized animation sequences, scenic backgrounds,
and highly accurate collision detection.
Gravity, friction, drag, and wind are the easiest factors to either simulate or adjust a 2D sprite or 3D model
movement for in your Java code. I touch on this near the end of my book Beginning Java 8 Games Development
(Apress, 2014). Bounce is similar to the mathematics done for acceleration and deceleration in motion curves,
which could be used to simulate a single bounce, but not the decay of a bounce that a physics simulation will.
You can code your own Java methods to apply physics to your pro Java game or you can use the third-
party Java libraries, which are available on sites like SourceForge, GitHub, or code.google.com. I will cover
some of the libraries that are out there for 2D and 3D game engines, 2D and 3D physics simulation engines,
2D and 3D collision detection engines, forward and inverse kinematics engines, and the like. I will cover this
in the next major section for this chapter, just in case you want to use these in your pro Java games or IoT
applications instead of writing your own.
It is interesting to note that most of the open source third-party physics engines, which I’m going
to cover in the “Java Engines: Game, Physics, and Inverse Kinematic” section of this chapter, not only
implement physics simulation but also implement collision detection. This is because these two things are
closely tied together in real life. To do collisions really well, the physics simulation needs to be a seamless
integration in that code. There are physics involved both before and after a collision in real life, and these
engines seek to re-create real-life (completely believable) implementation results. Be advised that as of Java
9 these offerings will need to be “modularized” for use with the new Java 9 module system in order to be
used properly within that system.


Artificial Intelligence: The Foundation of Your Gameplay Logic


Finally, the most proprietary attribute or logic constructs (Java code) that you can add to add to your
gameplay is the custom gameplay logic, which makes your game truly unique in the marketplace. This
artificial intelligence (AI) programming logic should be kept in its own Java class and methods, separate
from physics simulation or collision detection code. After all, Java makes modularization easy, and this
gameplay intelligence is like the referee for your pro Java game. It oversees the player, opponents, obstacles,
treasure, scoring, penalties, and similar, making sure the game experience is the same every time and for
everyone! This is the same function that a referee performs at a sporting event or competition.
There are third-party AI engines for Java; however, I suggest this is an area where you may want to write
your gameplay logic code from scratch so that it integrates with your user interface (UI) code, your scoring
engine code, your animation engine code, your actor (sprites or models) movement code, and your collision
processing code in a much more seamless fashion than any third-party AI rules engine ever could.
When you start to add all these game components together, it starts to make the game more believable,
as well as more professional. One of the key objectives for a great game is “suspension of belief,” which
simply means that your player is “buying into” the premise, characters, objectives, and gameplay 100 percent
completely. This is the same objective that any content producer, whether it be a filmmaker, television series
producer, author, songwriter, game programmer, or application developer, is going for. Games these days
have the same revenue generation capability as any of the other content distribution genres, if not more, and
you can distribute them directly to the public without a middleman such as a movie studio, record producer,
or television network. That’s the most significant part, as you will get a “70 percent you, 30 percent store”
split, rather than a “70 percent distributor, 30 percent you” split!

Free download pdf