public static void buildingDamaged(float x, float y, float gain) { int bash = Util.random(0, NUM_BASHES - 1); float pitch = (float) Math.random() / 20.0f; Game.allocateSound( instance.bashDistantBuffer[bash], Worm.calcGain(x, y) * gain, 1.0f - pitch, Game.class); Game.allocateSound( instance.bashBuffer[bash], Worm.calcGain(x, y) * gain, 1.0f - pitch, Game.class); }
/** * Gets the mouse pointer we should use when hovering over this entity * * @param clicked Whether the mouse is being clicked * @return a Mouse pointer appearance */ public LayersFeature getMousePointer(boolean clicked) { if (Worm.getGameState().inRangeOfCapacitor()) { return Worm.getGameState().isBezerk() ? Res.getMousePointerBezerkOnTarget() : Res.getMousePointerOnTarget(); } else { return Res.getMousePointer(); } }
public static void buildingDestroyed(float x, float y, float gain) { int bash = Util.random(0, NUM_BUILDING_DESTROYED - 1); Game.allocateSound( instance.buildingDestroyedDistantBuffer[bash], Worm.calcGain(x, y) * gain, 1.0f, Game.class); Game.allocateSound( instance.buildingDestroyedBuffer[bash], Worm.calcGain(x, y) * gain, 1.0f, Game.class); }
/** Returns the total life for a given team */ public int getTotalLifeFor(Team team) { int life = 0; for (Worm worm : getWorms()) { if (worm.getTeam().equals(team)) { life += worm.getLife(); } } return life; }
public List<Line2D> getHorizontalLines() { final List<Line2D> result = new ArrayList<Line2D>(); for (int i = 0; i < worm.size() - 1; i++) { final Point2D pt1 = worm.get(i); final Point2D pt2 = worm.get(i + 1); if (pt1.getY() == pt2.getY()) { final Line2D line = new Line2D.Double(pt1, pt2); result.add(line); } } return result; }
/** Returns a Map of teams that each has it's worms */ public Map<Team, List<Worm>> getByTeams() { Map<Team, List<Worm>> teams = new HashMap<>(); for (Worm worm : getWorms()) { List<Worm> team = teams.get(worm.getTeam()); if (team == null) { team = new ArrayList<>(); teams.put(worm.getTeam(), team); } team.add(worm); } return teams; }
/** Returns the first worm found with the most life */ public Worm getMostLivelyWorm() { Worm lively = getWorms().get(0); for (Worm worm : getWorms()) { if (worm.getLife() > lively.getLife()) { lively = worm; } } return lively; }
/** Returns the first worm that has a life of 0 or null if all the worms are alive. */ public Worm getFirstDeadWorm() { Worm dead = null; for (Worm worm : getWorms()) { if (!worm.isAlive()) { dead = worm; break; } } return dead; }
/** Returns a comma separated string of the worm names */ public String getCommaSeparatedNames() { String names = ""; int size = getWorms().size(); for (Worm worm : getWorms()) { if (getWorms().get(size - 1).equals(worm)) { names += worm.getName(); } else { names += worm.getName() + ", "; } } return names; }
/** Returns a unique list of names separated by commas */ public String getUniqueCommaSeparatedNames() { Set<String> names = new HashSet<>(); for (Worm worm : getWorms()) { names.add(worm.getName()); } String result = ""; Iterator<String> it = names.iterator(); while (it.hasNext()) { result += it.next(); if (it.hasNext()) { result += ", "; } } return result; }
private Point2D getTextBlockPosition(StringBounder stringBounder) { final Point2D pt1 = worm.get(0); final Point2D pt2 = worm.get(1); final Dimension2D dim = textBlock.calculateDimension(stringBounder); final double y = (pt1.getY() + pt2.getY()) / 2 - dim.getHeight() / 2; return new Point2D.Double(Math.max(pt1.getX(), pt2.getX()) + 4, y); }
public void drawInternal(UGraphic ug) { if (color.size() > 1) { drawRainbow(ug); } else { worm.drawInternalOneColor( ug, color.getColors().get(0), 1.5, emphasizeDirection, endDecoration); drawInternalLabel(ug); } }
public static WormsManager createRandom(int capacity) { WormsManager manager = new WormsManager(); for (int i = 0; i < capacity; i++) { manager.getWorms().add(Worm.createRandom()); } return manager; }
@Override public final void spawn(Screen screen) { createSprites(screen); if (sprite == null) { remove(); return; } active = true; Worm.getGameState().addEntity(this); doSpawn(); update(); }
private void drawRainbow(UGraphic ug) { final List<HtmlColorAndStyle> colors = color.getColors(); final int colorArrowSeparationSpace = color.getColorArrowSeparationSpace(); final double move = 2 + colorArrowSeparationSpace; final WormMutation mutation = WormMutation.create(worm, move); final double globalMove = -1.0 * (colors.size() - 1) / 2.0; Worm current = worm.moveFirstPoint(mutation.getFirst().multiplyBy(globalMove)); if (mutation.size() > 2) { current = current.moveLastPoint(mutation.getLast().multiplyBy(globalMove)); } for (int i = 0; i < colors.size(); i++) { double stroke = 1.5; if (colorArrowSeparationSpace == 0) { stroke = i == colors.size() - 1 ? 2.0 : 3.0; } current.drawInternalOneColor(ug, colors.get(i), stroke, emphasizeDirection, endDecoration); current = mutation.mute(current); } final UTranslate textTranslate = mutation.getTextTranslate(colors.size()); drawInternalLabel(ug.apply(textTranslate)); }
/** Remove the entity */ @Override public final void remove() { removeSprites(); if (!active) { // Already removed return; } active = false; Worm.getGameState().removeEntity(this); if (node != null) { node.remove(this); node = null; } doRemove(); }
public static void ricochet(float x, float y, float gain) { int ric = Util.random(0, NUM_RICOCHETS - 1); Game.allocateSound(instance.ricochetBuffer[ric], Worm.calcGain(x, y) * gain, 1.0f, Game.class); }
public static void blastMineReady(float x, float y) { Game.allocateSound(instance.blastMineReadyBuffer, Worm.calcGain(x, y), 1.0f, Game.class); }
private Point2D getFirst() { return worm.get(0); }
public Point2D getLast() { return worm.get(worm.size() - 1); }
/** * Can we see this location? * * @param mapX * @param mapY * @param positive If non null, if this entity is detected, algorithm returns true * @param targetFlying If true, and positive is a flying gidrah, we ignore walls and simply return * true * @return true if there is a LOS to the specified map location */ public boolean canSee(float mapX, float mapY, Entity positive, boolean targetFlying) { if (targetFlying && positive != null && positive.isFlying()) { return true; } WormGameState gameState = Worm.getGameState(); GameMap map = gameState.getMap(); ArrayList<Entity> entities = gameState.getEntities(); int n = entities.size(); // Create a list of solid entities we think are somewhere in the LOS ENTITYCACHE.clear(); for (int i = 0; i < n; i++) { Entity e = entities.get(i); if (e != this && e.isActive() && e.isSolid()) { double dist = Util.distanceFromLineToPoint(getX(), getY(), mapX, mapY, e.getX(), e.getY()); if (dist >= 0.0 && dist <= e.getRadius()) { ENTITYCACHE.add(e); } } } int numCachedEntities = ENTITYCACHE.size(); BRESENHAM.plot((int) getX(), (int) getY(), (int) mapX, (int) mapY); int oldMapX = -1, oldMapY = -1; while (BRESENHAM.next()) { int x = BRESENHAM.getX() / MapRenderer.TILE_SIZE; int y = BRESENHAM.getY() / MapRenderer.TILE_SIZE; if (x != oldMapX || y != oldMapY) { for (int z = 0; z < GameMap.LAYERS; z++) { Tile tile = map.getTile(x, y, z); if (tile != null && !tile.isBulletThrough()) { // Tile blocks LOS return false; } } oldMapX = x; oldMapY = y; } // Check entity list if (positive != null) { for (int i = 0; i < numCachedEntities; i++) { Entity e = ENTITYCACHE.get(i); if (e == positive && e.getDistanceTo(BRESENHAM.getX(), BRESENHAM.getY()) < e.getRadius()) { return true; } } } // Skip 4 pixels at a time if (!BRESENHAM.next()) { break; } if (!BRESENHAM.next()) { break; } if (!BRESENHAM.next()) { break; } } return true; }
public static void crystalSpawned(float x, float y) { Game.allocateSound(instance.crystalSpawnedBuffer, Worm.calcLoudGain(x, y), 1.0f, Game.class); }
public void addPoint(double x, double y) { worm.addPoint(x, y); }
public static void repair(float x, float y) { Game.allocateSound(instance.repairBuffer, Worm.calcGain(x, y), 1.0f, Game.class); }
@Override public String toString() { return worm.toString(); }