基于Android平台的星际射击游戏的设计与实现(9)
来源:56doc.com 资料编号:5D10234 资料等级:★★★★★ %E8%B5%84%E6%96%99%E7%BC%96%E5%8F%B7%EF%BC%9A5D10234
资料介绍
case YOU: enemyx += 2; break; } enemyy += 3; } public void RelaxView() { enemy.recycle(); enemy = null; enemyBitmap = null; } public void UpdataView(Canvas canvas, Paint paint) { switch(enemytype){ case LAN_PAO: enemy = enemyBitmap[0]; ViewTools.drawImage(canvas, enemy, enemyx, enemyy, enemy.getWidth()/3, enemy.getHeight(), 0, 0, paint); break; case HONG_PAO: enemy = enemyBitmap[1]; ViewTools.drawImage(canvas, enemy, enemyx, enemyy, enemy.getWidth()/3, enemy.getHeight(), 0, 0, paint); break; case HUANG_PAO: enemy = enemyBitmap[2]; ViewTools.drawImage(canvas, enemy, enemyx, enemyy, enemy.getWidth()/3, enemy.getHeight(), 0, 0, paint); break; case LV_PAO: enemy = enemyBitmap[3]; ViewTools.drawImage(canvas, enemy, enemyx, enemyy, enemy.getWidth()/3, enemy.getHeight(), 0, 0, paint); break; case JIGUANG_PAO: enemy = enemyBitmap[4]; ViewTools.drawImage(canvas, enemy, enemyx, enemyy, enemy.getWidth()/3, enemy.getHeight(), 0, 0, paint); break; } enemywidth = enemy.getWidth(); enemyheight = enemy.getHeight(); } } (2) 我机类(Plane.Java)、敌机子弹类(EnemyPaodan.Java)、我机子弹类(PlanePaodan.Java)、地图类(MapView.Java)、爆炸类(Pengzhuang.Java)、道具类(Daoju.Java),Boss类(Boss.Java)跟敌机类的实现方法一样,都是通过实现MyViewIMP接口进行逻辑处理,图片移动和更新视图。 5.2.4 游戏工具类 本游戏定义了一个工具类用以方便各个属性类使用此类来绘制图形和检验图形之间是否发生碰撞,具体实现代码如下: public class ViewTools { public static void drawImage(Canvas c,Bitmap image, int x, int y, int w, int h, int dx,int dy,Paint mPaint) { c.save(); c.clipRect(x, y, x+w, y+h); c.drawBitmap(image, x-dx, y-dy, mPaint); c.restore(); } public static boolean intersectRect(int r1x1,int r1y1,int r1x2,int r1y2, int r2x1,int r2y1,int r2x2,int r2y2){ if(r2x1>=r1x2||r2y1>=r1y2||r2x2<=r1x1||r2y2<=r1y1){ |