28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />

Game Design Concepts: Sprites, Physics, Collision<br />

Let’s take a look at the various game design components that we you will need to understand to be able to build a<br />

game, as well as what <strong>Java</strong> 8 (or <strong>Java</strong>FX) packages and classes you can use to implement these aspects of game play,<br />

which I like to term components of game play. These can include the game play elements themselves (commonly<br />

referred to as sprites) as well as processing engines, which you will either code yourself, or import preexisting <strong>Java</strong><br />

code libraries for, such as physics simulation and collision detection.<br />

Sprites are the foundation of game play, defining your main character, projectiles used to damage this main<br />

character, and the enemies firing these projectiles. Sprites are 2D graphics elements and can be either static (fixed,<br />

a single image) or dynamic (animated, a seamless loop of several images). A sprite will be moved around the screen<br />

based on programming logic, which dictates how the game is to function. Sprites need to be composited with<br />

background imagery and other game elements as well as other sprites and so the graphics used to create the sprites<br />

will need to support transparent backgrounds.<br />

In Chapter 4, I introduced you to the concept of alpha channels and transparency. You will need to achieve this<br />

same end result with your sprites to create a seamless visual experience with your game. The next most important<br />

aspect of game play is collision detection, because if your sprites simply flew right past each other on the screen<br />

and never did anything cool when they touched, or “intersected” each other, then you really would not have much<br />

of a game! Once you add a collision detection engine (composed of intersection logic processing routines) your<br />

game can ascertain when any two sprites are touching (edges) or overlapping each other. A collision detection will<br />

call (trigger) other logic processing routines that will determine what happens when any two given sprites, such as<br />

a projectile and the main character, intersect. For example, when a projectile intersects the main character, damage<br />

points might accrue, life force index might be decreased, or a death animation may be started. In contrast, if a treasure<br />

item intersects with (is picked up by) the main character, power or capability points might accrue, the life force index<br />

might be increased, or an “I found it” jubilation animation might be started. As you can see, the collision detection for<br />

your game is one of the foundational design elements of your game play, besides the sprites (characters, projectiles,<br />

treasures, enemies, obstacles, and so on) themselves, which is why I am covering this concept early on in the book.<br />

The concept next in significance to your game play is real-world physics simulation. The addition of things like<br />

gravity; friction; bounce; drag; acceleration; motion curves, such as the <strong>Java</strong>FX Interpolator class provides; and the like<br />

add an additional level of realism on top of the already photo-realistic sprites, synchronized animation sequences,<br />

scenic backgrounds, and highly accurate collision detection.<br />

Finally, the most proprietary attribute, or logic construct (<strong>Java</strong> code), to add to your game play is the custom<br />

game play logic, which makes your game truly unique in the marketplace. This logic should be kept in its own <strong>Java</strong><br />

class or methods, separate from physics simulation and collision detection code. After all, <strong>Java</strong> 8 makes your code<br />

modularization well-structured if you learn the OOP concepts and apply them to your programming logic!<br />

When you start to add all these game components together, they begin to make the game more believable as<br />

well as more professional. One of the key objectives for a great game is suspension of belief, which means that your<br />

player is buying into the premise, characters, objectives, and game play completely. This is the same objective that any<br />

content producer, whether he or she be a filmmaker, television producer, author, songwriter, <strong>Java</strong> 8 game programmer,<br />

or application developer, is going for. <strong>Games</strong> these days have the same revenue-generating capability as any of the<br />

other content distribution genres, if not more.<br />

Next, let’s take a look at the different types of games that can be created and how these differ in their application<br />

of the core game components of sprites, collision detection, physics simulation, and game play logic.<br />

Types of <strong>Games</strong>: Puzzles, Board <strong>Games</strong>, Arcade <strong>Games</strong>, Hybrids<br />

Like everything else I have talked about in this chapter, games themselves can be categorized by using a<br />

static-versus-dynamic classification approach. Static games are not processor bound, because they tend to be turn<br />

based and not hand-eye coordination based in nature, and so, in a sense, they are easier to get working smoothly;<br />

only the programming logic for the rules of game play and the attractive graphics have to be put in place and<br />

104<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!