private void processSpec(String s, String expected) { // System.out.println(s); // System.out.println(); // System.out.println("=========="); try { Explosion explosion = new Explosion(); List<Explosion.Bird> birds = explosion.createRanges(new ByteArrayInputStream(s.getBytes("UTF-8"))); // for (int i = 0; i < birds.size(); i++) { // Explosion.Bird bird = birds.get(i); // System.out.println(bird); // } StringBuilder sb = new StringBuilder(); int[][] birdKills = explosion.process(birds); // System.out.println("----------"); // for (int i = 0; i < birds.size(); i++) { // Explosion.Bird bird = birds.get(i); // System.out.println(bird); // } for (int[] bk : birdKills) { sb.append(bk[0]).append(" ").append(bk[1]); sb.append("\n"); } Assert.assertEquals(expected, sb.toString().trim()); System.out.println(sb.toString()); // System.out.println("-------"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
public void render(Canvas canvas) { // render explosions if (explosion != null) { if (mParticeBitmap != null) explosion.draw(mParticeBitmap, canvas); else explosion.draw(canvas); } }
public void drawFromThread(Canvas canvas) { final float scaleFactorX = getWidth() / (WIDTH * 1.f); final float scaleFactorY = getHeight() / (HEIGHT * 1.f); if (canvas != null) { final int savedState = canvas.save(); canvas.scale(scaleFactorX, scaleFactorY); bg.draw(canvas); if (!dissapear) { player.draw(canvas); } // draw smokepuffs for (Smokepuff sp : smoke) { sp.draw(canvas); } // draw missiles for (Missile m : missiles) { m.draw(canvas); } // draw topborder for (TopBorder tb : topborder) { tb.draw(canvas); } // draw botborder for (BotBorder bb : botborder) { bb.draw(canvas); } // draw explosion if (started) { explosion.draw(canvas); } drawText(canvas); canvas.restoreToCount(savedState); } }
public class Flame { public static int[][] table_flames; // Position der Flammen public int case_x, case_y; // Länge der Flamme public int distance; // Richtung der Flamme public int[] direction; // Gibt an ob Flamme eine Mauer zerstören kann public boolean last; // Gibt das Ende der Flamme an; public int end; private static final int DELAY = Explosion.getDelay(); public Flame(int case_x, int case_y, int distance, int[] direction, boolean last) { this.case_x = case_x; this.case_y = case_y; this.distance = distance; this.direction = direction; this.last = last; this.end = DELAY; table_flames[case_x][case_y]++; } }
public void checkForBox(float x, float y, Direction d) { for (IGameObject o : game.playground().getMapobjects()) { if (o instanceof Box) { if (o.getX() == x && o.getY() == y) { Explosion flame = null; try { flame = new Explosion(sprites, d); } catch (SlickException ex) { Logger.getLogger(Bomb.class.getName()).log(Level.SEVERE, null, ex); } flame.setPosition(o.getX(), o.getY()); game.playground().addToLevel(flame); game.playground().removeFromLevel(o); } } } // for (Player p : game.getTeam1().getPlayers()) { // if (p.getX() == x && p.getY() == y) { // Explosion flame = null; // try { // flame = new Explosion(sprites, d); // } catch (SlickException ex) { // Logger.getLogger(Bomb.class.getName()).log(Level.SEVERE, null, ex); // } // flame.setPosition(p.getX(), p.getY()); // game.playground().addToLevel(flame); // } // } // for (Player p : game.getTeam2().getPlayers()) { // if (p.getX() == x && p.getY() == y) { // Explosion flame = null; // try { // flame = new Explosion(sprites, d); // } catch (SlickException ex) { // Logger.getLogger(Bomb.class.getName()).log(Level.SEVERE, null, ex); // } // flame.setPosition(p.getX(), p.getY()); // game.playground().addToLevel(flame); // } // } }
public void startAnimation(int x, int y) { createLog("Starting Animation"); if (explosion == null || explosion.getState() == Explosion.STATE_DEAD) { explosion = new Explosion(EXPLOSION_SIZE, x, y); } mAnimation.setDuration(mDuration); mAnimation.setInterpolator(mInterpolator); startAnimation(mAnimation); createLog("Started"); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawImage(background, 0, 0, null); g2d.setColor(Color.WHITE); for (Ship ship : facade.getShips(world)) { if (!visualizations.containsKey(ship)) { visualizations.put(ship, new ShipVisualization(Color.BLUE, ship, null)); } visualizations.get(ship).draw(g2d); } for (Asteroid asteroid : facade.getAsteroids(world)) { if (!visualizations.containsKey(asteroid)) { visualizations.put(asteroid, new AsteroidVisualization(asteroid)); } visualizations.get(asteroid).draw(g2d); } for (Bullet bullet : facade.getBullets(world)) { if (!visualizations.containsKey(bullet)) { Ship ship = facade.getBulletSource(bullet); visualizations.put( bullet, new BulletVisualization(visualizations.get(ship).getColor(), bullet)); } visualizations.get(bullet).draw(g2d); } for (Explosion explosion : explosions) { explosion.draw(g2d); } if (msg != null) { g2d.setColor(Color.WHITE); g2d.setFont(g2d.getFont().deriveFont(40f)); drawCenteredString(g2d, msg); g2d.setFont(g2d.getFont().deriveFont(20f)); drawCenteredString(g2d, "Press ESC to continue ...", getHeight() / 3 * 2); } }
public void wasExploded(World world, BlockPosition blockposition, Explosion explosion) { if (!world.isClientSide) { EntityTNTPrimed entitytntprimed = new EntityTNTPrimed( world, (double) ((float) blockposition.getX() + 0.5F), (double) blockposition.getY(), (double) ((float) blockposition.getZ() + 0.5F), explosion.getSource()); entitytntprimed.setFuseTicks( (short) (world.random.nextInt(entitytntprimed.getFuseTicks() / 4) + entitytntprimed.getFuseTicks() / 8)); world.addEntity(entitytntprimed); } }
private void onRocketLifecycle(Room room, Rocket rocket, Integer rocketBatchId) { updatePosition(rocket); Circle rocketCircle = new Circle(rocket.getxStart(), rocket.getyStart(), PersonWebSocketEndpoint.ROCKET_RADIUS); Explosion explosion = null; if (rocket.getxStart() <= 0 || rocket.getxStart() >= room.getMap().getX() || rocket.getyStart() <= 0 || rocket.getyStart() >= room.getMap().getY()) { explosion = new Explosion((int) rocket.getxStart(), (int) rocket.getyStart()); } if (explosion == null) { for (AbstractZone zone : room.getMap().getZones()) { if (!zone.isShootable()) { Point[] point = CircleService.circleBoundsIntersection( rocketCircle, new Bounds(zone.getX(), zone.getY(), zone.getWidth(), zone.getHeight())); if (point.length > 0) { explosion = new Explosion((int) point[0].getX(), (int) point[0].getY()); break; } } } } if (explosion == null) { for (Person person : room.getPersons().values()) { if (person.getId() != rocket.getPersonId()) { Circle personCircle = new Circle(person.getX(), person.getY(), PersonWebSocketEndpoint.PERSON_RADIUS); Point[] point = CircleService.circleCircleIntersection(rocketCircle, personCircle); if (point.length > 0) { explosion = new Explosion((int) point[0].getX(), (int) point[0].getY()); onDamage(room.getPersons().get(rocket.getPersonId()), rocket.getDamage(), person, room); break; } } } } if (explosion != null) { explosion.setxEnd((int) explosion.getxStart()); explosion.setyEnd((int) explosion.getyStart()); int id = gameContext.getProjectilesIds().getAndIncrement(); room.getProjectiles().put(id, new Projectile[] {explosion}); Circle explosionCircle = new Circle(explosion.getxStart(), explosion.getyStart(), explosion.getRadius()); Person shooter = room.getPersons().get(rocket.getPersonId()); for (Person person : room.getPersons().values()) { double damageFactor = PointService.pointBelongToCircle( new Point(person.getX(), person.getY()), explosionCircle); if (damageFactor > -1) { double damage = explosion.getDamage() + damageFactor * explosion.getDamageFactor(); onDamage(shooter, (int) damage, person, room); } } room.getProjectiles().remove(rocketBatchId); } }
public void update() { if (player.getPlaying()) { if (botborder.isEmpty()) { player.setPlaying(false); return; } if (topborder.isEmpty()) { player.setPlaying(false); return; } bg.update(); player.update(); // calculate the threshold of height the border can have based on the score // max and min border heart are updated, and the border switched direction when either max or // min is met maxBorderHeight = 30 + player.getScore() / progressDenom; // cap max border height so that borders can only take up a total of 1/2 the screen if (maxBorderHeight > HEIGHT / 4) maxBorderHeight = HEIGHT / 4; minBorderHeight = 5 + player.getScore() / progressDenom; // check bottom border collision for (int i = 0; i < botborder.size(); i++) { if (collision(botborder.get(i), player)) player.setPlaying(false); } // check top border collision for (int i = 0; i < topborder.size(); i++) { if (collision(topborder.get(i), player)) player.setPlaying(false); } // update top border this.updateTopBorder(); // udpate bottom border this.updateBottomBorder(); // add missiles on timer long missileElapsed = (System.nanoTime() - missileStartTime) / 1000000; if (missileElapsed > (2000 - player.getScore() / 4)) { // first missile always goes down the middle if (missiles.size() == 0) { missiles.add( new Missile( BitmapFactory.decodeResource(getResources(), R.drawable.missile), WIDTH + 10, HEIGHT / 2, 45, 15, player.getScore(), 13)); } else { missiles.add( new Missile( BitmapFactory.decodeResource(getResources(), R.drawable.missile), WIDTH + 10, (int) (rand.nextDouble() * (HEIGHT - (maxBorderHeight * 2)) + maxBorderHeight), 45, 15, player.getScore(), 13)); } // reset timer missileStartTime = System.nanoTime(); } // loop through every missile and check collision and remove for (int i = 0; i < missiles.size(); i++) { // update missile missiles.get(i).update(); if (collision(missiles.get(i), player)) { missiles.remove(i); player.setPlaying(false); smoke.clear(); break; } // remove missile if it is way off the screen if (missiles.get(i).getX() < -100) { missiles.remove(i); break; } } // add smoke puffs on timer long elapsed = (System.nanoTime() - smokeStartTime) / 1000000; if (elapsed > 120) { smoke.add(new Smokepuff(player.getX(), player.getY() + 10)); smokeStartTime = System.nanoTime(); } for (int i = 0; i < smoke.size(); i++) { smoke.get(i).update(); if (smoke.get(i).getX() < -10) { smoke.remove(i); } } } else { player.resetDY(); if (!reset) { newGameCreated = false; startReset = System.nanoTime(); reset = true; dissapear = true; explosion = new Explosion( BitmapFactory.decodeResource(getResources(), R.drawable.explosion), player.getX(), player.getY() - 30, 100, 100, 25); } explosion.update(); long resetElapsed = (System.nanoTime() - startReset) / 1000000; if (resetElapsed > 2500 && !newGameCreated) { newGame(); } } }
/** * This is the game update method. It iterates through all the objects and calls their update * method if they have one or calls specific engine's update method. */ public void update(float interpolatedTime) { // update explosions if (explosion != null && explosion.isAlive()) { explosion.update(interpolatedTime); } }
public void lookAround(Direction direction, Float range) throws SlickException { Float oldX = this.getX(); Float oldY = this.getY(); switch (direction) { case EAST: for (int r = 0; r < range; r++) { this.x += (48 + 48 * r); Explosion flameMid = new Explosion(sprites); flameMid.setPosition(oldX, oldY); game.playground().addToLevel(flameMid); if (!this.intersectWithBox() && !this.intersectWithWall()) { Explosion flame = new Explosion(sprites, Direction.EAST); flame.setPosition(oldX + 48 + 48 * r, oldY); game.playground().addToLevel(flame); checkForBase(this.getX(), this.getY()); checkForBomb(this.getX(), this.getY()); } else { checkForBox(this.getX(), this.getY(), Direction.EAST); this.x -= (48 + 48 * r); break; } this.x -= (48 + 48 * r); } break; case WEST: for (int r = 0; r < range; r++) { this.x -= (48 + 48 * r); if (!this.intersectWithBox() && !this.intersectWithWall()) { Explosion flame = new Explosion(sprites, Direction.WEST); flame.setPosition(oldX - 48 - 48 * r, oldY); game.playground().addToLevel(flame); checkForBase(this.getX(), this.getY()); checkForBomb(this.getX(), this.getY()); } else { checkForBox(this.getX(), this.getY(), Direction.WEST); this.x += (48 + 48 * r); break; } this.x += (48 + 48 * r); } break; case SOUTH: for (int r = 0; r < range; r++) { this.y += (48 + 48 * r); if (!this.intersectWithBox() && !this.intersectWithWall()) { Explosion flame = new Explosion(sprites, Direction.SOUTH); flame.setPosition(oldX, oldY + 48 + 48 * r); game.playground().addToLevel(flame); checkForBase(this.getX(), this.getY()); checkForBomb(this.getX(), this.getY()); } else { checkForBox(this.getX(), this.getY(), Direction.SOUTH); this.y -= (48 + 48 * r); break; } this.y -= (48 + 48 * r); } break; case NORTH: for (int r = 0; r < range; r++) { this.y -= (48 + 48 * r); if (!this.intersectWithBox() && !this.intersectWithWall()) { Explosion flame = new Explosion(sprites, Direction.NORTH); flame.setPosition(oldX, oldY - 48 - 48 * r); game.playground().addToLevel(flame); checkForBase(this.getX(), this.getY()); checkForBomb(this.getX(), this.getY()); } else { checkForBox(this.getX(), this.getY(), Direction.NORTH); this.y += (48 + 48 * r); break; } this.y += (48 + 48 * r); } break; } }