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 16 ■ Collision Detection: Creating SVG Polygons for the Game Actors and Writing Code to Detect Collision<br />

The SVG Data Format: Hand Coding Vector Shapes<br />

There are ten different letters that can be utilized with the numeric (X,Y data point location in 2D space) data in an<br />

SVG data string. Each has an upper case (absolute referencing) and a lower case (relative referencing) version. We will<br />

be using absolute referencing as we need these data points to match up with pixel locations in the sprite imagery that<br />

we are going to “attach” or group these SVG Path data strings with to provide collision detection data guidelines. As<br />

you can see in Table 16-1, the SVG data commands provide you a great deal of flexibility in defining custom curves for<br />

your <strong>Java</strong> 8 game development. You could even combine all of these scalable vector commands with your <strong>Java</strong> 8 code<br />

to create interactive vector (digital illustration) artwork that has never before been experienced, but since this is a<br />

game development title, we’re going to use this information to develop highly optimized collision polygons that only<br />

use a dozen X,Y data points (somewhere between 12 and 15) to define a relatively detailed collision polygon that will<br />

encase our sprite imagery, and provide highly accurate (from the game player’s viewpoint, at least) collision results.<br />

Table 16-1. SVG data commands to use for creating SVG path data string (source: Worldwide Web Consortium w3.org)<br />

SVG Command Name Symbol Type Parameter Description<br />

moveto M Absolute X, Y Defines a Start Of Path at the X,Y using<br />

absolute coordinates<br />

moveto m Relative X, Y Defines a Start Of Path at the X,Y using<br />

relative coordinates<br />

closepath Z Absolute None Close SVG Path, by drawing line from last to<br />

first coordinate<br />

closepath z Relative None Close SVG Path, by drawing line from last to<br />

first coordinate<br />

lineto L Absolute X, Y Draws a Line from the current point to the<br />

next coordinate<br />

lineto l Relative X, Y Draws a Line from the current point to the<br />

next coordinate<br />

horizontal lineto H Absolute X Draws a Horizontal Line from current point to<br />

next coordinate<br />

horizontal lineto h Relative X Draws a Horizontal Line from current point to<br />

next coordinate<br />

vertical lineto V Absolute Y Draws a Vertical Line from current point to<br />

next coordinate<br />

vertical lineto v Relative Y Draws a Vertical Line from current point to<br />

next coordinate<br />

curveto C Absolute X,Y, X,Y, X,Y Draws a cubic Bezier curve from current<br />

point to next point<br />

curveto c Relative X,Y, X,Y, X,Y Draws a cubic Bezier curve from current<br />

point to next point<br />

shortandsmoothcurve S Absolute X,Y, X,Y Draws a cubic Bezier curve from current<br />

point to next point<br />

(continued)<br />

344<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!