moveYuanHu记录该飞机按圆形轨迹运行时
小编导读:
建议使用更好的路径追踪或者更好的AI,比如启发式搜寻等模式的经典状态机实现.这种事先写死坐标然后依次绘制太死板也太原始了(对于现代游戏开发技术而言),一些经典的运行路线还可以通过贝塞尔二次,三次函数求解得到平滑的任意2D曲线,通过迭代或者矢量缩放得到你想要的精度和范围区间.这样的好处是节省大量坐标存储空间并只多一些几乎可以忽略的CPU计算量.
解决方案3:不懂,顶你
关于网友提出的“android飞机游戏敌机移动路径”问题疑问,本网通过在网上对“android飞机游戏敌机移动路径”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
在敌机移动的时候,插入下面代码,实现每次绘制canvas时,让敌机按自己设定的路径动起来。我这里设计时只是简单的直线——圆行——直线飞机路径。
在敌机管理模块,加入此段代碼。movePingXing记录该飞机直线轨迹运行时,每次canvas绘制的x、y的偏量值。moveYuanHu记录该飞机按圆形轨迹运行时,每次canvas绘制的x、y的偏量值。String中,“、”前面得是x方向坐标偏移量,后面得是y方向坐标偏移量。
描述:基础android的飞机类游戏,与前人一样,由surfaceView绘制游戏画面,另起线程控制绘制时间间隔达到动态效果。这里附上最近自己写的敌机自动飞行路径代码。请大家给点意见。
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); } }调用initMoveList1()方法后,敌机管理类就可获得一个记录敌机飞行轨迹的偏移量的ArrayList了。
解决方案2:Map<String, String> map= moveList1.get(enemy.getCurrentSecond()); String moveWay = map.get("way"); String[] zuobiao= moveWay.split(","); enemy.x += Integer.parseInt(zuobiao[0]); enemy.y += Integer.parseInt(zuobiao[1]);上面currentSecond是一个int型变量,是敌机的属性,记录敌机在画面中出现的时间。
望高手给点意见,看有什么地方能改进下。
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。否则会出现空指针异常。
热门资讯
05-25
· 整个电影渲染了一种神秘诡异的05-25
·咖喱味05-25
·恐怕要标注“心脏病人谢绝观看”05-25
·给人的感觉就是十分的高大上!点05-25
·也让技嘉全面普及了USB3.1技术05-25
·性能表现自然是不用多说05-25
·一直未告知公司并披露二者的一致05-25
·《权力的游戏》怎样书写女性和暴
传奇特荐
05-04
·《期间》评最具影响力50款科技产05-05
·虐心游戏《Choppa》评测:虐的就05-06
·慈文传媒第一季度矫正通告:上半05-19
·女主播直播斗鸡游戏 衣着暴露动05-19
·眼下就是花式告白的最佳时机05-19
·《白发魔女传》删档测试今日开启05-19
·整体音乐让游戏带入感非常不错05-20
·《诛仙手游》中还有凄凉肃杀的空05-21
·pass:深圳市巨彩科技05-21
·pass:棋牌游戏银商