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

📄 575-577.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 the JAVAroids Game</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=13//-->
<!--PAGES=575-577//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="570-575.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="578-588.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading26"></A><FONT COLOR="#000077">The Effect Manager</FONT></H4>
<P>For the effect manager, we&#146;re going to depart from our policy of avoiding object instantiations during game play. This is because the number of explosions is tricky to judge beforehand, so it&#146;s easier to keep a Vector of explosions, and insert new explosions when the other manager classes detect collisions. Thus, EffManager provides the public methods addShipExplosion(), addEnemyExplosion(), and addAstExplosion(), which the other managers can invoke. These methods create new Explosion objects that are added to the explosions Vector.
</P>
<P>Listing 13-17 contains the complete effect manager class.</P>
<P><B>Listing 13-17</B> EffManager class</P>
<!-- CODE //-->
<PRE>
/////////////////////////////////////////////////////////////////
//
// EffManager: handles effects, such as explosions and sound
//
/////////////////////////////////////////////////////////////////

public class EffManager extends Object &#123;

  Vector explosions;
  AudioClip expsound;

/////////////////////////////////////////////////////////////////
// EffManager constructor
/////////////////////////////////////////////////////////////////

  public EffManager(AudioClip expsound) &#123;
    explosions = new Vector();
    this.expsound = expsound;
  &#125;

/////////////////////////////////////////////////////////////////
// make a ship explosion at x,y
/////////////////////////////////////////////////////////////////

  public void addShipExplosion(int x,int y) &#123;
    Explosion exp = new Explosion(Color.red,x,y,20);
    Explosion exp1 = new Explosion(Color.yellow,x&#43;2,y&#43;2,25);
    explosions.addElement(exp);
    explosions.addElement(exp1);
    if (expsound != null) &#123;
      expsound.play();
    &#125;
  &#125;

/////////////////////////////////////////////////////////////////
// make an asteroid explosion at x,y
/////////////////////////////////////////////////////////////////
  public void addAstExplosion(int x,int y) &#123;
    Explosion exp = new Explosion(Color.white,x,y,15);
    explosions.addElement(exp);
    if (expsound != null) &#123;
      expsound.play();
    &#125;
  &#125;

/////////////////////////////////////////////////////////////////
// make an asteroid explosion at x,y
/////////////////////////////////////////////////////////////////
  public void addEnemyExplosion(int x,int y) &#123;
    Explosion exp = new Explosion(Color.orange,x,y,15);
    explosions.addElement(exp);
    if (expsound != null) &#123;
      expsound.play();
    &#125;
  &#125;

/////////////////////////////////////////////////////////////////
// make an explosion of the given color at x,y
/////////////////////////////////////////////////////////////////
  public void addExplosion(Color c,int x, int y, int u) &#123;
    Explosion exp = new Explosion(c,x,y,u);
    explosions.addElement(exp);
    if (expsound != null) &#123;
      expsound.play();
    &#125;
  &#125;

/////////////////////////////////////////////////////////////////
// paint the explosions by stepping through the
//   explosions Vector
/////////////////////////////////////////////////////////////////
  public void paint (Graphics g) &#123;
     Enumeration e;
      e = explosions.elements();
      while (e.hasMoreElements()) &#123;
       Sprite exp = (Sprite) e.nextElement();
       exp.paint(g);
      &#125;
   &#125;

/////////////////////////////////////////////////////////////////
// update the explosions by stepping through the
//   explosions Vector
/////////////////////////////////////////////////////////////////
  public void update() &#123;
    Enumeration e;
    e = explosions.elements();
    while (e.hasMoreElements()) &#123;
      Explosion exp = (Explosion) e.nextElement();
      exp.update();
      // if the explosion's finished, remove it from vector
      if (exp.isDone()) &#123;
       explosions.removeElement(exp);
      &#125;
    &#125;
  &#125;
&#125;
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="570-575.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="578-588.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</BODY>

⌨️ 快捷键说明

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