/** * Overridden paintComponent method is called by the Swing framework when this component needs to * be redrawn. NEVER call this method yourself. */ @Override public void paintComponent(Graphics g) { Color savedColor = g.getColor(); // paint background ((Graphics2D) g).setBackground(Color.BLACK); g.clearRect(0, 0, getWidth(), getHeight()); // draw everybody for (Sprite s : getAllSprites()) { s.draw(g); } // restore g.setColor(savedColor); }
public void actionPerformed(ActionEvent event) { // update state and then call repaint() for (Sprite s : getAllSprites()) { s.update(); } if (player.collides(platform)) { player.setBallistic(false); player.setPosition(player.getXExact(), platform.getYExact() - player.getHeight()); player.setDirection(player.getDx(), 0); } for (Sprite e : platform.getChildren()) { if (player.collides(e)) { e.markForDeletion(); Renderer r = new ExplosionRenderer(40, Color.ORANGE, Color.BLACK); explosion = new Explosion(e.getX(), e.getY(), SIZE, SIZE, r, 40); } } platform.deleteMarkedChildren(); if (explosion != null && explosion.shouldDelete()) explosion = null; repaint(); }