Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
ExplosionSprite.java
Go to the documentation of this file.
1 // This file is part of MicropolisJ.
2 // Copyright (C) 2013 Jason Long
3 // Portions Copyright (C) 1989-2007 Electronic Arts Inc.
4 //
5 // MicropolisJ is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GPLv3, with additional terms.
7 // See the README file, included in this distribution, for details.
8 
9 package micropolisj.engine;
10 
11 import static micropolisj.engine.TileConstants.*;
12 
17 public class ExplosionSprite extends Sprite {
18  protected boolean sendReport;
19  protected boolean playSound;
20 
21  public ExplosionSprite(Micropolis engine, int x, int y) {
22  this(engine, x, y, true, false);
23  }
24 
25  public ExplosionSprite(Micropolis engine, int x, int y, boolean sendReport, boolean playSound) {
26  super(engine, SpriteKind.EXP);
27  this.x = x;
28  this.y = y;
29  this.width = 48;
30  this.height = 48;
31  this.offx = -24;
32  this.offy = -24;
33  this.frame = 1;
34  // custom
35  this.sendReport = sendReport;
36  this.playSound = playSound;
37  }
38 
39  @Override
40  public void moveImpl() {
41  if(city.acycle % 2 == 0) {
42  if(this.frame == 1) {
43  if(playSound) {
44  city.makeSound(x / 16, y / 16, Sound.EXPLOSION_HIGH);
45  }
46  if(sendReport) {
47  city.sendMessageAt(MicropolisMessage.EXPLOSION_REPORT, x / 16, y / 16);
48  }
49  }
50  this.frame++;
51  }
52 
53  if(this.frame > 6) {
54  this.frame = 0;
55 
56  startFire(x / 16, y / 16);
57  startFire(x / 16 - 1, y / 16 - 1);
58  startFire(x / 16 + 1, y / 16 - 1);
59  startFire(x / 16 - 1, y / 16 + 1);
60  startFire(x / 16 + 1, y / 16 + 1);
61  return;
62  }
63  }
64 
65  void startFire(int xpos, int ypos) {
66  if(!city.testBounds(xpos, ypos))
67  return;
68 
69  int t = city.getTile(xpos, ypos);
70  if(!isCombustible(t) && t != DIRT)
71  return;
72  if(isZoneCenter(t))
73  return;
74  city.setTile(xpos, ypos, (char) (FIRE + city.PRNG.nextInt(4)));
75  }
76 }