public void logic() { for (int i = 0; i < bullets.length; i++) { Playerbullet bullet = bullets[i]; if (bullet.status == Playerbullet.NONE) continue; bullet.logic(); } // end for i for (int i = 0; i < MAX_MISSILE_NUM; i++) { missiles[i].logic(); } if ((loadgunCount++) % 40 == 0) { gun_curBullet_num++; if (gun_curBullet_num > gun_bullet_max) { gun_curBullet_num = gun_bullet_max; } } // end if if (loadMissileProgress < LOAD_MISSILE_MAX) { loadMissileProgress++; } gunNumRect.right = gunNumRect.left + gun_curBullet_num * each_gun_panel_width; missileReloadProgress.set( missilePanelProgress_x, missilePanelProgress_y, missilePanelProgress_x + ((float) loadMissileProgress / LOAD_MISSILE_MAX) * missilePanel_width, missilePanelProgress_y + missileIconBitmap.getHeight()); }
public void draw(Canvas canvas) { canvas.drawBitmap(gunIconBitmap, gunIconSrc, gunIconDst, null); canvas.drawRect(gunNumRect, gunIconPaint); canvas.drawBitmap(missileIconBitmap, missileIconRect, missileIconDst, null); canvas.drawRect(missileReloadProgress, missilePanelPaint); for (int i = 0; i < bullets.length; i++) { Playerbullet bullet = bullets[i]; bullet.draw(canvas); } // end for i for (int i = 0; i < MAX_MISSILE_NUM; i++) { missiles[i].draw(canvas); } }
public void fire() { if (gun_curBullet_num <= 0) { return; } if (System.currentTimeMillis() - preFiretime < 200) { // 控制发射频率 return; } preFiretime = System.currentTimeMillis(); firebulletIndex = (firebulletIndex + 1) % MAX_BULLET_NUM; Playerbullet bulletLeft = bullets[firebulletIndex]; bulletLeft.status = Playerbullet.SHOW; bulletLeft.x = player.x + 4; bulletLeft.y = player.y; firebulletIndex = (firebulletIndex + 1) % MAX_BULLET_NUM; Playerbullet bulletRight = bullets[firebulletIndex]; bulletRight.status = Playerbullet.SHOW; bulletRight.x = player.x + player.width - 4; bulletRight.y = player.y; // 播放子弹发射音效 player.context.mSoundPlayer.playSound(R.raw.gun_sound); gun_curBullet_num--; }