📄 465-467.html
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1571690433"><META name=vstitle content="Black Art of Java Game Programming"><META name=vsauthor content="Joel Fan"><META name=vsimprint content="Sams"><META name=vspublisher content="Macmillan Computer Publishing"><META name=vspubdate content="11/01/96"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Black Art of Java Game Programming:Building 3D Applets with App3Dcore</TITLE>
<!-- HEADER --><STYLE type="text/css"> <!-- A:hover { color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><script><!--function displayWindow(url, width, height) { var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes'); if (Win) { Win.focus(); }}//--></script><SCRIPT><!--function popUp(url) { var Win = window.open(url,"displayWindow",'width=400,height=300,resizable=1,scrollbars=yes'); if (Win) { Win.focus(); }}//--></SCRIPT><script language="JavaScript1.2"><!--function checkForQuery(fm) { /* get the query value */ var i = escape(fm.query.value); if (i == "") { alert('Please enter a search word or phrase'); return false; } /* query is blank, dont run the .jsp file */ else return true; /* execute the .jsp file */}//--></script></HEAD><BODY>
<TABLE border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=75 valign=top>
<img src="../1571690433.gif" width=60 height=73 alt="Black Art of Java Game Programming" border="1">
</td>
<td align="left">
<font face="arial, helvetica" size="-1" color="#336633"><b>Black Art of Java Game Programming</b></font>
<br>
<font face="arial, helvetica" size="-1"><i>by Joel Fan</i>
<br>
Sams, Macmillan Computer Publishing
<br>
<b>ISBN:</b> 1571690433<b> Pub Date:</b> 11/01/96</font>
</td>
</tr>
</table>
<P>
<!--ISBN=1571690433//-->
<!--TITLE=Black Art of Java Game Programming//-->
<!--AUTHOR=Joel Fan//-->
<!--AUTHOR=Eric Ries//-->
<!--AUTHOR=Calin Tenitchi//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=12//-->
<!--PAGES=465-467//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="462-465.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="467-470.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="CENTER"><A NAME="Heading28"></A><FONT COLOR="#000077">The cmAbstractStaticStructure Class</FONT></H4>
<P>The static structure is the root of all static buildings. Since all static structures are placed at ground level, the constructor only needs to know the coordinates of the structure in 2D. It then decides how high above the ground the object should be placed so that the bottom touches the ground. This, once again, is because of the way the vertices in an F3D file are centered and scaled.
</P>
<P>All structures are interested in collisions with weapon rounds like bullets and missiles. The default action taken in such a collision is to decrease the “health,” depending on the impact damage of the round. Extensions of this class might take additional actions.</P>
<P>Extensions of this class might be buildings, rocks, or anything that can be considered as an impassable structure. Listing 12-10 shows the abstract static structure class.</P>
<P><B>Listing 12-10</B> The abstract static structure</P>
<!-- CODE //-->
<PRE>
abstract class cmAbstractStaticStructure extends cmAbstractStaticObject{
protected cmAbstractStaticStructure (fWorld world, double x, double z,
fAngle3d agl, double w, double b, double h)
{
super(world,new fPoint3d(x,h,z),agl);
myHealth=Double.MAX_VALUE;
}
protected cmAbstractStaticStructure (fWorld world, double x, double z,
fAngle3d agl, double w, double b, double h, double health)
{
super(world,new fPoint3d(x,h,z),new fAngle3d(0,0,0),health);
}
public boolean interestedOfCollisionWith (fObject obj) {
if(obj instanceof cmAbstractRound) return true;
return super.interestedOfCollisionWith(obj);
}
protected boolean handleCollisionWith (fObject obj,double dt) {
if(obj instanceof cmAbstractRound){
myHealth-=((cmAbstractRound)obj).getImpactDamage();
if(myHealth<0) {
die();
}
}
return super.handleCollisionWith(obj,dt);
}
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="CENTER"><A NAME="Heading29"></A><FONT COLOR="#000077">The cmAbstractMovingStructure Class</FONT></H4>
<P>This class, shown in Listing 12-11, represents a moving structure, which is nearly the same as a static structure except that it can move around.
</P>
<P><B>Listing 12-11</B> The abstract moving structure</P>
<!-- CODE //-->
<PRE>
abstract class cmAbstractMovingStructure extends cmAbstractMovingObject{
protected cmAbstractMovingStructure (fWorld w, fPoint3d p, fAngle3d a,
fPoint3d dp, fAngle3d da)
{
super(w,p,a,dp,da);
myHealth=Double.MAX_VALUE;
}
protected cmAbstractMovingStructure (fWorld w, fPoint3d p, fAngle3d a,
fPoint3d dp, fAngle3d da,
double health)
{
super(w,p,a,dp,da,health);
}
public boolean interestedOfCollisionWith (fObject obj) {
if(obj instanceof cmAbstractRound) return true;
return super.interestedOfCollisionWith(obj);
}
protected boolean handleCollisionWith (fObject obj,double dt) {
if(obj instanceof cmAbstractRound){
myHealth-=((cmAbstractRound)obj).getImpactDamage();
if(myHealth<0) {
die();
}
}
return super.handleCollisionWith(obj,dt);
}
}
</PRE>
<!-- END CODE //-->
<P>Extensions of this class might be, for example, a huge moving gate or a large asteroid.
</P>
<H4 ALIGN="CENTER"><A NAME="Heading30"></A><FONT COLOR="#000077">The cmAbstractStaticScenery Class</FONT></H4>
<P>This class, shown in Listing 12-12, is the mother of all static scenery. Scenery is the type of object that does not interact with the rest of world. Its only purpose in life is to make things look prettier. No object should be interested in collisions with scenery, and no scenery should be interested in collisions with other objects.
</P>
<P><B>Listing 12-12</B> The abstract static scenery</P>
<!-- CODE SNIP //-->
<PRE>
abstract class cmAbstractStaticScenery extends cmAbstractStaticObject{
protected cmAbstractStaticScenery (fWorld w, fPoint3d p, fAngle3d a) {
super(w,p,a);
}
}
</PRE>
<!-- END CODE SNIP //-->
<P>Extensions of this class might be small rocks, bushes, and so on.
</P>
<H4 ALIGN="CENTER"><A NAME="Heading31"></A><FONT COLOR="#000077">The cmAbstractMovingScenery Class</FONT></H4>
<P>This class is just like the static one, but this scenery is moving. The code is shown in Listing 12-13.
</P>
<P><B>Listing 12-13</B> The abstract moving scenery</P>
<!-- CODE SNIP //-->
<PRE>
abstract class cmAbstractStaticScenery extends cmAbstractStaticObject{
protected cmAbstractStaticScenery (fWorld w, fPoint3d p, fAngle3d a) {
super(w,p,a);
}
}
</PRE>
<!-- END CODE SNIP //-->
<P>Extensions of this class might be small fragments, clouds, and so on.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="462-465.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="467-470.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -