⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 458-461.html

📁 java game programming e-book
💻 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,&nbsp;Macmillan Computer Publishing
    <br>
    <b>ISBN:</b>&nbsp;1571690433<b>&nbsp;&nbsp;&nbsp;Pub Date:</b>&nbsp;11/01/96</font>&nbsp;&nbsp;
</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=458-461//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="455-458.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="462-465.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Using a Template to Simplify Designing New Objects</FONT></H4>
<P>To make the designing of new objects easier, I have put together a template, shown in Listing 12-7, with the basic methods that can be overridden.
</P>
<P><B>Listing 12-7</B> The template</P>
<!-- CODE //-->
<PRE>
class MyCoolObject extends fObject&#123;
   /**
    * Constructor.
    */
   MyCoolObject(fWorld world)&#123;
      super(world,new fPoint3d(0,0,0),new fAngle3d(0,0,0));
      usePolyhedronInstance(new
fPolyhedronInstance(ourDefaultPolyhedron,ourScale));

      //--
      //-- insert code here
      //--
   &#125;
   /**
    * Updates this object by dt seconds.
    */
   public void update (double dt) &#123;
      super.update(dt);

      //--
      //-- insert code here
      //--
   &#125;

   /**
    * The core will ask this object if it is interested of
    * collision with some other object. Return true if the object
    * is interested otherwise let the base class decide.
    */
   public boolean interestedOfCollisionWith (fObject obj) &#123;
      //--
      //-- insert code here, example
      //--     if(obj instanceof MyCoolClass) return true;
      //--

      return super.interestedOfCollisionWith(obj);
   &#125;
   /**
 * Handles a collision with a object. Returns false if there
     * is no point in checking more collisions. I.e. the object is dead.
    */
   protected boolean handleCollisionWith (fObject obj,double dt) &#123;
      //--
      //-- insert code here, example
      //--     if(obj instanceof AtomicBomb) &#123;die();return false;&#125;
      //--

      return super.handleCollisionWith(obj,dt);
   &#125;
   /**
    * Kills this object.
    */
   protected void die () &#123;
      super.die();

      //--
      //-- insert code here, example
      //--   largeExplosion();

   &#125;
   /**
    * Inititates this class by loading the static parameters from
    * the applet.
    */
   public static void initiateClass (Applet app) &#123;
      try&#123;
         //-- load the default polyhedron for all bouncing boxes
         //-- this MUST be done in all non-abstract classes
         String polyfile=
           app.getParameter("MyCoolObject_ourDefaultPolyhedron");
         URL url=new URL(app.getCodeBase(),polyfile);
         InputStream is=url.openStream();
         ourDefaultPolyhedron=new fConvexPolyhedron(is);
      &#125; catch(Exception e) &#123;
         e.printStackTrace();
      &#125;
      //-- the scaling of the polyhedron
      double xscale=new
Double(app.getParameter("MyCoolObject_scalex")).doubleValue();
      double yscale=new
Double(app.getParameter("MyCoolObject_scaley")).doubleValue();
      double zscale=new
Double(app.getParameter("MyCoolObject_scalez")).doubleValue();
      ourScale=new fPoint3d(xscale,yscale,zscale);

      //--
      //-- load your other constants here
      //--
   &#125;

   //-- class "constants"
   protected static fPolyhedron ourDefaultPolyhedron;
   protected static fPoint3d ourScale;
   //--
   //-- insert your static stuff here
   //--
&#125;
</PRE>
<!-- END CODE //-->

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Things to Watch out For</B></FONT>
<DL>
<DD><B>1.</B>&nbsp;&nbsp;When overriding a method, copy it from the template or you might misspell it.
<DD><B>2.</B>&nbsp;&nbsp;Always be sure to initiate all classes in yourWorld.initiateClasses().
<DD><B>3.</B>&nbsp;&nbsp;Always make sure to add the new parameters to the HTML file when you create a new class.
<DD><B>4.</B>&nbsp;&nbsp;Make sure the parameters are loaded properly and that they are not misspelled, or they&#146;ll be null or zero and possibly crash the core.
<DD><B>5.</B>&nbsp;&nbsp;When using getPosition(), getAngle(), getdPosition(), or getdAngle(), you will receive a clone of that object. You have to call setPosition(), etc., in order to really change the state of the object; otherwise you will only change the clone.
<DD><B>6.</B>&nbsp;&nbsp;Do not forget to call the method usePolyhedronInstance(..) in all nonabstract classes or the object will not have a 3D model.
<DD><B>7.</B>&nbsp;&nbsp;Be sure you have checked points 1, 2, 3, 4, 5, 6, and 7.
</DL>
</TABLE>

<H3><A NAME="Heading23"></A><FONT COLOR="#000077">Creating the Game Layer</FONT></H3>
<P>In this section, a layer of classes called the game layer will be developed. This layer of classes will turn the general App3Dcore into a game engine. This layer also breaks the intimate contact with the core. Figure 12-5 shows an abstract representation of how the classes are extended layer by layer.
</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/12-05.jpg',594,405 )"><IMG SRC="images/12-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/12-05.jpg',594,405)"><FONT COLOR="#000077"><B>Figure 12-5</B></FONT></A>&nbsp;&nbsp;Extending the App3Dcore<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="455-458.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="462-465.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -