train-sprite: use constants

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@902 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-12-13 01:38:46 +00:00
parent c5b6b9db4a
commit 7f1dad1083

View file

@ -26,6 +26,12 @@ public class TrainSprite extends Sprite
static final int FRAME_SW_NE = 4; static final int FRAME_SW_NE = 4;
static final int FRAME_UNDERWATER = 5; static final int FRAME_UNDERWATER = 5;
static final int DIR_NORTH = 0;
static final int DIR_EAST = 1;
static final int DIR_SOUTH = 2;
static final int DIR_WEST = 3;
static final int DIR_NONE = 4; //not moving
public TrainSprite(Micropolis engine, int xpos, int ypos) public TrainSprite(Micropolis engine, int xpos, int ypos)
{ {
super(engine, SpriteKind.TRA); super(engine, SpriteKind.TRA);
@ -33,7 +39,7 @@ public class TrainSprite extends Sprite
this.y = ypos * 16 + TRA_GROOVE_Y; this.y = ypos * 16 + TRA_GROOVE_Y;
this.offx = -16; this.offx = -16;
this.offy = -16; this.offy = -16;
this.dir = 4; //not moving this.dir = DIR_NONE; //not moving
} }
@Override @Override
@ -51,7 +57,7 @@ public class TrainSprite extends Sprite
int d1 = city.PRNG.nextInt(4); int d1 = city.PRNG.nextInt(4);
for (int z = d1; z < d1 + 4; z++) { for (int z = d1; z < d1 + 4; z++) {
int d2 = z % 4; int d2 = z % 4;
if (this.dir != 4) { //impossible? if (this.dir != DIR_NONE) { //impossible?
if (d2 == (this.dir + 2) % 4) if (d2 == (this.dir + 2) % 4)
continue; continue;
} }
@ -61,11 +67,11 @@ public class TrainSprite extends Sprite
(c == RAILVPOWERH) || (c == RAILVPOWERH) ||
(c == RAILHPOWERV)) (c == RAILHPOWERV))
{ {
if ((this.dir != d2) && (this.dir != 4)) { if ((this.dir != d2) && (this.dir != DIR_NONE)) {
if (this.dir + d2 == 3) if (this.dir + d2 == 3)
this.frame = 3; this.frame = FRAME_NW_SE;
else else
this.frame = 4; this.frame = FRAME_SW_NE;
} }
else { else {
this.frame = TrainPic2[d2]; this.frame = TrainPic2[d2];
@ -73,18 +79,18 @@ public class TrainSprite extends Sprite
if ((c == RAILBASE) || (c == (RAILBASE+1))) { if ((c == RAILBASE) || (c == (RAILBASE+1))) {
//underwater //underwater
this.frame = 5; this.frame = FRAME_UNDERWATER;
} }
this.dir = d2; this.dir = d2;
return; return;
} }
} }
if (this.dir == 4) { if (this.dir == DIR_NONE) {
// train has nowhere to go, so retire // train has nowhere to go, so retire
this.frame = 0; this.frame = 0;
return; return;
} }
this.dir = 4; this.dir = DIR_NONE;
} }
} }
} }