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

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

?? ch6.htm

?? 有關于游戲開發的教程我閱讀后感覺不錯所以就拿出來與大家共享。
?? 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一区二区三区免费野_久草精品视频
亚洲精品国产a| 麻豆精品视频在线观看免费| 国产资源在线一区| 欧美日本国产一区| 亚洲一级片在线观看| 91免费看视频| 成人欧美一区二区三区1314| 蜜桃久久久久久久| 日韩片之四级片| 男女激情视频一区| 欧美一区二区免费观在线| 午夜精品成人在线视频| 欧美私人免费视频| 国产日韩av一区| 国产一区二区精品久久99 | 国产一区二区三区免费播放| 日韩你懂的在线观看| 久久国产人妖系列| 久久嫩草精品久久久久| 国产精品2024| 中文字幕一区二区三区色视频| 99视频在线精品| 亚洲综合一区在线| 3atv在线一区二区三区| 日韩黄色在线观看| 精品国产乱码久久久久久浪潮| 性感美女久久精品| 日韩美一区二区三区| 国产一区在线观看视频| 中文字幕一区二区三中文字幕 | 成人黄动漫网站免费app| 国产精品国产a| 欧美日韩精品三区| 日本一区中文字幕| 久久久久久久久久看片| av在线不卡电影| 最新日韩av在线| 欧美日韩免费视频| 国产酒店精品激情| 一区二区三区美女| 久久久午夜精品| 色偷偷88欧美精品久久久| 亚洲韩国一区二区三区| 久久久精品影视| 欧美在线观看你懂的| 韩国女主播成人在线观看| 综合激情成人伊人| 91精品国产色综合久久不卡电影 | 欧美精品日韩精品| 极品少妇xxxx精品少妇| 亚洲欧美区自拍先锋| 日韩一区二区免费视频| 国产精品亚洲一区二区三区在线 | 亚洲精品一二三| 精品久久久久久久人人人人传媒 | 91首页免费视频| 蜜桃av噜噜一区| 国产欧美在线观看一区| 欧美亚州韩日在线看免费版国语版| 蜜桃在线一区二区三区| 亚洲人精品午夜| 精品国产一区二区亚洲人成毛片| 91浏览器打开| 国产麻豆精品久久一二三| 亚洲午夜久久久| 国产精品区一区二区三区| 91精品国产aⅴ一区二区| 成人黄色777网| 国产中文字幕一区| 亚洲一区二区不卡免费| 国产精品免费视频观看| 欧美大片拔萝卜| 欧美日韩黄色影视| 色94色欧美sute亚洲线路一ni| 国产精品一区二区在线看| 日本大胆欧美人术艺术动态| 亚洲麻豆国产自偷在线| 欧美激情中文字幕一区二区| 日韩欧美电影在线| 欧美一区二区三区播放老司机| av爱爱亚洲一区| 成人黄色在线看| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 久久综合九色综合欧美就去吻| 欧美优质美女网站| 91欧美一区二区| 99久久夜色精品国产网站| 婷婷综合另类小说色区| 精品sm在线观看| 久久这里都是精品| 国产午夜精品一区二区三区嫩草| 欧美大片在线观看一区二区| 精品国产一二三| 国产三级精品在线| 中文字幕av免费专区久久| 中文字幕一区二区在线观看| 亚洲精品久久7777| 日韩av高清在线观看| 久久成人18免费观看| 国产成人aaa| 色综合久久综合网欧美综合网 | 日韩欧美在线影院| 久久久久久久久久久久久夜| 国产精品青草久久| 亚洲国产另类av| 久久精品国产精品亚洲精品| 国产激情91久久精品导航| 一本大道av伊人久久综合| 欧美撒尿777hd撒尿| 欧美成人艳星乳罩| 国产精品视频免费看| 亚洲一区视频在线| 精品在线播放免费| 成人av网在线| 在线成人免费视频| 国产欧美日韩精品在线| 亚洲乱码中文字幕| 麻豆精品久久精品色综合| 国产高清一区日本| 欧美日韩国产在线播放网站| 久久久久久久精| 亚洲成人精品一区二区| 国产成人h网站| 制服丝袜日韩国产| 亚洲欧美中日韩| 精东粉嫩av免费一区二区三区| 91偷拍与自偷拍精品| 精品美女一区二区三区| 亚洲一区二区三区四区在线观看 | 91福利在线观看| 久久久久九九视频| 午夜精品福利一区二区三区蜜桃| 风流少妇一区二区| 日韩一区二区不卡| 亚洲黄网站在线观看| 国产激情一区二区三区| 91精品国产色综合久久ai换脸| 中文天堂在线一区| 日韩国产精品久久久久久亚洲| 成人av资源下载| 4438x成人网最大色成网站| 亚洲视频精选在线| 黄色成人免费在线| 91极品视觉盛宴| 中文字幕在线不卡一区| 日本欧美加勒比视频| 91视频91自| 久久一区二区三区四区| 视频一区二区国产| 91在线视频播放| 国产亚洲一区字幕| 日本欧美肥老太交大片| 色综合久久久久综合体桃花网| xfplay精品久久| 午夜精品福利一区二区三区av| 北条麻妃一区二区三区| 亚洲精品在线网站| 天堂久久久久va久久久久| av资源网一区| 亚洲欧美自拍偷拍色图| 国产专区欧美精品| 91精品国产色综合久久不卡电影| 亚洲免费色视频| 91麻豆产精品久久久久久 | 884aa四虎影成人精品一区| 亚洲色大成网站www久久九九| 国产成人h网站| 精品久久一区二区三区| 日韩精品一二区| 欧美午夜精品一区二区蜜桃| 国产精品情趣视频| 国产成a人亚洲| 2023国产精华国产精品| 日韩精品电影一区亚洲| 欧美日韩在线精品一区二区三区激情 | 欧美日本国产视频| 亚洲一二三区不卡| 欧美综合天天夜夜久久| 精品美女在线播放| 国产白丝精品91爽爽久久| 久久一区二区三区国产精品| 捆绑紧缚一区二区三区视频| 在线视频国内一区二区| 五月天中文字幕一区二区| 日本精品一区二区三区高清| 成人免费在线播放视频| 91精彩视频在线观看| 亚洲综合在线第一页| 在线观看欧美日本| 亚洲国产精品视频| 日韩一区二区三区四区五区六区| 五月综合激情日本mⅴ| 欧美日韩一区成人| 三级久久三级久久| 久久免费偷拍视频| 成人黄色小视频| 亚洲欧洲av色图| 91麻豆精品国产自产在线观看一区 | 国产成人在线免费| 一区二区三区四区不卡视频 |