freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

基于android的飛機大戰(zhàn)游戲設計與開發(fā)(編輯修改稿)

2025-07-25 00:16 本頁面
 

【文章內容簡介】 tent intent = new Intent(,)。 (intent)。 } } else if((eventX = SCORE_X)amp。amp。 (eventX = SCORE_X+())amp。amp。 (eventY = SCORE_Y)amp。amp。 (eventY = SCORE_Y+())){ if(action == ){ scoreButton = (getResources(), )。 drawScoreButton()。 } if(action == ){ scoreButton = (getResources(), )。 drawScoreButton()。 Intent intent = new Intent(,)。 (intent)。 } } else if((eventX = EXIT_X)amp。amp。 (eventX = EXIT_X +())amp。amp。 (eventY = EXIT_Y)amp。amp。 (eventY = EXIT_Y + ())){ if(action == ){ scoreButton = (getResources(), )。 drawExitButton()。 } if(action == ){ scoreButton = (getResources(), )。 drawExitButton()。 Activity activity = (Activity)context。 Intent intent = new Intent(EXIT)。 (EXIT)。 (intent)。 ()。 } } return true。 }本界面與開始界面都是使用SurfaceView繪制的界面,由于本界面相對于開始界面更加復雜在主線程外創(chuàng)建了子線程來負責對于SurfaceView的繪制工作,主線程負責對于各類對象的控制計算等計算工作。由于游戲界面涉及到的類比較多,且邏輯復雜,所以在這里只介紹下使用的空間、技術以及業(yè)務邏輯,粘貼部分技術代碼。繪制的游戲界面如圖48所示:圖48 游戲界面 Activity中注冊SurfaceView游戲界面并沒有像開始界面那樣注冊SurfaceView,而是直接在onCreate方法中使用代碼注冊的自定義SurfaceView,如下:private SkyGameScreenRollView sr = null。//自定義surfaceviewprotected void onCreate(Bundle savedInstanceState) { // TODO Autogenerated method stub (savedInstanceState)。 sr = new SkyGameScreenRollView(this)。 (new LayoutParams(, ))。 (0x000101)。 setContentView(sr)。} ContextMenu控件游戲界面使用了Android的ContextMenu,ContextMenu顯示的具體效果見圖49。圖49 ContextMenu效果ContextMenu針對某個控件,一旦為某個控件設置了ContextMenu,那么程序員將不能再實現該控件的長按事件處理了。ContextMenu的使用步驟:1. ContextMenu針對的是控件而不是窗體,構建完ContextMenu后需要與一個控件實施綁定。綁定的代碼為:(控件對象)。:**(當前應用使用的該方法)。()回調函數。(控件對象)。 具體操作方法重寫onCreateMenuItemSelected回調函數。:?xml version= encoding=utf8?menu xmlns:android= item android:id=@+id/pg_option_exit android:title=@string/option_menu_exit android:showAsAction=never/ item android:id=@+id/pg_option_score android:title=@string/option_menu_score android:showAsAction=never/ item android:id=@+id/pg_option_start android:title=@string/option_menu_start android:showAsAction=never/ item android:id=@+id/pg_option_option android:title=@string/option_menu_option android:showAsAction=never//menu在游戲界面的SkyGameScreenRollActivity的方法onCreateOptionsMenu(Menu menu),具體方法如下所示:public boolean onCreateOptionsMenu(Menu menu) { // TODO Autogenerated method stub MenuInflater inflater = new MenuInflater(this)。 (, menu)。 return true。 }在游戲界面的SkyGameScreenRollActivity的方法onOptionsItemSelected(MenuItem item)中為每個菜單選項編寫響應事件,具體使用方法如下所示:public boolean onOptionsItemSelected(MenuItem item) { // TODO Autogenerated method stub Intent intent = null。 switch(()){ case : intent = new Intent()。 (EXIT)。 (intent)。 ()。 break。 case : intent = new Intent(,)。 (intent)。 break。 case : intent = new Intent(,)。 (intent)。 break。 case : intent = new Intent(,)。 (intent)。 break。 } return true。 } 發(fā)送短信在用戶贏得一關的時候會發(fā)送一條信息“通過第N關”,實現該功能的代碼如下:private SmsManager sms = null。 = ()。private String telNum = null。telNum = 5554。//Android虛擬機的IDpublic void sendMessage(String telNum,String Message){ (telNum, null, Message, sentIntent , null)。 }(PS:Android的發(fā)送短信存在一個Bug就是當前DalvikVM發(fā)送的短信它自己無法收到,如果同時開兩個DalvikVM其中一個發(fā)送短信的話,另一個會收到短信。) 鼠標控制玩家飛機移動使用鼠標控制玩家飛機的移動,在自定義的SurfaceView的onTouchEvent方法中對于按下區(qū)域是否在玩家飛機圖片所在位置做出判定,如果在,則在拖動的過程中不斷獲得鼠標的坐標,并將該坐標傳遞給玩家飛機,以此來使玩家飛機隨著鼠標的位置移動。具體根據鼠標移動控制玩家飛機移動的邏輯如下所示:public boolean onTouchEvent(MotionEvent event) { // TODO Autogenerated method stub int action = ()。 float x = ()。 float y = ()。 if(x = ()amp。amp。 x = ()+()amp。amp。 y = ()amp。amp。 y = ()+()){ if(action == ){ playerIsTouch = true。 } if(action == ){ playerIsTouch = false。 (x, y)。 } } if(action == ){ if(playerIsTouch){ ((),())。 } } return true。 }圖410 鼠標控制玩家飛機序列圖 Activity之間傳遞數據使用到了Activity之間傳遞數據的技術,將玩家當前獲得的分數傳遞給下一個Activity以供使用。:Intent intent = new Intent(,)。 (score, ())。 (intent)。:Intent intent = getIntent()。 = (score, 1000)。 SurfaceView中繪制文字Android的Paint對象在畫布上實時繪制玩家的分數,代碼如下: public void drawScore(Canvas canvas){ Paint paint = new Paint()。 ()。 (20)。 (分數:+, viewWidth120, 30, paint)。 }繪制文字的效果如圖411所示: 圖411 繪制文字 碰撞邏輯判斷飛機是否中彈的邏輯非常簡單就是在繪制飛機與子彈的時候判斷兩個圖片是否存在重合的部分,如果存在則在該重合位置繪制一個爆炸圖片,之后將中彈飛機從飛機隊列中刪除,子彈同樣的處理。飛機中彈序列如圖412所示: 圖412 飛機中彈序列圖 血條繪制玩家飛機血線和Boss血線的邏輯是相同的,在統(tǒng)計飛機中彈次數的情況下使用圖413中的各個小圖對血線進行繪制。圖413 血線圖片集合繪制血線的邏輯如圖414所示:圖414 繪制血線邏輯具體負責繪制血線的函數(PS:該函數僅負責繪制,各種邏輯判斷的事情它不做)如下:public void drawPlayerBloodLine(Canvas canvas){ int num = playerIsShortedCount/5。 int leng = ()()*num。 Bitmap blood = null。 Bitmap empty = null。 if(num == 0){ ( fullBlood, 0, viewHeight (), null)。 }else if(leng ()){ blood = ( fullBlood, 0, 0, leng, ())。 empty = ( emptyBlood, leng, 0, ()leng, ())。 ( blood, 0, viewHeight (), null)。 ( empty, (), viewHeight (), null)。 }else if(leng 0){ blood = bloodBegin。 empty = ( emptyBlood, (), 0, ()(), ())。 ( blood, 0, viewHeight (), null)。 ( empty, (), viewHeight (), null)。 }else{ ( emptyBlood, 0, viewHeight (), null)。 isPlayerDead = true。 }}當前界面使用的是普通的layout,生成的設置界面如圖415所示:圖415 設置界面?xml version= encoding=utf8?LinearLayout xmlns:android= android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical LinearLayout android:layout_width=match_parent android:layout_height=wrap_content TextView android:id=@+
點擊復制文檔內容
環(huán)評公示相關推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1