@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw the ship. if (mShip != null) { mShip.draw(canvas); } // Draw bullets. int numBullets = mBullets.size(); for (int i = 0; i < numBullets; i++) { final Bullet bullet = mBullets.get(i); bullet.draw(canvas); } // Draw obstacles. int numObstacles = mObstacles.size(); for (int i = 0; i < numObstacles; i++) { final Obstacle obstacle = mObstacles.get(i); obstacle.draw(canvas); } }
public Bullet() { mPaint = new Paint(); mPaint.setStyle(Style.FILL); setSize(mBulletSize); }
for (int i = 0; i < numBullets; i++) { final Bullet bullet = mBullets.get(i); if (!bullet.step(tau)) { mBullets.remove(i); i -= 1; for (int j = 0; j < numObstacles; j++) { final Obstacle obstacle = mObstacles.get(j); if (bullet.collidesWith(obstacle)) { bullet.destroy(); obstacle.destroy(); break;
for (int i = 0; i < numBullets; i++) { final Bullet bullet = mBullets.get(i); if (!bullet.step(tau)) { mBullets.remove(i); i -= 1; for (int j = 0; j < numObstacles; j++) { final Obstacle obstacle = mObstacles.get(j); if (bullet.collidesWith(obstacle)) { bullet.destroy(); obstacle.destroy(); break;
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw the ship. if (mShip != null) { mShip.draw(canvas); } // Draw bullets. int numBullets = mBullets.size(); for (int i = 0; i < numBullets; i++) { final Bullet bullet = mBullets.get(i); bullet.draw(canvas); } // Draw obstacles. int numObstacles = mObstacles.size(); for (int i = 0; i < numObstacles; i++) { final Obstacle obstacle = mObstacles.get(i); obstacle.draw(canvas); } }
@Override public boolean step(float tau) { if (!super.step(tau)) { return false; } return !isOutsidePlayfield(); }
@Override public boolean step(float tau) { if (!super.step(tau)) { return false; } return !isOutsidePlayfield(); }
private void fire() { if (mShip != null && !mShip.isDestroyed()) { Bullet bullet = new Bullet(); bullet.setPosition(mShip.getBulletInitialX(), mShip.getBulletInitialY()); bullet.setVelocity(mShip.getBulletVelocityX(mBulletSpeed), mShip.getBulletVelocityY(mBulletSpeed)); mBullets.add(bullet); getVibrator().vibrate(20); } }
public Bullet() { mPaint = new Paint(); mPaint.setStyle(Style.FILL); setSize(mBulletSize); }
private void fire() { if (mShip != null && !mShip.isDestroyed()) { Bullet bullet = new Bullet(); bullet.setPosition(mShip.getBulletInitialX(), mShip.getBulletInitialY()); bullet.setVelocity(mShip.getBulletVelocityX(mBulletSpeed), mShip.getBulletVelocityY(mBulletSpeed)); mBullets.add(bullet); getVibrator().vibrate(20); } }