




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、Android游戲開發(fā)之旅一長按Button原理今天Android123開始新的Android游戲開發(fā)之旅系列,主要從控制方法(按鍵、軌跡球、觸屏、重力感應、攝像頭、話筒氣流、光線亮度)、圖形View(高效繪圖技術如雙緩沖)、音效(游戲音樂)以及最后的OpenGL ES(Java層)和NDK的OpenGL和J2ME游戲移植到Android方法,當然還有一些游戲?qū)崿F(xiàn)慣用方法,比方地圖編輯器,在Android OpenGL如何使用MD2文件,個部分講述下Android游戲開發(fā)的過程最終實現(xiàn)一個比擬完整的游戲引擎。相信大家都清楚AndroidMarket下載量比擬好的都是游戲,未來網(wǎng)游的開展相信An
2、droid使用的Java在這方面有比iPhone有更低的入門門檻。對于很多游戲使用屏幕控制一般需要考慮長按事件,比方在動作類的游戲中需要長按發(fā)射武器,結合Android Button模型,我們實現(xiàn)一個帶圖片的Button的長按,為了更清晰的顯示原理,Android開發(fā)網(wǎng)這里使用ImageButton作為基類public class RepeatingImageButton extends ImageButton private long mStartTime; /記錄長按開始private int mRepeatCount; /重復次數(shù)計數(shù)private RepeatListener mLis
3、tener;private long mInterval = 500; /Timer觸發(fā)間隔,即每0.5秒算一次按下public RepeatingImageButton(Context context) this(context, null);publicRepeatingImageButton(Contextcontext,AttributeSetattrs)this(context,attrs,android.R.attr.imageButtonStyle);public RepeatingImageButton(Context context, AttributeSet attrs,
4、int defStyle) super(context, attrs,defStyle);setFocusable(true); /允許獲得焦點setLongClickable(true); /啟用長按事件public void setRepeatListener(RepeatListener l, long interval) /實現(xiàn)重復按下事件listenermListener = l;mInterval = interval;Overridepublic boolean performLongClick() mStartTime = SystemClock.elapsedRealtime
5、();mRepeatCount = 0;post(mRepeater);return true;Overridepublic boolean onTouchEvent(MotionEvent event) if (event.getAction() = MotionEvent.ACTION_UP) /本方法原理同onKeyUp的一樣,這里處理屏幕事件,下面的onKeyUp處理Android上的物理按鍵事件removeCallbacks(mRepeater);if (mStartTime != 0) doRepeat(true);mStartTime = 0;return super.onTou
6、chEvent(event);/處理導航鍵事件的中鍵或軌跡球按下事件Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) switch (keyCode) case KeyEvent.KEYCODE_DPAD_CENTER:case KeyEvent.KEYCODE_ENTER:super.onKeyDown(keyCode, event); return true;return super.onKeyDown(keyCode, event);/當按鍵彈起通知長按結束Overridepublic boolean onKeyU
7、p(int keyCode, KeyEvent event) switch (keyCode) case KeyEvent.KEYCODE_DPAD_CENTER:case KeyEvent.KEYCODE_ENTER:removeCallbacks(mRepeater); /取消重復listener捕獲if (mStartTime != 0) doRepeat(true); /如果長按事件累計時間不為0那么說明長按了mStartTime = 0; /重置長按計時器return super.onKeyUp(keyCode, event);private Runnable mRepeater =
8、 new Runnable() /在線程中判斷重復public void run() doRepeat(false);if (isPressed() postDelayed(this, mInterval); /計算長按后延遲下一次累加 ;private void doRepeat(boolean last) long now = SystemClock.elapsedRealtime();if (mListener != null) mListener.onRepeat(this, now - mStartTime, last ? -1 : mRepeatCount+);下面是重復Butto
9、n Listener接口的定義,調(diào)用時在Button中先使用setRepeatListener()方法實現(xiàn)RepeatListener接口public interface RepeatListener void onRepeat(View v, long duration, int repeatcount); /參數(shù)一為用戶傳入的Button對象,參數(shù)二為延遲的毫秒數(shù),第三位重復次數(shù)回調(diào)。Android游戲開發(fā)之旅二View和SurfaceView在Android游戲當中充當主要的除了控制類外就是顯示類,在J2ME中我們用Display和Canvas來實現(xiàn)這些,而Google Android中
10、涉及到顯示的為view類,Android游戲開發(fā)中比擬重要和復雜的就是顯示和游戲邏輯的處理。這里我們說下android.view.View和android.view.SurfaceViewSurfaceView是從View基類中派生出來的顯示類,直接子類有GLSurfaceView和VideoView,可以看出GL和視頻播放以及Camera攝像頭一般均使用SurfaceView,到底有哪些優(yōu)勢呢?SurfaceView可以控制外表的格式,比方大小,顯示在屏幕中的位置,最關鍵是的提供了SurfaceHolder類,使用getHolder方法獲取,相關的有Canvas lockCanvas()Ca
11、nvas lockCanvas(Rect dirty)、void removeCallback(SurfaceHolder.Callback callback)、voidunlockCanvasAndPost(Canvas canvas)控制圖形以及繪制,而在SurfaceHolder.Callback接口回調(diào)中可以通過下面三個抽象類可以自己定義具體的實現(xiàn),比方第一個更改格式和顯示畫面。abstract void surfaceChanged(SurfaceHolder holder, int format, int width, int height) abstract voidsurfac
12、eCreated(SurfaceHolder holder)abstract void surfaceDestroyed(SurfaceHolder holder)對于Surface相關的,Android底層還提供了GPU加速功能,所以一般實時性很強的應用中主要使用SurfaceView而不是直接從View構建, 同時Android123未來后面說到的OpenGL中的GLSurfaceView也是從該類實現(xiàn)。Android游戲開發(fā)之旅三View類詳解在Android游戲開發(fā)之旅二中我們講到了View和SurfaceView的區(qū)別, 今天Android123從View類開始著重的介紹Androi
13、d圖形顯示基類的相關方法和注意點。自定義View的常用方法:onFinishInflate()當View中所有的子控件均被映射成xml后觸發(fā)onMeasure(int, int)確定所有子元素的大小onLayout(boolean, int, int, int, int)當View分配所有的子元素的大小和位置時觸發(fā)onSizeChanged(int, int, int, int)當view的大小發(fā)生變化時觸發(fā)onDraw(Canvas) view渲染內(nèi)容的細節(jié)onKeyDown(int, KeyEvent)有按鍵按下后觸發(fā)onKeyUp(int, KeyEvent)有按鍵按下后彈起時觸發(fā)onT
14、rackballEvent(MotionEvent)軌跡球事件onTouchEvent(MotionEvent)觸屏事件onFocusChanged(boolean, int, Rect)當View獲取或失去焦點時觸發(fā)onWindowFocusChanged(boolean)當窗口包含的view獲取或失去焦點時觸發(fā)onAttachedToWindow()當view被附著到一個窗口時觸發(fā)onDetachedFromWindow()當view離開附著的窗口時觸發(fā),Android123提示該方法和onAttachedToWindow()是相反的。onWindowVisibilityChanged(i
15、nt)當窗口中包含的可見的view發(fā)生變化時觸發(fā)以上是View實現(xiàn)的一些根本接口的回調(diào)方法,一般我們需要處理畫布的顯示時,重寫onDraw(Canvas)用的的是最多的:Overrideprotected void onDraw(Canvas canvas) /這里我們直接使用canvas對象處理當前的畫布,比方說使用Paint來選擇要填充的顏色Paint paintBackground = new Paint();paintBackground.setColor(getResources().getColor(R.color.xxx);/從Res中找到名為xxx的color顏色定義canva
16、s.drawRect(0, 0, getWidth(), getHeight(), paintBackground); /設置當前畫布的背景顏色為paintBackground中定義的顏色,以0,0作為為起點, 以當前畫布的寬度和高度為重點即整塊畫布來填充。具體的請查看Android123未來講到的Canvas和Paint,在Canvas中我們可以實現(xiàn)畫路徑,Paint作為繪畫方式的對象可以設置顏色,大小,甚至字體的類型等等。當然還有就是處理窗口復原狀態(tài)問題(一般用于橫豎屏切換),除了在Activity中可以調(diào)用外,開發(fā)游戲時我們盡量在View中使用類似Overrideprotected Pa
17、rcelable onSaveInstanceState() Parcelable p = super.onSaveInstanceState();Bundle bundle = new Bundle();bundle.putInt(x, pX);bundle.putInt(y, pY);bundle.putParcelable(android123_state, p);return bundle;Overrideprotected void onRestoreInstanceState(Parcelable state) Bundle bundle = (Bundle) state;doso
18、mething(bundle.getInt(x), bundle.getInt(y); /獲取剛剛存儲的x和y信息super.onRestoreInstanceState(bundle.getParcelable(android123_state); return;在View中如果需要強制調(diào)用繪制方法onDraw,可以使用invalidate()方法,它有很多重載版本,同時在線程中的postInvailidate()方法將在Android游戲開發(fā)之旅六中的自定義View完整篇講到。Android游戲開發(fā)之旅四Canvas和Paint實例昨天我們在Android游戲開發(fā)之旅三View詳解中提到了
19、onDraw方法,有關詳細的實現(xiàn)我們今天主要說下Android的Canvas和Paint對象的使用實例。Canvas類主要實現(xiàn)了屏幕的繪制過程,其中包含了很多實用的方法,比方繪制一條路徑、區(qū)域、貼圖、畫點、畫線、渲染文本,下面是Canvas類常用的方法,當然Android開發(fā)網(wǎng)提示大 家很多方法有不同的重載版本,參數(shù)更靈活。void drawRect(RectF rect, Paint paint)/繪制區(qū)域,參數(shù)一為RectF一個區(qū)域void drawPath(Path path, Paint paint) /繪制一個路徑,參數(shù)一為Path路徑對象void drawBitmap(Bitmap
20、 bitmap, Rect src, Rect dst, Paint paint)/貼圖,參數(shù)一就是我們常規(guī)的Bitmap對象,參數(shù)二是源區(qū)域(Android123提示這里是bitmap),參數(shù)三是目標區(qū)域(應該在canvas的位置和大小),參數(shù)四是Paint畫刷對象,因為用到了縮放和拉伸的可能,當原始Rect不等于目標Rect時性能將會有大幅損失。void drawLine(float startX, float startY, float stopX, float stopY, Paint paint)/畫線,參數(shù)一起始點的x軸位置,參數(shù)二起始點的y軸位置,參數(shù)三終點的x軸水平位置,參數(shù)四
21、y軸垂直位 置,最后一個參數(shù)為Paint畫刷對象。void drawPoint(float x, float y, Paint paint) /畫點,參數(shù)一水平x軸,參數(shù)二垂直y軸,第三 個參數(shù)為Paint對象。void drawText(String text, float x, float y, Paint paint)渲染文本,Canvas類除了上面的還可以描繪文字,參數(shù)一是String類型的文本,參數(shù)二x軸,參數(shù)三y軸,參數(shù)四是Paint對象。void drawTextOnPath(String text, Path path, float hOffset, float vOffset
22、, Paint paint) /在路徑上繪制文本,相對于上面第二個參數(shù)是Path路徑對象從上面來看我們可以看出Canvas繪制類比擬簡單同時很靈活,實現(xiàn)一般的方法通常沒有問題,同時可以疊加的處理設計出一些效果,不過細心的網(wǎng)友可能發(fā)現(xiàn)最后一個參數(shù)均為Paint對象如果我們把Canvas當做繪畫師來看,那么Paint就是我們繪畫的工具,比方畫筆、畫刷、顏料 等等。Paint類常用方法:void setARGB(int a, int r, int g, int b)設置Paint對象顏色,參數(shù)一為alpha透明通道void setAlpha(int a)設置alpha不透明度,范圍為0255void
23、 setAntiAlias(boolean aa)/是否抗鋸齒void setColor(int color)/設置顏色, 這里Android內(nèi)部定義的有Color類包含了一些常見顏色定義.void setFakeBoldText(boolean fakeBoldText) /設置偽粗體文本void setLinearText(boolean linearText) /設置線性文本PathEffect setPathEffect(PathEffect effect)/設置路徑效果Rasterizer setRasterizer(Rasterizer rasterizer) /設置光柵化Type
24、face setTypeface(Typeface typeface) /設置字體,Typeface包含了字體的類型,粗細,還有傾斜、顏色等。void setUnderlineText(boolean underlineText)/設置下劃線最終Canvas和Paint在onDraw中直接使用Overrideprotected void onDraw(Canvas canvas) Paint paintRed=new Paint();paintRed.setColor(Color.Red);canvas.drawPoint(11,3,paintRed); /在坐標11,3上畫一個紅點下一次An
25、droid123將會具體講到強大的Path路徑,和字體Typeface相關的使用。Android游戲開發(fā)之旅(五)Path和Typeface今天我們繼續(xù)處理上次Android游戲開發(fā)之旅(四)Canvas和Paint實例 中提到的Path路徑和Typeface字體兩個類。對于Android游戲開發(fā)或者說2D繪圖中來講Path路徑可以用強大這個詞來形容。在Photoshop中我們可能還記得使用鋼筆工具繪制路徑的方法。Path路徑類在位于android.graphics.Path中,Path的構造方法比擬簡單,如下Path cwj=new Path(); /構造方法Shader setShader
26、(Shader shader) voidsetTextAlign(Paint.Align align) voidsetTextScaleX(float scaleX) voidsetTextSize(float textSize)/設置陰影/設置文本對齊/設置文本縮放倍數(shù),1.0f為原始/設置字體大小復制代碼下面我們畫一個封閉的原型路徑,我們使用Path類的addCircle方法cwj.addCircle(10,10,50,Direction.CW); /參數(shù)一為x軸水平位置,參數(shù)二為y軸垂直位置,第三個參數(shù)為圓形的半徑,最后是繪制的方向,CW為順時針方向,而CCW是逆時針方向復制代碼結合An
27、droid上次提到的Canvas類中的繪制方法drawPath和drawTextOnPath,我們繼續(xù)可以在onDraw中參加。canvas.drawPath(cwj,paintPath); /Android123提示大家這里paintPath為路徑的畫刷顏色,可以見下文完整的源代碼。canvas.drawTextOnPath(Android123 - CWJ,cwj,0,15,paintText); /將文字繪制到路徑中去,復制代碼有關drawTextOnPath的參數(shù)如下:方法原型public void drawTextOnPath (String text, Path path, flo
28、at hOffset, float vOffset, Paint paint)復制代碼參數(shù)列表text為需要在路徑上繪制的文字內(nèi)容。path將文字繪制到哪個路徑。hOffset距離路徑開始的距離vOffset離路徑的上下高度,這里Android開發(fā)網(wǎng)提示大家,該參數(shù)類型為float浮點型,除了精度為8位小數(shù)外,可以為正或負,當為正時文字在路徑的圈里面,為負時在路徑的圈外面。paint最后仍然是一個Paint對象用于制定Text本文的顏色、字體、大小等屬性。下面是我們的onDraw方法中如何繪制路徑的演示代碼為:Overrideprotected void onDraw(Canvas canva
29、s) Paint paintPath=new Paint();Paint paintText=new Paint();paintPath.setColor(Color.Red); /路徑的畫刷為紅色paintText.setColor(Color.Blue); /路徑上的文字為藍色Path pathCWJ=new Path();pathCWJ.addCircle(10,10,50,Direction.CW); /半徑為50px,繪制的方向CW為順時針canvas.drawPath(pathCWJ,paintPath);canvas.drawTextOnPath(Android123 - CWJ
30、,pathCWJ,0,15,paintText); /在路徑上繪制文字復制代碼 有關路徑類常用的方法如下void addArc(RectF oval, float startAngle, float sweepAngle) /為路徑添加一個多邊形void addCircle(float x, float y, float radius, Path.Direction dir) /void addOval(RectF oval, Path.Direction dir) /添加橢圓形void addRect(RectF rect, Path.Direction dir) /添加一個區(qū)域void a
31、ddRoundRect(RectF rect, float radii, Path.Direction dir) /boolean isEmpty() /判斷路徑是否為空void transform(Matrix matrix) /應用矩陣變換void transform(Matrix matrix, Path dst) /應用矩陣變換并將結果放到新的路徑中,即第二個參 數(shù)。復制代碼有關路徑的高級效果大家可以使用PathEffect類, 有關路徑的更多實例Android123將在今后的游戲開發(fā)實戰(zhàn)中講解道。Typeface字體類給path添加圓圈添加一個圓角區(qū)域平時我們在TextView中需要
32、設置顯示的字體可以通過TextView中的setTypeface方法來指定一個Typeface對象,因為Android的字體類比擬簡單,我們列出所有成員方法static Typeface create(Typeface family, int style) /靜態(tài)方法,參數(shù)一為字體類型這里是Typeface的靜態(tài)定義,如宋體,參數(shù)二風格,如粗體,斜體static Typeface create(String familyName, int style) /靜態(tài)方法,參數(shù)一為字體名的字符串,參數(shù)二為風格同上,這里我們推薦使用上面的方法。static Typeface createFromAsse
33、t(AssetManager mgr, String path) /靜態(tài)方法,參數(shù)一為AssetManager對象,主要用于從APK的assets文件夾中取出字體,參數(shù)二為相對于Android工程下的assets文件夾中的外掛字體文件的路徑。static Typeface createFromFile(File path) /以是sdcard中的某個字體文件static Typeface createFromFile(String path) /static Typeface defaultFromStyle(int style) / intgetStyle() /獲取當前字體風格final
34、boolean isBold() /判斷當前是否為粗體final boolean isItalic() /判斷當前風格是否為斜體復制代碼 本類的常量靜態(tài)定義,首先為字體類型名稱Typeface DEFAULTTypeface DEFAULT_BOLDTypeface MONOSPACETypeface SANS_SERIFTypeface SERIF字體風格名稱int BOLDint BOLD_ITALICint ITALICint NORMAL明天我們將在Android游戲開發(fā)之旅六自定義View一文中具體講解onDraw以及什么時候會觸發(fā)繪制方法,來實現(xiàn)我們自定義或子類化控件。靜態(tài)方法,從
35、文件系Android游戲開發(fā)之旅六自定義View有關Android的自定義View的框架今天我們一起討論下,對于常規(guī)的游戲,我們在View中需要處理以下幾種問題: 1.控制事件2.刷新View 3.繪制View1.對于控制事件今天我們只處理按鍵事件onKeyDown, 以后的文章中將會講到屏幕觸控的具體處理onTouchEvent以及Sensor重力感應等方法。2.刷新view的方法這里主要有invalidate(int l, int t, int r, int b)刷新局部,四個參數(shù)分別為左、上、右、下。整個view刷新invalidate(),刷新一個矩形區(qū)域invalidate(Rect
36、 dirty),刷新一個特性Drawable,invalidateDrawable(Drawable drawable), 執(zhí)行invalidate類的方法將會設置view為無效,最終導致onDraw方法被重新調(diào)用。由于今天的view比擬簡單,Android123提示大家如果在線程中刷新,除了使用handler方式外, 可以在Thread中直接使用postInvalidate方法來實現(xiàn)。3.繪制View主要是onDraw()中通過形參canvas來處理,相關的繪制主要有drawRect、drawLine、drawPath等等。view方法內(nèi)部還重寫了很多接口,其回調(diào)方法可以幫助我們判斷出vie
37、w的位置和大小,比方onMeasure(int, int) Called to determine the size requirements for thisview and all of its children.、onLayout(boolean, int, int, int, int) Called when this view should assigna size and position to all of its children和onSizeChanged(int, int, int, int) Called when the size ofthis view has cha
38、nged.具體的作用,大家可以用Logcat獲取當view變化時每個形參的變動。下面cwjView是我們?yōu)榻窈笥螒蛟O計的一個簡單自定義View框架,我們可以看到在Android平臺自定義view還是很簡單的,同時Java支持多繼承可以幫助我們不斷的完善復雜的問題。public class cwjView extends View public cwjView(Context context) super(context);setFocusable(true); /允許獲得焦點setFocusableInTouchMode(true); /獲取焦點時允許觸控Overrideprotected P
39、arcelable onSaveInstanceState() /處理窗口保存事件Parcelable pSaved = super.onSaveInstanceState();Bundle bundle = new Bundle();/dosomething return bundle;Overrideprotected void onRestoreInstanceState(Parcelable state) /處理窗口復原事件Bundle bundle = (Bundle) state;/dosomethingsuper.onRestoreInstanceState(bundle.get
40、Parcelable(cwj);return;Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) /處理窗口大小變化事件super.onSizeChanged(w, h, oldw, oldh);Overrideprotected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)super.onMeasure(widthMeasureSpec, heightMeasureSpec); /如果不讓父類處理記住調(diào)用setMeasuredD
41、imensionOverrideprotected void onLayout (boolean changed, int left, int top, int right, int bottom) super.onLayout (changed,left,top, ight,bottom) ;Overrideprotected void onDraw(Canvas canvas) Paint bg = new Paint();bg.setColor(Color.Red);canvas.drawRect(0, 0, getWidth()/2, getHeight()/2, bg); /將vie
42、w的左上角四分之一填充為 紅色Overridepublic boolean onTouchEvent(MotionEvent event) return super.onTouchEvent(event); /讓父類處理屏幕觸控事件Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) /處理按鍵事件,響應的軌跡球事件為public boolean onTrackballEvent (MotionEvent event)switch (keyCode) case KeyEvent.KEYCODE_DPAD_UP:break;c
43、ase KeyEvent.KEYCODE_DPAD_DOWN:break;case KeyEvent.KEYCODE_DPAD_LEFT:break;case KeyEvent.KEYCODE_DPAD_RIGHT:break;case KeyEvent.KEYCODE_DPAD_CENTER: /處理中鍵按下break;default:return super.onKeyDown(keyCode, event);return true;上面我們可以看到onMeasure使用的是父類的處理方法,如果我們需要解決自定義View的大小,可以嘗試下面的方法Overrideprotected void
44、 onMeasure (int widthMeasureSpec, int heightMeasureSpec) height = View.MeasureSpec.getSize(heightMeasureSpec);width = View.MeasureSpec.getSize(widthMeasureSpec);setMeasuredDimension(width,height);/這里面是原始的大小,需要重新計算可以修改本/dosomethingAndroid游戲開發(fā)之旅七自定義SurfaceView今天我們說下未來的Android游戲引擎模板架構問題,對于游戲我們還是選擇Surfa
45、ceView,相關的原因Android123已經(jīng)在Android游戲開發(fā)之旅二View和SurfaceView中說的很清楚了, 這里我們直接繼承SurfaceView,實現(xiàn)SurfaceHolder.Callback接口,處理surfaceCreated、surfaceChanged以及surfaceDestroyed方法,這里我們并沒有把按鍵控制傳入,最終游戲的控制方面仍然由View內(nèi)部類處理比擬好,有關SurfaceView的具體我們可以參見Android開源項目的Camera中有關畫面捕捉以及VideoView的控件實現(xiàn)大家可以清晰了解最終的用意。public class cwjView
46、 extends SurfaceView implements SurfaceHolder.Callback public cwjView(Context context, AttributeSet attrs) super(context, attrs);SurfaceHolder holder=getHolder(); holder.addCallback(this);setFocusable(true); public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) public v
47、oid surfaceCreated(SurfaceHolder holder) public void surfaceDestroyed(SurfaceHolder holder) Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) Android游戲開發(fā)之旅八SurfaceView類實例有關SurfaceView我們將通過三個系統(tǒng)自帶的例子來深入掌握Android繪圖必會的SurfaceView今天我們以SDK中的Sample游戲lunarlander中的LunarView具體實現(xiàn),Android123建議大家導
48、入該游戲工程到你的Eclipse然后自己編譯先玩一下這個游戲,然后再看代碼比擬好理解。class LunarView extends SurfaceView implements SurfaceHolder.Callback class LunarThread extends Thread /* Difficulty setting constants*/public static final int DIFFICULTY_EASY = 0;public static final int DIFFICULTY_HARD = 1;public static final int DIFFICULT
49、Y_MEDIUM = 2;/* Physics constants*/public static final int PHYS_DOWN_ACCEL_SEC = 35;public static final int PHYS_FIRE_ACCEL_SEC = 80;public static final int PHYS_FUEL_INIT = 60;public static final int PHYS_FUEL_MAX = 100;public static final int PHYS_FUEL_SEC = 10;public static final int PHYS_SLEW_SE
50、C = 120; / degrees/second rotatepublic static final int PHYS_SPEED_HYPERSPACE = 180;public static final int PHYS_SPEED_INIT = 30;public static final int PHYS_SPEED_MAX = 120;/* State-tracking constants*/public static final int STATE_LOSE = 1;public static final int STATE_PAUSE = 2;public static fina
51、l int STATE_READY = 3;public static final int STATE_RUNNING = 4;public static final int STATE_WIN = 5;/* Goal condition constants*/public static final int TARGET_ANGLE = 18; / this angle means crashpublic static final int TARGET_BOTTOM_PADDING = 17; / px below gearpublic static final int TARGET_PAD_
52、HEIGHT = 8; / how high above groundpublic static final int TARGET_SPEED = 28; / this speed means crashpublic static final double TARGET_WIDTH = 1.6; / width of target /* UI constants (i.e. the speed & fuel bars)*/public static final int UI_BAR = 100; / width of the bar(s)public static final int
53、UI_BAR_HEIGHT = 10; / height of the bar(s) private static final StringKEY_DIFFICULTY = mDifficulty;private static final String KEY_DX = mDX;private static final String KEY_DY = mDY;private static final String KEY_FUEL = mFuel;private static final String KEY_GOAL_ANGLE = mGoalAngle;private static fin
54、al String KEY_GOAL_SPEED = mGoalSpeed;private static final String KEY_GOAL_WIDTH = mGoalWidth;private static final String KEY_GOAL_X = mGoalX;private static final String KEY_HEADING = mHeading;private static final String KEY_LANDER_HEIGHT = mLanderHeight;private static final String KEY_LANDER_WIDTH
55、= mLanderWidth;private static final String KEY_WINS = mWinsInARow;private static final String KEY_X = mX;private static final String KEY_Y = mY;/* Member (state) fields*/* The drawable to use as the background of the animation canvas */ private Bitmap mBackgroundImage;/* Current height of the surfac
56、e/canvas.* see #setSurfaceSize*/private int mCanvasHeight = 1;/* Current width of the surface/canvas.* see #setSurfaceSize*/private int mCanvasWidth = 1;/* What to draw for the Lander when it has crashed */ private Drawable mCrashedImage;/*Current difficulty - amount of fuel, allowed angle, etc. Def
57、ault is MEDIUM.*/private int mDifficulty;/* Velocity dx. */ private double mDX;/* Velocity dy. */ private double mDY;/* Is the engine burning? */ private boolean mEngineFiring;/* What to draw for the Lander when the engine is firing */ private Drawable mFiringImage;/* Fuel remaining */ private doubl
58、e mFuel;/* Allowed angle. */ private int mGoalAngle;/* Allowed speed. */ private int mGoalSpeed;/* Width of the landing pad. */ private int mGoalWidth;/* X of the landing pad. */ private int mGoalX;/* Message handler used by thread to interact with TextView */ private Handler mHandler;/* Lander head
59、ing in degrees, with 0 up, 90 right. Kept in the range * 0.360.*/private double mHeading;/* Pixel height of lander image. */private int mLanderHeight;/* What to draw for the Lander in its normal state */ private Drawable mLanderImage;/* Pixel width of lander image. */ private int mLanderWidth;/* Use
60、d to figure out elapsed time between frames */ private long mLastTime;/* Paint to draw the lines on screen. */ private Paint mLinePaint;/* Bad speed-too-high variant of the line color. */ private Paint mLinePaintBad;/* The state of the game. One of READY, RUNNING, PAUSE, LOSE, or WIN */ private int mMode;/* Cu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 合同買賣擔保協(xié)議書
- 借款合同第三方擔保
- 醫(yī)療器械服務協(xié)議合同
- 建筑次結構勞務合同
- 房地產(chǎn)融資居間合同書
- 工作接送服務合同范本
- 項目合同終止申請書(2025年版)
- 牙膏批發(fā)合同范本
- 規(guī)劃與總體專業(yè)綠色建筑分析報告與計算書的內(nèi)容要求
- 財務審計框架合同范本
- 2024福建漳州市九龍江集團有限公司招聘10人筆試參考題庫附帶答案詳解
- 公安審訊技巧課件
- 中國少數(shù)民族文化知到課后答案智慧樹章節(jié)測試答案2025年春云南大學
- 西方教育史考題及答案
- 軟件開發(fā)java筆試題及答案
- 小學綜合實踐三年級下冊巧手工藝坊教學課件
- 2025年紹興職業(yè)技術學院單招職業(yè)適應性測試題庫帶答案
- 2025年監(jiān)理工程師考試《建設工程監(jiān)理案例分析(水利工程)》綜合案例題
- DB61T 5113-2024 建筑施工全鋼附著式升降腳手架安全技術規(guī)程
- 店鋪轉(zhuǎn)讓合同店鋪轉(zhuǎn)讓合同電子版5篇
- 公共衛(wèi)生應急管理體系建設的調(diào)研報告
評論
0/150
提交評論