private void spawnRandomers() { for (int i = 0; i < randomN; i++) { float x = (float) Math.random() * width; float y = (float) Math.random() * height; float r = (float) Math.sqrt( Math.pow(((Player) players.get(0)).getX() - x, 2) + Math.pow(((Player) players.get(0)).getY() - x, 2)); while (r < distanceLimit) { x = (float) Math.random() * width; y = (float) Math.random() * height; r = (float) Math.sqrt( Math.pow(((Player) players.get(0)).getX() - x, 2) + Math.pow(((Player) players.get(0)).getY() - y, 2)); } enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders)); } spawnRandomersB = false; }
/** * Find the distance between two characters * * @param Targ Target character * @return distance */ public double Dist(GameObject Targ) { // find x squared and y squared double dx = Math.pow(((X + W / 2 * GROWTHFACTOR) - (Targ.X + Targ.W / 2 * Targ.GROWTHFACTOR)), 2); double dy = Math.pow(((Y + H / 2 * GROWTHFACTOR) - (Targ.Y + Targ.H / 2 * Targ.GROWTHFACTOR)), 2); // find distance return (Math.sqrt(dx + dy)); }
static BufferedImage addMagnitudes(BufferedImage img1, BufferedImage img2) { BufferedImage dst = new BufferedImage(img1.getWidth(), img1.getHeight(), img1.getType()); for (int y = 0; y < img1.getHeight(); ++y) { for (int x = 0; x < img1.getWidth(); ++x) { int rgb1 = img1.getRGB(x, y); int rgb2 = img2.getRGB(x, y); int r1 = (rgb1 & 0x00FF0000) >> 16; int r2 = (rgb2 & 0x00FF0000) >> 16; int r = (int) (Math.sqrt(r1 * r1 + r2 * r2) / Math.sqrt(2.0)); if (r > 255) r = 255; if (r < 0) r = 0; int g1 = (rgb1 & 0x0000FF00) >> 8; int g2 = (rgb2 & 0x0000FF00) >> 8; int g = (int) (Math.sqrt(g1 * g1 + g2 * g2) / Math.sqrt(2.0)); if (g > 255) g = 255; if (g < 0) g = 0; int b1 = rgb1 & 0x000000FF; int b2 = rgb2 & 0x000000FF; int b = (int) (Math.sqrt(b1 * b1 + b2 * b2) / Math.sqrt(2.0)); if (b > 255) b = 255; if (b < 0) b = 0; int rgb = b + (g << 8) + (r << 16); dst.setRGB(x, y, rgb); } } return dst; }