Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
TornadoSprite.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 
14 public class TornadoSprite extends Sprite
15 {
16  static int [] CDx = { 2, 3, 2, 0, -2, -3 };
17  static int [] CDy = { -2, 0, 2, 3, 2, 0 };
18 
19  boolean flag;
20  int count;
21 
22  public TornadoSprite(Micropolis engine, int xpos, int ypos)
23  {
24  super(engine, SpriteKind.TOR);
25  this.x = xpos * 16 + 8;
26  this.y = ypos * 16 + 8;
27  this.width = 48;
28  this.height = 48;
29  this.offx = -24;
30  this.offy = -40;
31 
32  this.frame = 1;
33  this.count = 200;
34  }
35 
36  @Override
37  public void moveImpl()
38  {
39  int z = this.frame;
40 
41  if (z == 2) {
42  //cycle animation
43 
44  if (this.flag)
45  z = 3;
46  else
47  z = 1;
48  }
49  else {
50  this.flag = (z == 1);
51  z = 2;
52  }
53 
54  if (this.count > 0) {
55  this.count--;
56  }
57 
58  this.frame = z;
59 
60  for (Sprite s : city.allSprites()) {
61  if (checkSpriteCollision(s) &&
62  (s.kind == SpriteKind.AIR ||
63  s.kind == SpriteKind.COP ||
64  s.kind == SpriteKind.SHI ||
65  s.kind == SpriteKind.TRA)
66  ) {
67  s.explodeSprite();
68  }
69  }
70 
71  int zz = city.PRNG.nextInt(CDx.length);
72  x += CDx[zz];
73  y += CDy[zz];
74 
75  if (!city.testBounds(x/16, y/16)) {
76  // out of bounds
77  this.frame = 0;
78  return;
79  }
80 
81  if (this.count == 0 && city.PRNG.nextInt(501) == 0) {
82  // early termination
83  this.frame = 0;
84  return;
85  }
86 
87  destroyTile(x/16, y/16);
88  }
89 }