public void moveLayerThree(Graphics g) { backy += (int) (player1.getVelocity() * 0.1); midy += (int) (player1.getVelocity() * 0.5); drawEnemy(g); drawCoin(g); drawBox(g); drawPoof(g); drawStar(g); drawJumper(g); drawSpike(g); drawPup(g); if (backy <= dieHeight) { // System.out.println(die); g.drawImage(player1.move(2), player1.getX(), player1.getY(), this); if (player1.animationComplete()) { die = true; } } else { if (backy <= dieHeight) { player1.resetCounter(); } if (keys[KeyEvent.VK_RIGHT]) { g.drawImage(player1.move(1), player1.getX(), player1.getY(), this); } else if (keys[KeyEvent.VK_LEFT]) { g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this); } else { g.drawImage(player1.move(0), player1.getX(), player1.getY(), this); } } }
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 paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.drawImage(img, 0, 0, null); g2d.drawImage(p.getImage(), p.getX(), p.getY(), null); }
private void drawPlayers(Graphics g) { Iterator i = players.iterator(); Player p; while (i.hasNext()) { p = (Player) i.next(); if (p.isActive()) { if (p.getImmunity()) { g.setColor(Color.red.brighter()); g.drawOval(p.getX() - 30, p.getY() - 30, 60, 60); } g.setColor(Color.WHITE); g.fillOval(p.getX() - 5, p.getY() - 5, 10, 10); } p.paint(g); } }
public void drawPowerUpEffect(Graphics g) { if (player1.getPower().equals("Magnet")) { Image magpic = magnetList.get((int) count % 6); g.drawImage( magpic, player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2), player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2), magpic.getWidth(null), magpic.getHeight(null), this); count += 0.1; } else if (player1.getPower().equals("Ball")) { g.drawImage( ballPower, player1.getX() - ballPower.getWidth(null) / 2 + 17, player1.getY() + player1.getHeight() - 20, ballPower.getWidth(null), ballPower.getHeight(null), this); } else if (player1.getPower().equals("Sheild")) { g.drawImage( sheildPower, player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2), player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2), sheildPower.getWidth(null), sheildPower.getHeight(null), this); } else if (player1.getPower().equals("Umbrella")) { g.drawImage( umbrellaPower, player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20, player1.getY() - umbrellaPower.getHeight(null) + 40, umbrellaPower.getWidth(null), umbrellaPower.getHeight(null), this); } else if (player1.getPower().equals("")) { } }
public void loseCoins() { int x = player1.getX(); int y = player1.getY(); double losePercentage = 0.1; for (int i = 0; i < (int) coins * losePercentage; i++) { // makes the user lose 10 percent of the coin and draws them in a circle // System.out.println(i); int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i))); int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i))); coinList.add(new Coin(xPos, yPos, 3)); } coins -= (int) (coins * losePercentage); }
private void drawLayout(Graphics g) { g.setColor(Color.blue); g.drawRect(10, 10, width - 20, height - 20); g.setColor(Color.red.brighter()); Iterator f = players.iterator(); int lifeDisplayPosition = 0; while (f.hasNext()) { Player h = (Player) f.next(); if (h.isActive()) { lifeDisplayPosition++; String lifeInformation = "Player " + lifeDisplayPosition + ": "; for (int i = 0; i < h.getLives(); i++) { lifeInformation += "\u2606"; } g.drawString(lifeInformation, 20, lifeDisplayPosition * 40); } } borders[2] = width - 20; borders[3] = height - 20; Iterator i = players.iterator(); Player p; while (i.hasNext()) { p = (Player) i.next(); if (p.isActive() && !countdownF && (p.getX() < borders[0] || p.getY() < borders[1] || p.getX() > borders[2] || p.getY() > borders[3]) && (!p.getImmunity())) { p.decLives(width / 2, height / 2); p.setImmunity(true); } if (p.getLives() <= 0) { if (p instanceof MouseControlledPlayer) { MouseControlledPlayer m = (MouseControlledPlayer) p; removeMouseListener(m); removeMouseMotionListener(m); } else if (p instanceof KeyboardControlledPlayer) { KeyboardFocusManager.getCurrentKeyboardFocusManager() .removeKeyEventDispatcher((KeyboardControlledPlayer) p); } i.remove(); for (int h = 0; h < 4; h++) { if (deathLocation[h] == -1) { deathLocation[h] = p.getX(); deathLocation[h + 1] = p.getY(); break; } } } } if ((deathLocation[0] != -1) && (deathLocation[1] != -1)) { g.drawLine( deathLocation[0] - 15, deathLocation[1] - 15, deathLocation[0] + 15, deathLocation[1] + 15); g.drawLine( deathLocation[0] + 15, deathLocation[1] - 15, deathLocation[0] - 15, deathLocation[1] + 15); } if ((deathLocation[2] != -1) && (deathLocation[3] != -1)) { g.drawLine( deathLocation[2] - 15, deathLocation[3] - 15, deathLocation[2] + 15, deathLocation[3] + 15); g.drawLine( deathLocation[2] + 15, deathLocation[3] - 15, deathLocation[2] - 15, deathLocation[3] + 15); } if (!onePlayerAlive) { Font old = g.getFont(); g.setFont(new Font("monospaced", Font.BOLD, 20)); g.setColor(Color.red.darker()); g.drawString("GAME OVER", width / 2 - 40, height / 2); g.setFont(old); g.setColor(Color.WHITE); g.drawString("Score", width - 60, 25); g.drawString(String.valueOf(score), width - 60, 40); } }