Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
AirplaneSprite.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 AirplaneSprite extends Sprite
18 {
19  int destX;
20  int destY;
21 
22  // Note: frames 1-8 used for regular movement
23  // 9-11 used for Taking off
24  static int [] CDx = { 0, 0, 6, 8, 6, 0, -6, -8, -6, 8, 8, 8 };
25  static int [] CDy = { 0, -8, -6, 0, 6, 8, 6, 0, -6, 0, 0, 0 };
26 
27  public AirplaneSprite(Micropolis engine, int xpos, int ypos)
28  {
29  super(engine, SpriteKind.AIR);
30  this.x = xpos * 16 + 8;
31  this.y = ypos * 16 + 8;
32  this.width = 48;
33  this.height = 48;
34  this.offx = -24;
35  this.offy = -24;
36 
37  this.destY = this.y;
38  if (xpos > engine.getWidth()-20) {
39  // not enough room to east of airport for taking off
40  this.destX = x - 200;
41  this.frame = 7;
42  }
43  else {
44  this.destX = x + 200;
45  this.frame = 11;
46  }
47  }
48 
49  @Override
50  public void moveImpl()
51  {
52  int z = this.frame;
53 
54  if (city.acycle % 5 == 0) {
55  if (z > 8) { //plane is still taking off
56  z--;
57  if (z < 9) { z = 3; }
58  this.frame = z;
59  }
60  else { // go to destination
61  int d = getDir(x, y, destX, destY);
62  z = turnTo(z, d);
63  this.frame = z;
64  }
65  }
66 
67  if (getDis(x, y, destX, destY) < 50) { // at destination
68  //FIXME- original code allows destination to be off-the-map
69  destX = city.PRNG.nextInt(city.getWidth()) * 16 + 8;
70  destY = city.PRNG.nextInt(city.getHeight()) * 16 + 8;
71  }
72 
73  if (!city.noDisasters) {
74  boolean explode = false;
75 
76  for (Sprite s : city.allSprites()) {
77  if (s != this &&
78  (s.kind == SpriteKind.AIR || s.kind == SpriteKind.COP) &&
79  checkSpriteCollision(s))
80  {
81  s.explodeSprite();
82  explode = true;
83  }
84  }
85  if (explode) {
86  explodeSprite();
87  }
88  }
89 
90  this.x += CDx[z];
91  this.y += CDy[z];
92  }
93 }