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

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

?? ch6.htm

?? Java游戲開發
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
&nbsp;&nbsp;&nbsp;&nbsp;// Get a random position<BR>
&nbsp;&nbsp;&nbsp;&nbsp;pos.x = Math.abs(rand.nextInt() %<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background.getSize().width);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;pos.y = Math.abs(rand.nextInt() %<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background.getSize().height);
<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Iterate through sprites, checking
if position is empty<BR>
&nbsp;&nbsp;&nbsp;&nbsp;boolean collision = false;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; size(); i++) {
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rectangle testPos = ((Sprite)elementAt(i)).getPosition();
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (pos.intersects(testPos))
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collision = true;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;empty = !collision;<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;return new Point(pos.x, pos.y);</FONT></TT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">}</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
<TT><FONT FACE="Courier">getEmptyPosition</FONT></TT> is a method
whose importance might not be readily apparent to you right now;
it is used to find an empty physical position in which to place
a new sprite in the sprite list. This doesn't mean the position
of the sprite in the list; rather, it means its physical position
on the screen. This method is very useful when you want to randomly
place multiple sprites on the screen. By using <TT><FONT FACE="Courier">getEmptyPosition</FONT></TT>,
you eliminate the possibility of placing new sprites on top of
existing sprites. For example, in an adventure game you could
randomly place scenery objects such as trees using <TT><FONT FACE="Courier">getEmptyPosition</FONT></TT>
to make sure none of them overlap each other.
<P>
The <TT><FONT FACE="Courier">isPointInside</FONT></TT> method
in <TT><FONT FACE="Courier">SpriteVector</FONT></TT> is similar
to the version of <TT><FONT FACE="Courier">isPointInside</FONT></TT>
in <TT><FONT FACE="Courier">Sprite</FONT></TT>, except it goes
through the entire sprite list checking each sprite. Check out
the source code for it:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">Sprite isPointInside(Point pt) {<BR>
&nbsp;&nbsp;// Iterate backward through the sprites, testing each
<BR>
&nbsp;&nbsp;for (int i = (size() - 1); i &gt;= 0; i--) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Sprite s = (Sprite)elementAt(i);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (s.isPointInside(pt))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return s;<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;return null;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
If the point passed in the parameter <TT><FONT FACE="Courier">pt</FONT></TT>
lies in a sprite, <TT><FONT FACE="Courier">isPointInside</FONT></TT>
returns the sprite. Notice that the sprite list is searched in
reverse, meaning that the last sprite is checked before the first.
The sprites are searched in this order for a very important reason:
Z-order. The sprites are stored in the sprite list sorted in ascending
Z-order, which specifies their depth on the screen. Therefore,
sprites near the beginning of the list are sometimes concealed
by sprites near the end of the list. If you want to check for
a point lying within a sprite, it only makes sense to check the
topmost sprites first-that is, the sprites with larger Z-order
values. If this sounds a little confusing, don't worry; you'll
learn more about Z-order later today when you get to the <TT><FONT FACE="Courier">add</FONT></TT>
method.
<P>
As in <TT><FONT FACE="Courier">Sprite</FONT></TT>, the <TT><FONT FACE="Courier">update</FONT></TT>
method is the key method in <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
because it handles updating all the sprites. Listing 6.3 contains
the source code for <TT><FONT FACE="Courier">update</FONT></TT>.
<HR>
<BLOCKQUOTE>
<B>Listing 6.3. The </B><TT><B><FONT FACE="Courier">SpriteVector</FONT></B></TT><B>
class's </B><TT><B><FONT FACE="Courier">update</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public void update() {<BR>
&nbsp;&nbsp;// Iterate through sprites, updating each<BR>
&nbsp;&nbsp;Sprite&nbsp;&nbsp;&nbsp;&nbsp;s, sHit;<BR>
&nbsp;&nbsp;Rectangle lastPos;<BR>
&nbsp;&nbsp;for (int i = 0; i &lt; size(); ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// Update the sprite<BR>
&nbsp;&nbsp;&nbsp;&nbsp;s = (Sprite)elementAt(i);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;lastPos = new Rectangle(s.getPosition().x,
s.getPosition().y,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.getPosition().width, s.getPosition().height);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;BitSet action = s.update();<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// Check for the SA_ADDSPRITE action<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (action.get(Sprite.SA_ADDSPRITE)) {
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add the sprite<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sprite sToAdd = s.addSprite(action);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (sToAdd != null) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int iAdd = add(sToAdd);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (iAdd &gt;=
0 &amp;&amp; iAdd &lt;= i)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// Check for the SA_RESTOREPOS action
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (action.get(Sprite.SA_RESTOREPOS))
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.setPosition(lastPos);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// Check for the SA_KILL action<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (action.get(Sprite.SA_KILL)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;removeElementAt(i);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// Test for collision<BR>
&nbsp;&nbsp;&nbsp;&nbsp;int iHit = testCollision(s);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (iHit &gt;= 0)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (collision(i, iHit))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.setPosition(lastPos);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;i++;<BR>
&nbsp;&nbsp;}</FONT></TT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">}</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
The <TT><FONT FACE="Courier">update</FONT></TT> method iterates
through the sprites, calling <TT><FONT FACE="Courier">Sprite</FONT></TT>'s
<TT><FONT FACE="Courier">update</FONT></TT> method on each one.
It then checks for the various sprite action flags returned by
the call to <TT><FONT FACE="Courier">update</FONT></TT>. If the
<TT><FONT FACE="Courier">SA_ADDSPRITE</FONT></TT> flag is set,
the <TT><FONT FACE="Courier">addSprite</FONT></TT> method is called
on the sprite and the returned sprite is added to the list. If
the <TT><FONT FACE="Courier">SA_RESTOREPOS</FONT></TT> flag is
set, the sprite position is set to the position of the sprite
prior to being updated. If the <TT><FONT FACE="Courier">SA_KILL</FONT></TT>
flag is set, the sprite is removed from the sprite list. Finally,
<TT><FONT FACE="Courier">testCollision</FONT></TT> is called to
see whether a collision has occurred between sprites. You get
the whole scoop on <TT><FONT FACE="Courier">testCollision</FONT></TT>
in this section. If a collision has occurred, the old position
of the collided sprite is restored and the <TT><FONT FACE="Courier">collision</FONT></TT>
method is called.
<P>
The <TT><FONT FACE="Courier">collision</FONT></TT> method is used
to handle collisions between two sprites:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected boolean collision(int i, int
iHit) {<BR>
&nbsp;&nbsp;// Swap velocities (bounce)<BR>
&nbsp;&nbsp;Sprite s = (Sprite)elementAt(i);<BR>
&nbsp;&nbsp;Sprite sHit = (Sprite)elementAt(iHit);<BR>
&nbsp;&nbsp;Point swap = s.getVelocity();<BR>
&nbsp;&nbsp;s.setVelocity(sHit.getVelocity());<BR>
&nbsp;&nbsp;sHit.setVelocity(swap);<BR>
&nbsp;&nbsp;return true;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The <TT><FONT FACE="Courier">collision</FONT></TT> method is responsible
for handling any actions that result from a collision between
sprites. The action in this case is to simply swap the velocities
of the collided <TT><FONT FACE="Courier">Sprite</FONT></TT> objects,
which results in a bouncing effect. This method is where you provide
specific collision actions in derived sprites. For example, in
a space game, you might want alien sprites to explode upon collision
with a meteor sprite.
<P>
The <TT><FONT FACE="Courier">testCollision</FONT></TT> method
is used to test for collisions between a sprite and the rest of
the sprites in the sprite list:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected int testCollision(Sprite test)
{<BR>
&nbsp;&nbsp;// Check for collision with other sprites<BR>
&nbsp;&nbsp;Sprite&nbsp;&nbsp;s;<BR>
&nbsp;&nbsp;for (int i = 0; i &lt; size(); i++)<BR>
&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;s = (Sprite)elementAt(i);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (s == test)&nbsp;&nbsp;// don't check
itself<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (test.testCollision(s))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return i;<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;return -1;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The sprite to be tested is passed in the <TT><FONT FACE="Courier">test</FONT></TT>
parameter. The sprites are then iterated through and the <TT><FONT FACE="Courier">testCollision</FONT></TT>
method in <TT><FONT FACE="Courier">Sprite</FONT></TT> is called
for each. Notice that <TT><FONT FACE="Courier">testCollision</FONT></TT>
isn't called on the test sprite if the iteration refers to the
same sprite. To understand the significance of this code, consider
the effect of passing <TT><FONT FACE="Courier">testCollision</FONT></TT>
the same sprite on which the method is being called; you would
be checking to see whether a sprite was colliding with itself,
which would always return true. If a collision is detected, the
<TT><FONT FACE="Courier">Sprite</FONT></TT> object that has been
hit is returned from <TT><FONT FACE="Courier">testCollision</FONT></TT>.
<P>
The <TT><FONT FACE="Courier">draw</FONT></TT> method handles drawing
the background, as well as drawing all the sprites:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public void draw(Graphics g) {<BR>
&nbsp;&nbsp;// Draw the background<BR>
&nbsp;&nbsp;background.draw(g);<BR>
<BR>
&nbsp;&nbsp;// Iterate through sprites, drawing each<BR>
&nbsp;&nbsp;for (int i = 0; i &lt; size(); i++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;((Sprite)elementAt(i)).draw(g);<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The background is drawn with a simple call to the <TT><FONT FACE="Courier">draw</FONT></TT>
method of the <TT><FONT FACE="Courier">Background</FONT></TT>
object. The sprites are then drawn by iterating through the sprite
list and calling the <TT><FONT FACE="Courier">draw</FONT></TT>
method for each.
<P>
The <TT><FONT FACE="Courier">add</FONT></TT> method is probably
the trickiest method in the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class. Listing 6.4 contains the source code for <TT><FONT FACE="Courier">add</FONT></TT>.
<HR>
<BLOCKQUOTE>
<B>Listing 6.4. The </B><TT><B><FONT FACE="Courier">SpriteVector</FONT></B></TT><B>
class's </B><TT><B><FONT FACE="Courier">add</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public int add(Sprite s) {<BR>
&nbsp;&nbsp;// Use a binary search to find the right location
to insert the<BR>
&nbsp;&nbsp;// new sprite (based on z-order)<BR>
&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;l = 0, r = size(), i = 0;<BR>
&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;z = s.getZOrder(),<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zTest = z + 1;
<BR>
&nbsp;&nbsp;while (r &gt; l) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;i = (l + r) / 2;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;zTest = ((Sprite)elementAt(i)).

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品自拍毛片| 亚洲欧美日本韩国| 精品综合久久久久久8888| 日韩美一区二区三区| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美电影影音先锋| 免费观看久久久4p| 国产亚洲欧美激情| 色综合久久久久综合体| 亚洲成人激情自拍| 精品人在线二区三区| www.亚洲在线| 日韩在线一区二区三区| 欧美精品一区男女天堂| 成人av网站在线| 亚洲国产精品久久久久秋霞影院| 7777精品伊人久久久大香线蕉经典版下载 | 亚洲国产一区视频| 日韩欧美在线不卡| 成人国产精品免费网站| 日韩国产欧美一区二区三区| 国产精品青草综合久久久久99| 在线看国产一区| 国产高清不卡一区| 午夜精品福利一区二区三区蜜桃| 久久亚洲精精品中文字幕早川悠里 | 亚洲欧美区自拍先锋| 久久网这里都是精品| 91精品国产色综合久久| 91福利精品视频| 成人久久视频在线观看| 久久精品99久久久| 丝袜亚洲精品中文字幕一区| 国产精品乱人伦中文| 日韩美女一区二区三区四区| 欧美最猛黑人xxxxx猛交| jlzzjlzz亚洲女人18| 国产99久久久国产精品潘金 | 欧美一区二区三区小说| 日本韩国精品在线| 一本大道久久a久久综合婷婷| 风间由美一区二区av101| 国产美女精品人人做人人爽| 精品一区二区在线免费观看| 日韩成人精品在线观看| 日韩电影免费在线看| 日韩国产欧美在线播放| 蜜桃传媒麻豆第一区在线观看| 日日骚欧美日韩| 欧美aaa在线| 精品在线亚洲视频| 精品亚洲成av人在线观看| 毛片一区二区三区| 福利一区二区在线观看| 91猫先生在线| 欧美男同性恋视频网站| 欧美一区二区福利视频| 2020国产精品久久精品美国| 国产日韩欧美制服另类| 亚洲人妖av一区二区| 亚洲国产综合在线| 久久国产精品第一页| 成人黄色在线网站| 欧美四级电影网| 久久一区二区视频| 一区2区3区在线看| 日本不卡在线视频| 91日韩在线专区| 这里只有精品99re| 一区免费观看视频| 奇米777欧美一区二区| 成人ar影院免费观看视频| 日韩欧美亚洲一区二区| 亚洲人午夜精品天堂一二香蕉| 裸体歌舞表演一区二区| 欧美在线|欧美| 国产精品久久久久精k8| 青青草成人在线观看| 色94色欧美sute亚洲线路一久 | 精品乱人伦小说| 婷婷开心激情综合| 日本丰满少妇一区二区三区| 欧美国产精品一区二区| 精品一区免费av| 欧美日韩亚洲另类| 亚洲激情男女视频| 91小宝寻花一区二区三区| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲一区中文日韩| 91成人在线观看喷潮| 亚洲图片欧美激情| 欧美sm美女调教| 久久不见久久见免费视频1| 日韩欧美一区二区不卡| 免费成人在线观看| 欧美大尺度电影在线| 青青草97国产精品免费观看 | 精品日产卡一卡二卡麻豆| 日韩精品每日更新| 欧美日韩aaaaa| 蜜臀va亚洲va欧美va天堂| 日韩欧美国产一区在线观看| 麻豆精品一区二区综合av| 久久亚洲一区二区三区明星换脸| 国产91露脸合集magnet| 欧美日韩精品一区二区在线播放| 国产无人区一区二区三区| 色94色欧美sute亚洲线路一ni | 欧美亚洲动漫制服丝袜| 污片在线观看一区二区| 日韩一级高清毛片| 粉嫩欧美一区二区三区高清影视| 中文一区二区完整视频在线观看| 成人深夜在线观看| 亚洲人精品一区| 日韩欧美亚洲国产另类| 99精品欧美一区二区三区综合在线| 亚洲激情综合网| 日韩一区二区在线看| 99国产精品久久久久久久久久久| 六月丁香婷婷久久| 亚洲成人资源网| 亚洲欧洲综合另类| 国产精品你懂的在线欣赏| 日韩午夜在线观看视频| 91免费国产在线观看| 精品一区二区综合| 午夜精品福利一区二区蜜股av| 中文成人综合网| 国产亚洲一区二区三区| 日韩欧美在线不卡| 日韩欧美另类在线| 日韩精品一区国产麻豆| 欧美一卡二卡三卡四卡| 91免费在线播放| 一区二区中文字幕在线| 91精品久久久久久蜜臀| 精品国内二区三区| 亚洲专区一二三| 国产久卡久卡久卡久卡视频精品| 日韩精品三区四区| 国产在线国偷精品产拍免费yy| 国产高清在线精品| 一本色道a无线码一区v| 91福利精品视频| 欧美久久久久久久久| 日韩精品一区二区三区swag| 日韩欧美电影一二三| 国产精品日韩成人| 亚洲一区二区精品视频| 亚洲高清免费视频| 美腿丝袜亚洲一区| k8久久久一区二区三区| 91精品欧美福利在线观看| 欧美成人a在线| 中文字幕久久午夜不卡| 亚洲国产cao| 国产一区二区成人久久免费影院| 欧美色图天堂网| 精品处破学生在线二十三| 国产精品免费视频网站| 婷婷中文字幕一区三区| 国产aⅴ综合色| 欧美视频一区二区三区在线观看| 亚洲国产高清不卡| 一区二区三区小说| 久草在线在线精品观看| 99精品久久99久久久久| 精品对白一区国产伦| 亚洲在线免费播放| 成人av动漫网站| 国产精品色哟哟网站| 成人污视频在线观看| 久久久久亚洲蜜桃| 成人午夜在线免费| 国产精品久久影院| gogogo免费视频观看亚洲一| 国产精品色哟哟网站| 日本道色综合久久| 丝袜亚洲另类欧美综合| 成人免费看黄yyy456| 色猫猫国产区一区二在线视频| 精品精品国产高清a毛片牛牛| 亚洲精品中文在线观看| av在线播放不卡| 中文在线一区二区| 国产一区二区三区香蕉| 久久欧美中文字幕| 国产乱国产乱300精品| 精品成人在线观看| 老鸭窝一区二区久久精品| 91极品视觉盛宴| 国产欧美日韩综合| 大陆成人av片| 国产精品国产三级国产三级人妇| 国产毛片精品国产一区二区三区| 国产午夜精品理论片a级大结局| 国产在线精品一区二区三区不卡| 久久伊人蜜桃av一区二区| 国产成人一区二区精品非洲|