for (int i = 0; i < numObstacles; i++) { final Obstacle obstacle = mObstacles.get(i); if (!obstacle.step(tau)) { mObstacles.remove(i); i -= 1; if (bullet.collidesWith(obstacle)) { bullet.destroy(); obstacle.destroy(); break; if (mShip.collidesWith(obstacle)) { mShip.destroy(); obstacle.destroy(); break; float velocityY = (float) Math.sin(direction) * speed; Obstacle obstacle = new Obstacle(); obstacle.setPosition(positionX, positionY); obstacle.setSize(size); obstacle.setVelocity(velocityX, velocityY); mObstacles.add(obstacle);
@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); } }
for (int i = 0; i < numObstacles; i++) { final Obstacle obstacle = mObstacles.get(i); if (!obstacle.step(tau)) { mObstacles.remove(i); i -= 1; if (bullet.collidesWith(obstacle)) { bullet.destroy(); obstacle.destroy(); break; if (mShip.collidesWith(obstacle)) { mShip.destroy(); obstacle.destroy(); break; float velocityY = (float) Math.sin(direction) * speed; Obstacle obstacle = new Obstacle(); obstacle.setPosition(positionX, positionY); obstacle.setSize(size); obstacle.setVelocity(velocityX, velocityY); mObstacles.add(obstacle);
@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; } wrapAtPlayfieldBoundary(); return true; }
@Override public boolean step(float tau) { if (!super.step(tau)) { return false; } wrapAtPlayfieldBoundary(); return true; }