android飞机游戏敌机移动路径是什么样的
基础android的飞机类游戏,与前人一样,由su易做图ceView绘制游戏画面,另起线程控制绘制时间间隔达到动态效果。这里附上最近自己写的敌机自动飞行路径代码。请大家给点意见。
在敌机管理模块,加入此段代易做图。movePingXing记录该飞机直线轨迹运行时,每次canvas绘制的x、y的偏量值。moveYuanHu记录该飞机按圆形轨迹运行时,每次canvas绘制的x、y的偏量值。String中,“、”前面得是x方向坐标偏移量,后面得是y方向坐标偏移量。
[java]
private static String[] movePingXing = { 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0 };
private static String[] moveYuanHu = { 5 + "," + 1, 5 + "," + 1,
4 + "," + 2, 4 + "," + 2,
3 + "," + 3,3 + "," + 3,
2 + "," + 4, 2 + "," + 4,
1 + "," + 5, 1 + "," + 5,
-1 + "," + 5,-1 + "," + 5,
-2 + "," + 4,-2 + "," + 4,
-3 + "," + 3, -3 + "," + 3,
-4 + "," + 2, -4 + "," + 2,
-5 + "," + 1, -5 + "," + 1,
-5 + "," + -1,-5 + "," + -1,
-4 + "," + -2,-4 + "," + -2,
-3 + "," + -3,-3 + "," + -3,
-2 + "," + -4,-2 + "," + -4,
-1 + "," + -5,-1 + "," + -5,
1 + "," + -5,1 + "," + -5,
2 + "," + -4,2 + "," + -4,
3 + "," + -3,3 + "," + -3,
4 + "," + -2,4 + "," + -2,
5 + "," + -1,5 + "," + -1};
private static String[] movePingXing = { 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0 };
private static String[] moveYuanHu = { 5 + "," + 1, 5 + "," + 1,
4 + "," + 2, 4 + "," + 2,
3 + "," + 3,3 + "," + 3,
2 + "," + 4, 2 + "," + 4,
1 + "," + 5, 1 + "," + 5,
-1 + "," + 5,-1 + "," + 5,
-2 + "," + 4,-2 + "," + 4,
-3 + "," + 3, -3 + "," + 3,
-4 + "," + 2, -4 + "," + 2,
-5 + "," + 1, -5 + "," + 1,
-5 + "," + -1,-5 + "," + -1,
-4 + "," + -2,-4 + "," + -2,
-3 + "," + -3,-3 + "," + -3,
-2 + "," + -4,-2 + "," + -4,
-1 + "," + -5,-1 + "," + -5,
1 + "," + -5,1 + "," + -5,
2 + "," + -4,2 + "," + -4,
3 + "," + -3,3 + "," + -3,
4 + "," + -2,4 + "," + -2,
5 + "," + -1,5 + "," + -1};
然后给出路径添加方法,把这些坐标偏移量加入到moveList1。moveList1里的内容一定要充足,必须保证在每次canvas绘制时,飞机都能得到一个有效路径的String。否则会出现空指针异常。
[java]
public static boolean initMoveList1() {
addPingXing();
addYuanHu();
addPingXing();
addPingXing();
addPingXing();
return true;
}
public static void addPingXing(){
Map<String, String> map;
for (int i = 0; i < movePingXing.length; i++) {
map = new HashMap<String, String>();
map.put("way", movePingXing[i]);
moveList1.add(map);
}
}
public static void addYuanHu(){
Map<String, String> map;
for (int i = 0; i < moveYuanHu.length; i++) {
map = new HashMap<String, String>();
map.put("way", moveYuanHu[i]);
moveList1.add(map);
}
}
public static boole
补充:移动开发 , Android ,