人生的第乙個Android遊戲誕生

2021-07-03 22:00:46 字數 3758 閱讀 1214

所需的基本知識:

使用su***ceview類建立遊戲場景,遊戲場景實現runnable介面,並使用執行緒重新整理遊戲畫布

如何解決不同物體的重新整理頻率?

由於畫布是統一重新整理的(暫時不知道如何實現區域性重新整理畫布),例如a要0.1秒重新整理一次畫布,而b要1秒重新整理一次畫布,那麼就在場景中引入計時器timer,每次重新整理執行緒計時器遞增,讓執行緒休眠100毫秒,通過對計時器求模運算(如timer%20就是2秒重新整理頻率)

核心**:

package com.example.testgame;

import android.content.context;

import android.graphics.bitmap;

import android.graphics.bitmapfactory;

import android.graphics.canvas;

import android.graphics.color;

import android.graphics.paint;

import android.graphics.point;

import android.media.audiomanager;

import android.media.mediaplayer;

import android.media.soundpool;

import android.security.keystoreparameter.builder;

import android.view.motionevent;

import android.view.su***ceholder;

import android.view.su***ceholder.callback;

import android.view.su***ceview;

public class gameview extends su***ceview implements callback, runnable ,,,

,,,};

private int rows, cols;

int blk_width, blk_height;

private int mou***, mousey;

private int getx, gety;

private boolean touched;

private int timer = 1;

private int score = 0;

private soundpool clicksound, startsound;

private int soundid, startsoundid;

private bitmap bmpbtn = new bitmap[2];

private bitmap bmpbg, bmpscoreboard, map;

private boolean pressed = false;

private boolean startgame = false;

private mediaplayer mp, end;

private bitmap mouse;

private int count_down;

public gameview(context context)

@override

public void run()

if (timer % 10 == 0)

if (count_down < 0)

try catch (interruptedexception e)

} }@override

public void su***cechanged(su***ceholder arg0, int arg1, int arg2, int arg3)

@override

public void su***cecreated(su***ceholder arg0)

public boolean containspoint(int x, int y, bitmap bitmap, point point) else

} @override

public void su***cedestroyed(su***ceholder arg0)

public void logic()

} int jump_count = (int) (math.random() * 4 + 2);

// system.out.println(jump_count);

long start = system.currenttimemillis();

for (int i = 0; i < jump_count; i++)

} @override

public boolean ontouchevent(motionevent event)

}} else if (event.getaction() == motionevent.action_up)

if (!startgame)

return true;

} public void gamedraw() else if (grid[i][j] == 1)

// paint.setcolor(color.black);

// canvas.drawrect(j * blk_width, i * blk_height, (j + 1) *

// blk_width, (i + 1) * blk_height, paint);

// 邊框

// paint.setcolor(color.gray);

// paint.setstyle(paint.style.stroke);

// canvas.drawrect(j * blk_width, i * blk_height, (j + 1) *

// blk_width, (i + 1) * blk_height, paint);

}} paint scorepaint = new paint();

scorepaint.setcolor(color.red);

scorepaint.settextsize(80);

paint countdownpaint = new paint();

countdownpaint.setcolor(color.white);

countdownpaint.settextsize(40);

if (score != 0)

canvas.drawtext(count_down + "", this.getwidth() - 60, 40, countdownpaint);

sfh.unlockcanvasandpost(canvas);

} public void gameinit() else

if (startgame) catch (interruptedexception e)

if (flag)

} paintwhite.settextsize(20);

canvas.drawtext("start game", x + bmpbtn[0].getwidth() / 2 - 50, y + bmpbtn[0].getheight() / 2 + 4, paintwhite);

sfh.unlockcanvasandpost(canvas);

} public void scoreboard()

public void startgame()

}

hittherat

人生第乙個shell指令碼

有時候,不知道什麼原因,lib裡面的各種so檔案的鏈結會失效,導致依賴這些庫的各種操作都會error,所以,需要能恢復鏈結。bin bash for file in pwd do if f file then filename basename file linkfile ls filename g...

人生的第乙個Python程式

今天因為給beaubeau提供的 號碼做sql檔案,一開始收到zip檔案解開壓縮之後被嚇到了 29個csv檔案,每個檔案儲存了1000個獎券id和號碼 照上次一樣,開啟每個csv檔案做先做單獨的sql檔案,每個sql中有1000條插入語句,隨後將29個檔案的所有sql語句都複製貼上到同乙個總的sql...

第乙個遊戲 啟程 1

通過從0寫這個專案,掌握遊戲開發所說要的c c 的高階特性,快速強化c c 掌握遊戲開發的基本概念 基本流程,快速入門遊戲開發。玩遊戲是快樂的,開發遊戲同樣是快樂的,甚至更快樂,享受 造物主 的樂趣。蘋果wwdc大會上,一位82歲的日本老奶奶若宮正子,是一名銀行退休職員,成了全場最年長開發者。蘋果公...