android 遊戲學習(jbox2d)

2021-09-01 10:36:05 字數 4645 閱讀 6547

匯入jbox2d-2.0.1-library-only.jar

/*** 矩形物件

** @time 上午11:17:09

* @author retacn yue

* @email [email protected]

*/public class myrect

public void drawrect(canvas canvas, paint paint)

public void setx(float x)

public void sety(float y)

public void setangle(float angle)

public float getwidth()

public float getheight()

}/**

* 磚塊

** @time 上午11:17:44

* @author retacn yue

* @email [email protected]

*/public class mytitle

public float getx()

public void setx(float x)

public float gety()

public void sety(float y)

public void setwidth(float w)

public void setheight(float h)

public float getwidth()

public float getheight()

public void setangle(float angle)

/*** 繪製磚塊

*/public void draw(canvas canvas, paint paint)

}/**

* 遊戲主介面

** @time 上午11:18:15

* @author retacn yue

* @email [email protected]

*/@suppresswarnings("unused")

public class buildhoursesu***ceview extends su***ceview implements callback, runnable ;

private int temp;

private boolean isdeletejoint;

private boolean isdown;

private int isdowncount;

/*** 建構函式

** @param context

*/public buildhoursesu***ceview(context context)

@override

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

@override

public void su***cechanged(su***ceholder holder, int format, int width, int height)

@override

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

/*** 建立距離關節

** @param body1

* @param body2

* @return

*/public distancejoint createdistancejoint(body body1, body body2)

/*** 建立磚塊

** @param x

* @param y

* @param w

* @param h

* @param angle

* @param isstation

* @return

*/private body createmytitle(float x, float y, float w, float h, float angle, boolean isstation) else

polygondef.friction = 0.8f;// 摩擦力

polygondef.restitution = 0.3f;// 恢復力

// 快捷成盒子

polygondef.setasbox(w / 2 / rate, h / 2 / rate);

polygondef.filter.groupindex = 2;

// 建立乙個剛體

bodydef def = new bodydef();

// 設定剛體的座標

def.position.set((x + w / 2) / rate, (y + h / 2) / rate);

// 設定角度

def.angle = (float) (angle * math.pi / 180);

def.angle = (float) (angle * math.pi / 180);

random = new random();

temp = random.nextint(3);//

// 隨機取背景

switch (temp)

body body = world.createbody(def);// 建立乙個物體

body.m_userdata = new mytitle(x, y, w, h, bmp_bg);

// 設定**

body.createshape(polygondef);

// 整個物體計算打包

body.setmassfromshapes();

return body;

}/**

* 建立固定body

** @param x

* @param y

* 座標

* @param w

* @param h

* 高寬

* @param angle

* 角度

* @param isstation

* 是否為靜態

* @return

*/private body createpolygon(float x, float y, float w, float h, float angle, boolean isstation) else

// 設定摩擦力

polygondef.friction = 0.8f;

// 設定恢復力

polygondef.restitution = 0.3f;

// 快捷成盒子

polygondef.setasbox(w / 2 / rate, h / 2 / rate);

// 建立乙個剛體

bodydef def = new bodydef();

def.position.set((x + w / 2) / rate, (y + h / 2) / rate);// 設定剛體的座標

def.angle = (float) (angle * 180 / math.pi);// 設定角度

body body = world.createbody(def);

body.m_userdata = new myrect(x, y, w, h);

body.createshape(polygondef);// 設定**

body.setmassfromshapes();// 整個物體打包

return body;

}/**

* 繪製方法

*/private void draw() else if ((body.m_userdata) instanceof mytitle)

body = body.m_next;

}if (null != bodywall && null != bodyhouse) }}

} catch (exception e) finally }}

/*** 遊戲邏輯

*/private void logic() else if ((body.m_userdata) instanceof mytitle)

body = body.m_next;

}if (isdeletejoint)

// 動態body是否下落

if (isdown == true) }}

@suppresswarnings("static-access")

@override

public void run() catch (interruptedexception e) }}

/*** 重寫觸屏方法

** @param event

* @return

*/@override

public boolean ontouchevent(motionevent event)

}return true;}}

/*** 建房子主介面

** @time 上午11:18:56

* @author retacn yue

* @email [email protected]

*/public class mainactivity extends activity

}

Android 遊戲程式設計

android 遊戲程式設計,我之前也看了 從零開始 android遊戲程式設計 挺好的,當時也是搞了搞 最後飛機大戰那個demo 挺好玩。而且之前看了乙個人寫的文章,他說他就是用了飛機大戰這個demo搞到第乙份工作,然後3年成了技術總監。這個人的名字我也忘了。之前看過他部落格,感覺也挺簡單,正是如...

android遊戲開發

1 容器我們準備自定義viewgroup 叫做game2048layout 裡面的塊塊自定義view 叫做game2048item 接下來從簡單的開始 2 game2048item game2048item是個view,並且需要哪些屬性呢?首先得有個number,顯示數字嘛,然後繪製的時候根據num...

Android遊戲引擎《Rokon》

android遊戲引擎 rokon 主要類和方法的介紹文件 android遊戲引擎 rokon 學習筆記一 為你的專案新增rokon框架 android遊戲引擎 rokon 學習筆記二 helloworld android遊戲引擎 rokon 學習筆記三 精靈類sprites的使用 android遊...