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

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

?? ch6.htm

?? 有關于游戲開發的教程我閱讀后感覺不錯所以就拿出來與大家共享。
?? 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一区二区三区免费野_久草精品视频
久久国产精品露脸对白| 中文字幕在线观看一区二区| 国产成人午夜视频| 亚洲国产乱码最新视频| 亚洲精品高清在线观看| 亚洲欧美一区二区三区国产精品| 中文字幕欧美三区| 中文字幕av一区二区三区高| 欧美经典三级视频一区二区三区| 久久久精品免费网站| 精品福利在线导航| 91片在线免费观看| 色综合久久99| 日本不卡不码高清免费观看 | 性做久久久久久| 午夜精品福利一区二区三区av| 中文字幕佐山爱一区二区免费| 国产精品久久久久精k8| 亚洲人123区| 最新中文字幕一区二区三区| 自拍av一区二区三区| 国产精品人成在线观看免费| 综合分类小说区另类春色亚洲小说欧美| 欧美精品一区视频| 中文字幕一区日韩精品欧美| 亚洲一区电影777| 久久成人久久爱| 蜜桃视频免费观看一区| 国产美女一区二区三区| 国产99久久久国产精品免费看| 高清在线成人网| 日本韩国欧美在线| 欧美成人一区二区三区| 久久久久97国产精华液好用吗| 成人免费在线视频观看| 日韩avvvv在线播放| 成人av电影在线| 欧美精品第1页| 综合久久久久久久| 黄色成人免费在线| 欧美在线免费视屏| 国产欧美一区二区精品久导航| 亚洲一区av在线| 国产精品一区免费在线观看| 欧美日韩精品一区二区三区蜜桃| 久久天堂av综合合色蜜桃网| 亚洲一区在线视频观看| 高清成人免费视频| 欧美一区二区三区爱爱| 一级特黄大欧美久久久| 高清不卡一区二区| 日韩久久精品一区| 亚洲国产一区二区在线播放| 成人app软件下载大全免费| 欧美一区二区三区啪啪| 亚洲美女一区二区三区| 成人三级伦理片| 欧美精品一区二区三区在线播放| 一区二区三区在线看| 日韩电影在线观看一区| 欧美三级日本三级少妇99| 中文字幕第一页久久| 黄色精品一二区| 日韩一区二区精品在线观看| 午夜a成v人精品| 色成年激情久久综合| 亚洲视频网在线直播| av日韩在线网站| 国产欧美日韩精品一区| 国产揄拍国内精品对白| 日韩一区二区三区视频在线观看| 午夜激情综合网| 欧美日韩久久久一区| 性感美女久久精品| 5月丁香婷婷综合| 亚洲va欧美va人人爽| 欧美嫩在线观看| 日韩国产一区二| 欧美日韩精品一二三区| 日韩va欧美va亚洲va久久| 在线观看视频欧美| 亚洲激情校园春色| 欧美三级日韩三级国产三级| 日韩av中文在线观看| 日韩一区二区三区四区| 蜜臀av性久久久久蜜臀aⅴ流畅 | 亚洲美女免费视频| 欧美中文字幕亚洲一区二区va在线| 亚洲精品自拍动漫在线| 欧美午夜片在线看| 日本美女一区二区| 69成人精品免费视频| 久久爱www久久做| 国产午夜精品一区二区| av高清久久久| 亚洲一区二区免费视频| 精品三级在线看| 国产99一区视频免费| 亚洲同性gay激情无套| 欧美日韩精品二区第二页| 日韩精品亚洲专区| 久久久久久久久久久久电影| 99久久精品免费看国产| 天天影视涩香欲综合网| 久久网站热最新地址| 色综合视频在线观看| 强制捆绑调教一区二区| 国产精品日韩成人| 欧美日韩精品欧美日韩精品一| 国产伦精品一区二区三区免费| 亚洲视频小说图片| 精品999在线播放| 色8久久精品久久久久久蜜| 精品在线一区二区| 亚洲五码中文字幕| 国产精品麻豆一区二区| 欧美久久久久久久久| 国产69精品久久久久777| 午夜日韩在线电影| 国产精品色眯眯| 精品日韩99亚洲| 日本精品视频一区二区三区| 国产一区二区中文字幕| 亚洲成人精品在线观看| 国产精品黄色在线观看| 日韩一区二区在线观看视频播放| 91麻豆国产福利精品| 激情综合网天天干| 丝袜美腿亚洲综合| 亚洲欧美综合色| 久久久久久久久久久黄色| 欧美乱熟臀69xxxxxx| 91麻豆swag| 99久久精品久久久久久清纯| 精品午夜久久福利影院| 日韩va亚洲va欧美va久久| 自拍偷拍欧美激情| 精品黑人一区二区三区久久| 一本色道久久综合亚洲aⅴ蜜桃 | 91在线观看视频| 美美哒免费高清在线观看视频一区二区 | 亚洲男人的天堂在线aⅴ视频| 国产午夜精品美女毛片视频| 精品国产一区二区三区四区四| 欧美日韩一区不卡| 91福利在线导航| www.久久精品| 不卡欧美aaaaa| 国产乱色国产精品免费视频| 麻豆精品在线播放| 美女网站在线免费欧美精品| 亚洲美女免费视频| 亚洲狠狠丁香婷婷综合久久久| 日韩毛片精品高清免费| 亚洲色图.com| 亚洲天堂网中文字| 一区二区三区四区精品在线视频| 亚洲国产精品av| 欧美精彩视频一区二区三区| 国产欧美一区二区三区在线老狼| 国产情人综合久久777777| 久久久久久久一区| 国产日韩欧美麻豆| 国产精品天天摸av网| 中文字幕一区三区| 一区二区日韩电影| 亚洲成人精品一区| 蜜桃av一区二区在线观看| 国产在线播放一区三区四| 国产又黄又大久久| 成人午夜私人影院| 国产成人精品一区二| 国产成人精品在线看| 在线精品视频免费播放| 中文字幕+乱码+中文字幕一区| 中文字幕精品一区二区精品绿巨人| 国产欧美一区在线| 自拍偷在线精品自拍偷无码专区| 夜夜操天天操亚洲| 久久se精品一区精品二区| 处破女av一区二区| 欧美色视频在线| 精品国免费一区二区三区| 中文在线免费一区三区高中清不卡| 最新国产成人在线观看| 麻豆freexxxx性91精品| 不卡一区在线观看| 欧美一卡在线观看| 国产精品素人一区二区| 日韩黄色片在线观看| 成人黄色av电影| 精品欧美乱码久久久久久1区2区| 亚洲欧洲无码一区二区三区| 男人操女人的视频在线观看欧美| 成人午夜大片免费观看| 在线综合亚洲欧美在线视频| 国产精品蜜臀在线观看| 麻豆91在线观看| 欧美日韩一区久久| 亚洲男人的天堂一区二区|