public void paintComponent(Graphics g) { super.paintComponent(g); height = this.getHeight(); width = this.getWidth(); drawPlayers(g); g.setColor(Color.WHITE); g.drawString("Score", width - 60, 25); g.drawString(String.valueOf(score), width - 60, 40); if (countdownF) { g.drawString(String.valueOf(counterN), width / 2 - 10, height / 2); } else { if ((spawnCircleB) && (spawnIncrease)) { spawnCircles(); } if (spawnMonsterB) { spawnMonsters(); } if (spawnRandomersB) { spawnRandomers(); } if (spawnRainB) { spawnRain(); } if (spawnBombB()) { spawnBomb(); } try { Iterator i = enemies.iterator(); while (i.hasNext()) { Enemy e = (Enemy) i.next(); Iterator j = players.iterator(); while (j.hasNext()) { Player p = (Player) j.next(); e.move(players, programSpeedAdjust /*/players.size()*/); if ((e.collidesWith(p.getX(), p.getY())) && (!p.getImmunity())) { p.decLives(p.getX(), p.getY()); p.setImmunity(true); } } e.paint(g); } } catch (Exception e) { } } drawLayout(g); }
public void drawEnemy(Graphics g) { Graphics2D g2d = (Graphics2D) g; for (Enemy i : enemyList) { if (i.getFlip()) { g2d.drawImage( i.getPics().get(i.getCounter()), i.getX() + i.getWidth(), i.getY(), -i.getWidth(), i.getHeight(), null); // flips the image if the flip is true } else { g.drawImage( i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null); } i.count(); i.setDirection(); i.move(); } }
public void moveEnemies() { for (Enemy i : enemyList) { i.move(); } }