private void reset() { mShip = new Ship(); mBullets.clear(); mObstacles.clear(); }
@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); } }
mShip.accelerate(tau, mMaxShipThrust, mMaxShipSpeed); if (!mShip.step(tau)) { reset(); if (mShip.collidesWith(obstacle)) { mShip.destroy(); obstacle.destroy(); break; break OuterLoop; } while (mShip.distanceTo(positionX, positionY) < minDistance);
mShip.accelerate(tau, mMaxShipThrust, mMaxShipSpeed); if (!mShip.step(tau)) { reset(); if (mShip.collidesWith(obstacle)) { mShip.destroy(); obstacle.destroy(); break; break OuterLoop; } while (mShip.distanceTo(positionX, positionY) < minDistance);
@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); } }
private void reset() { mShip = new Ship(); mBullets.clear(); mObstacles.clear(); }
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); } }
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); } }