Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
HelicopterSprite.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 
17 public class HelicopterSprite extends Sprite
18 {
19  int count;
20  int destX;
21  int destY;
22  int origX;
23  int origY;
24 
25  static int [] CDx = { 0, 0, 3, 5, 3, 0, -3, -5, -3 };
26  static int [] CDy = { 0, -5, -3, 0, 3, 5, 3, 0, -3 };
27  static final int SOUND_FREQ = 200;
28 
29  public HelicopterSprite(Micropolis engine, int xpos, int ypos)
30  {
31  super(engine, SpriteKind.COP);
32  this.x = xpos * 16 + 8;
33  this.y = ypos * 16 + 8;
34  this.width = 32;
35  this.height = 32;
36  this.offx = -16;
37  this.offy = -16;
38 
39  this.destX = city.PRNG.nextInt(city.getWidth()) * 16 + 8;
40  this.destY = city.PRNG.nextInt(city.getHeight()) * 16 + 8;
41 
42  this.origX = x;
43  this.origY = y;
44  this.count = 1500;
45  this.frame = 5;
46  }
47 
48  @Override
49  public void moveImpl()
50  {
51  if (this.count > 0) {
52  this.count--;
53  }
54 
55  if (this.count == 0) {
56 
57  // attract copter to monster and tornado so it blows up more often
58  if (city.hasSprite(SpriteKind.GOD)) {
59 
60  MonsterSprite monster = (MonsterSprite) city.getSprite(SpriteKind.GOD);
61  this.destX = monster.x;
62  this.destY = monster.y;
63 
64  }
65  else if (city.hasSprite(SpriteKind.TOR)) {
66 
67  TornadoSprite tornado = (TornadoSprite) city.getSprite(SpriteKind.TOR);
68  this.destX = tornado.x;
69  this.destY = tornado.y;
70 
71  }
72  else {
73  this.destX = origX;
74  this.destY = origY;
75  }
76 
77  if (getDis(x, y, origX, origY) < 30) {
78  // made it back to airport, go ahead and land.
79  this.frame = 0;
80  return;
81  }
82  }
83 
84  if (city.acycle % SOUND_FREQ == 0) {
85  // send report, if hovering over high traffic area
86  int xpos = this.x / 16;
87  int ypos = this.y / 16;
88 
89  if (city.getTrafficDensity(xpos, ypos) > 170 &&
90  city.PRNG.nextInt(8) == 0)
91  {
92  city.sendMessageAt(MicropolisMessage.HEAVY_TRAFFIC_REPORT,
93  xpos, ypos);
94  city.makeSound(xpos, ypos, Sound.HEAVYTRAFFIC);
95  }
96  }
97 
98  int z = this.frame;
99  if (city.acycle % 3 == 0) {
100  int d = getDir(x, y, destX, destY);
101  z = turnTo(z, d);
102  this.frame = z;
103  }
104  x += CDx[z];
105  y += CDy[z];
106  }
107 }