亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch6.htm

?? Java游戲開發
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vel.y = -vel.y;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (bounce)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setVelocity(vel);<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;// Die?<BR>
&nbsp;&nbsp;else if (boundsAction == Sprite.BA_DIE) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if ((pos.x + position.width) &lt; bounds.x
||<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x &gt; bounds.width ||
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(pos.y + position.height)
&lt; bounds.y ||<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y &gt; bounds.height)
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action.set(Sprite.SA_KILL);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return action;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;// Stop (default)<BR>
&nbsp;&nbsp;else {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (pos.x&nbsp;&nbsp;&lt; bounds.x ||
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x &gt; (bounds.x + bounds.width
- position.width)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x = Math.max(bounds.x,
Math.min(pos.x,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounds.x + bounds.width
- position.width));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setVelocity(new Point(0, 0));
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (pos.y&nbsp;&nbsp;&lt; bounds.y ||
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y &gt; (bounds.y + bounds.height
- position.height)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y = Math.max(bounds.y,
Math.min(pos.y,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounds.y + bounds.height
- position.height));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setVelocity(new Point(0, 0));
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;setPosition(pos);<BR>
<BR>
&nbsp;&nbsp;return action;</FONT></TT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">}</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
The <TT><FONT FACE="Courier">update</FONT></TT> method handles
the task of updating the animation frame and position of the sprite.
<TT><FONT FACE="Courier">update</FONT></TT> begins by creating
an empty set of action flags, which are stored in a <TT><FONT FACE="Courier">BitSet</FONT></TT>
object. The animation frame is then updated with a call to <TT><FONT FACE="Courier">incFrame</FONT></TT>.
The position of the sprite is updated by translating the position
rectangle based on the velocity. You can think of the position
rectangle as sliding a distance determined by the velocity.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
The <TT><FONT FACE="Courier">BitSet</FONT></TT> class is included in the standard Java package <TT><FONT FACE="Courier">java.util</FONT></TT> and provides a means of maintaining a set of boolean flags or bit fields.
</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>
The rest of the code in <TT><FONT FACE="Courier">update</FONT></TT>
is devoted to handling the various bounds actions. The first bounds
action flag, <TT><FONT FACE="Courier">BA_WRAP</FONT></TT>, causes
the sprite to wrap around to the other side of the bounds rectangle.
This flag is useful in an Asteroids type game, in which the asteroids
float off one side of the screen and back from the other. The
<TT><FONT FACE="Courier">BA_BOUncE</FONT></TT> flag causes the
sprite to bounce if it encounters a boundary. This flag is useful
in a Breakout or Pong type game, in which a ball bounces off the
edges of the screen. The <TT><FONT FACE="Courier">BA_DIE</FONT></TT>
flag causes the sprite to die if it encounters a boundary. This
flag is useful for sprites such as bullets, which you often want
destroyed when they travel beyond the edges of the screen. Finally,
the default flag, <TT><FONT FACE="Courier">BA_STOP</FONT></TT>,
causes the sprite to stop when it encounters a boundary.
<P>
Notice that <TT><FONT FACE="Courier">update</FONT></TT> finishes
by returning a set of sprite action flags, <TT><FONT FACE="Courier">action</FONT></TT>.
Derived sprite classes can return different sprite action values
to trigger different actions. Judging by its size, it's not hard
to figure out that the <TT><FONT FACE="Courier">update</FONT></TT>
method is itself the bulk of the code in the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class. This is logical though, because the <TT><FONT FACE="Courier">update</FONT></TT>
method is where all the action takes place; <TT><FONT FACE="Courier">update</FONT></TT>
handles all the details of updating the animation frame and position
of the sprite, along with carrying out different bounds actions.
<P>
Another important method in the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class is <TT><FONT FACE="Courier">draw</FONT></TT>, whose source
code is as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public void draw(Graphics g) {<BR>
&nbsp;&nbsp;// Draw the current frame<BR>
&nbsp;&nbsp;if (!hidden)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;g.drawImage(image[frame], position.x,
position.y, component);<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
After wading through the <TT><FONT FACE="Courier">update</FONT></TT>
method, the <TT><FONT FACE="Courier">draw</FONT></TT> method looks
like a piece of cake! It simply uses the <TT><FONT FACE="Courier">drawImage</FONT></TT>
method to draw the current sprite frame image to the <TT><FONT FACE="Courier">Graphics</FONT></TT>
object that is passed in. Notice that the <TT><FONT FACE="Courier">drawImage</FONT></TT>
method requires the image, XY position, and component (<TT><FONT FACE="Courier">ImageObserver</FONT></TT>)
to carry this out.
<P>
The <TT><FONT FACE="Courier">addSprite</FONT></TT> method is used
to add sprites to the sprite list:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected Sprite addSprite(BitSet action)
{<BR>
&nbsp;&nbsp;return null;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The sprite list contains all the sprites and is maintained by
the <TT><FONT FACE="Courier">SpriteVector</FONT></TT> class, which
you'll learn about a little later today. The reason for having
the <TT><FONT FACE="Courier">addSprite</FONT></TT> method is that
a sprite occasionally needs to create and add another sprite to
the sprite list. However, there is a big problem in that an individual
sprite doesn't know anything about the sprite list. To get around
this problem, you use sprite actions. Sprite actions work like
this: A sprite notifies the sprite list that it wants to add a
sprite by setting the <TT><FONT FACE="Courier">SA_ADDSPRITE</FONT></TT>
action flag in the set of action flags returned by the <TT><FONT FACE="Courier">update</FONT></TT>
method. The sprite list, in turn, calls the <TT><FONT FACE="Courier">addSprite</FONT></TT>
method for the sprite and adds the new sprite to the list. I know
this sounds like a convoluted way to handle sprite creation, but
it actually works quite well and fits in with the object-oriented
design of the sprite classes. The remaining question, then, is
why does this implementation of <TT><FONT FACE="Courier">addSprite</FONT></TT>
return <TT><FONT FACE="Courier">null</FONT></TT>? The answer is
that it is up to derived sprites to provide a specific implementation
for <TT><FONT FACE="Courier">addSprite</FONT></TT>. Knowing this,
you could make <TT><FONT FACE="Courier">addSprite</FONT></TT>
abstract, but then you would be forced to derive a new sprite
class any time you want to create a sprite.
<P>
The last method in <TT><FONT FACE="Courier">Sprite</FONT></TT>
is <TT><FONT FACE="Courier">testCollision</FONT></TT>, which is
used to check for collisions between sprites:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected boolean testCollision(Sprite
test) {<BR>
&nbsp;&nbsp;// Check for collision with another sprite<BR>
&nbsp;&nbsp;if (test != this)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return collision.intersects(test.getCollision());
<BR>
&nbsp;&nbsp;return false;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The sprite to test for collision is passed in the <TT><FONT FACE="Courier">test</FONT></TT>
parameter. The test simply involves checking to see whether the
collision rectangles intersect. If so, <TT><FONT FACE="Courier">testCollision</FONT></TT>
returns <TT><FONT FACE="Courier">true</FONT></TT>. <TT><FONT FACE="Courier">testCollision</FONT></TT>
isn't all that useful within the context of a single sprite, but
it is very handy when you put together the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class, which you are going to do next.
<H3><A NAME="TheSpriteVectorClass"><B>The </B><TT><B><FONT SIZE=4 FACE="Courier">SpriteVector</FONT></B></TT><B><FONT SIZE=4>
Class</FONT></B></A></H3>
<P>
At this point, you have a <TT><FONT FACE="Courier">Sprite</FONT></TT>
class with some pretty impressive features, but you don't really
have any way to manage it. Of course, you could go ahead and create
an applet with some <TT><FONT FACE="Courier">Sprite</FONT></TT>
objects, but how would they be able to interact with each other?
The answer to this question is the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class, which handles all the details of maintaining a list of
sprites and the handling of interactions between them.
<P>
The <TT><FONT FACE="Courier">SpriteVector</FONT></TT> class is
derived from the <TT><FONT FACE="Courier">Vector</FONT></TT> class,
which is a standard class provided in the <TT><FONT FACE="Courier">java.util</FONT></TT>
package. The <TT><FONT FACE="Courier">Vector</FONT></TT> class
models a growable array of objects. In this case, the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class is used as a container for a growable array of <TT><FONT FACE="Courier">Sprite</FONT></TT>
objects.
<P>
The <TT><FONT FACE="Courier">SpriteVector</FONT></TT> class has
only one member variable, <TT><FONT FACE="Courier">background</FONT></TT>,
which is a <TT><FONT FACE="Courier">Background</FONT></TT> object:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected Background background;</FONT></TT>
</BLOCKQUOTE>
<P>
This <TT><FONT FACE="Courier">Background</FONT></TT> object represents
the background upon which the sprites appear. It is initialized
in the constructor for <TT><FONT FACE="Courier">SpriteVector</FONT></TT>,
like this:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public SpriteVector(Background back)
{<BR>
&nbsp;&nbsp;super(50, 10);<BR>
&nbsp;&nbsp;background = back;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The constructor for <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
simply takes a <TT><FONT FACE="Courier">Background</FONT></TT>
object as its only parameter. You'll learn about the <TT><FONT FACE="Courier">Background</FONT></TT>
class a little later today. Notice that the constructor for <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
calls the <TT><FONT FACE="Courier">Vector</FONT></TT> parent class
constructor and sets the default storage capacity (<TT><FONT FACE="Courier">50</FONT></TT>)
and amount to increment the storage capacity (<TT><FONT FACE="Courier">10</FONT></TT>)
if the vector needs to grow.
<P>
<TT><FONT FACE="Courier">SpriteVector</FONT></TT> contains the
following two access methods for getting and setting the <TT><FONT FACE="Courier">background</FONT></TT>
member variable:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public Background getBackground() {<BR>
&nbsp;&nbsp;return background;<BR>
}<BR>
<BR>
public void setBackground(Background back) {<BR>
&nbsp;&nbsp;background = back;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
These methods are useful in games in which the background changes
based on the level of the game. To change the background, you
simply call <TT><FONT FACE="Courier">setBackground</FONT></TT>
and pass in the new <TT><FONT FACE="Courier">Background</FONT></TT>
object.
<P>
The <TT><FONT FACE="Courier">getEmptyPosition</FONT></TT> method
is used by the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class to help position new sprites. Listing 6.2 contains the source
code for <TT><FONT FACE="Courier">getEmptyPosition</FONT></TT>.
<HR>
<BLOCKQUOTE>
<B>Listing 6.2. The </B><TT><B><FONT FACE="Courier">SpriteVector</FONT></B></TT><B>
class's </B><TT><B><FONT FACE="Courier">getEmptyPosition</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public Point getEmptyPosition(Dimension
sSize) {<BR>
&nbsp;&nbsp;Rectangle pos = new Rectangle(0, 0, sSize.width, sSize.height);
<BR>
&nbsp;&nbsp;Random&nbsp;&nbsp;&nbsp;&nbsp;rand = new Random(System.currentTimeMillis());
<BR>
&nbsp;&nbsp;boolean&nbsp;&nbsp;&nbsp;empty = false;<BR>
&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numTries
= 0;<BR>
<BR>
&nbsp;&nbsp;// Look for an empty position<BR>
&nbsp;&nbsp;while (!empty &amp;&amp; numTries++ &lt; 50) {<BR>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产欧美综合在线观看第十页| 制服丝袜一区二区三区| 亚洲成人你懂的| 日韩理论片网站| 久久人人爽爽爽人久久久| 日韩视频一区二区在线观看| 欧美日韩在线免费视频| 91影视在线播放| 成人性视频免费网站| 国产激情一区二区三区| 一区二区三区在线看| 国产在线视频一区二区| 日韩有码一区二区三区| 亚洲444eee在线观看| 一区二区三区四区在线播放| 中文字幕免费观看一区| 国产拍揄自揄精品视频麻豆| 久久久久亚洲综合| 国产午夜精品一区二区三区视频| 久久网站最新地址| 国产三级精品三级在线专区| 久久精品视频一区二区三区| 欧美国产日韩精品免费观看| 中文字幕av免费专区久久| 国产精品久久综合| 亚洲国产欧美在线| 激情国产一区二区| 欧美日韩免费观看一区三区| 欧美日韩大陆一区二区| 日韩欧美在线网站| 亚洲国产成人在线| 亚洲一区二区视频在线观看| 久久se精品一区二区| 成人蜜臀av电影| 欧美日韩成人综合| 久久男人中文字幕资源站| 亚洲日本va午夜在线影院| 亚洲国产另类精品专区| 国产精品一线二线三线精华| 99视频在线精品| 欧美大片一区二区| 亚洲精品大片www| 精品中文字幕一区二区小辣椒 | 亚洲日本欧美天堂| 青青青伊人色综合久久| 91亚洲精品一区二区乱码| 欧美电影免费观看高清完整版在线观看| 日本一区二区三区免费乱视频| 午夜a成v人精品| 一本大道av伊人久久综合| 精品国产伦一区二区三区免费| 亚洲欧美日韩一区二区| 在线视频中文字幕一区二区| 国产夜色精品一区二区av| 亚洲高清不卡在线观看| 91在线精品一区二区| 中文字幕精品一区二区三区精品| 久久99精品国产91久久来源| 精品国产亚洲在线| 亚洲精品中文在线观看| 国产·精品毛片| 久久久久久免费毛片精品| 美女视频网站久久| 91精品久久久久久久91蜜桃| 亚洲成a人片在线观看中文| 欧洲视频一区二区| 成人黄色片在线观看| 国产视频一区二区在线观看| 三级不卡在线观看| 亚洲自拍偷拍九九九| 成人精品免费网站| 国产精品久久久久久福利一牛影视| 国产不卡在线播放| 国产精品拍天天在线| 播五月开心婷婷综合| 成人欧美一区二区三区黑人麻豆 | 蜜桃视频一区二区三区| 日韩欧美另类在线| 国产成人精品影视| 亚洲伦在线观看| 制服丝袜成人动漫| 国产成人在线观看免费网站| 在线电影欧美成精品| 26uuu精品一区二区在线观看| 激情综合色综合久久| 日本一区二区综合亚洲| 色综合久久九月婷婷色综合| 亚洲成人黄色小说| 国产三级久久久| 精品视频资源站| 国产成人高清在线| 日本中文字幕一区二区有限公司| 国产校园另类小说区| 欧美日本视频在线| 99精品国产视频| 精品综合久久久久久8888| 一区二区在线观看av| 久久久久久久久岛国免费| 欧美精品777| 国产精品对白交换视频| 日本不卡的三区四区五区| 国产精品久99| 久久日一线二线三线suv| 欧美少妇一区二区| voyeur盗摄精品| 国内精品在线播放| 日本91福利区| 亚洲电影在线播放| 一区二区三区在线观看国产| 国产欧美日韩视频在线观看| 精品国产一区二区三区不卡| 91精品国产福利| 国产午夜亚洲精品理论片色戒| 欧美一区二区视频在线观看2020 | 成人国产精品免费观看视频| 婷婷国产v国产偷v亚洲高清| 亚洲欧美日韩人成在线播放| 国产精品久久久久影院| 国产日韩欧美在线一区| 久久先锋资源网| 久久久99精品免费观看不卡| 久久久精品欧美丰满| 国产亚洲欧美日韩俺去了| 久久综合九色综合久久久精品综合| 欧美成人性福生活免费看| 国产亚洲欧美日韩在线一区| 日本一区免费视频| 一区二区三区中文在线| 成人av在线看| 欧美午夜影院一区| 精品国产一区久久| 一区在线观看免费| 天天综合色天天综合色h| 免费观看在线综合色| 丁香婷婷综合网| 色屁屁一区二区| 日韩三级免费观看| 国产精品免费av| 亚洲成人动漫av| 国产成人免费视频| 欧美日韩成人综合在线一区二区| 欧美精品一区二区三区视频| 亚洲精品免费播放| 国产一区二区免费视频| 日韩一区二区免费高清| 欧美国产欧美综合| 日日摸夜夜添夜夜添国产精品| 成人午夜激情片| 日韩精品自拍偷拍| 亚洲一二三区在线观看| 成人国产精品视频| 亚洲精品一线二线三线无人区| 日韩制服丝袜av| 亚洲婷婷在线视频| 老司机精品视频线观看86| 在线观看日韩一区| 久久亚洲影视婷婷| 免费在线看成人av| 欧美日韩一区在线| **网站欧美大片在线观看| 国产99久久久国产精品潘金| 欧美日本一区二区三区四区| 亚洲人快播电影网| 成人午夜激情影院| 日本一区二区高清| 国产传媒一区在线| 午夜视黄欧洲亚洲| 欧美日韩精品系列| 亚洲一区二区三区四区在线 | 香蕉影视欧美成人| 欧美日韩大陆一区二区| 午夜欧美在线一二页| 91女人视频在线观看| 亚洲欧美综合另类在线卡通| 99久久久国产精品免费蜜臀| 亚洲视频在线一区观看| 99精品国产99久久久久久白柏| 国产精品伦一区二区三级视频| 色综合色狠狠综合色| 亚洲视频一区在线| 在线观看欧美黄色| 男女视频一区二区| 久久久国产午夜精品| 成人福利视频在线| 亚洲电影在线播放| 久久久综合激的五月天| 91麻豆自制传媒国产之光| 日韩中文字幕区一区有砖一区| 精品少妇一区二区三区在线视频| 粉嫩蜜臀av国产精品网站| 亚洲久本草在线中文字幕| 日韩欧美中文一区二区| 久久综合九色欧美综合狠狠| 久久综合九色欧美综合狠狠 | 成年人国产精品| 香蕉乱码成人久久天堂爱免费| xvideos.蜜桃一区二区| 91福利社在线观看| 国产成人一区二区精品非洲| 午夜精品一区二区三区电影天堂 |