public void move(Map world) { setOldPos(getPos()); if (frindly) { int des = 1 + rand.nextInt(4); switch (des) { case 1: moveTo(new Position(getPos().getX() - 1, getPos().getY()), world); break; case 2: moveTo(new Position(getPos().getX() + 1, getPos().getY()), world); break; case 3: moveTo(new Position(getPos().getX(), getPos().getY() - 1), world); break; case 4: moveTo(new Position(getPos().getX(), getPos().getY() + 1), world); break; case 5: break; default: } } else { if (path != null) { if (path.hasNext()) moveTo(path.getNext(), world); } if (target == null) { target = world.find_player(getPos()); } else { path = world.getGraph(getPos(), target.getPos()).findShortestPath(); } } if (getPos() == getOldPos()) setMoving(no_move); }
public void moveTo(Position target, Map world) { int diff = getPos().find_diff(target); setMoving(diff); if (world.isMovable(target.getX(), target.getY())) { setPos(target); tile.setC(null); tile = world.tileAt(target); tile.setC(this); } else { setMoving(Creature.no_move); setPath(null); setMoving(Creature.no_move); } }
public Creature(Position pos, Map world) { setMoving(5); attacked = false; setTarget(null); setTile(world.tileAt(pos)); getTile().setC(this); this.setPos(pos); this.world = world; setHp(DEF_HP); setMp(DEF_MP); setMaxhp(DEF_HP); setMaxmp(DEF_MP); setSpeed(DEF_SPEED); setActive(false); setDead(false); damageTaken = new Label(""); damageTaken.setForeground(Color.red); healTaken = new Label(""); healTaken.setForeground(Color.green); }