public static int Main(string[] args) { TCODConsole.initRoot(100, 75, "my game", false); TCODMap map = new TCODMap(100, 75); // first, create a new map. look under fov toolkit for more on this for (int x = 0; x < 100; x++) { // time to fill in our map details for (int y = 0; y < 75; y++) { map.setProperties(x, y, true, true); // i'm setting the entire map to walkable. here is where you need to set the walkable status, based on the map generated } } TCODPath path = new TCODPath(map, 1.0f); // here we create the path object, using our map. the diagonal movement cost here is set to 1.0f int creatureX = 25; // TCODRandom.getInstance().getInt(0, 99); // let's start our creature at a random point int creatureY = 25; //TCODRandom.getInstance().getInt(0, 74); int destinationX = 75; //TCODRandom.getInstance().getInt(0, 99); // and let's give our beast a random destination int destinationY = 50; // TCODRandom.getInstance().getInt(0, 74); path.compute(creatureX, creatureY, destinationX, destinationY); // now we compute the path while (!path.isEmpty()) { // a little while loop that ends when the destination is reached TCODConsole.root.putCharEx(creatureX, creatureY, '@', TCODColor.white, TCODColor.black); TCODConsole.flush(); // here is where we draw the creature on the screen. we won't be overwriting anything, so he'll leave a trail path.walk(ref creatureX, ref creatureY, true); // here we walk the path. by setting the last arg to true, we'll automatically recompute the path if the path is blocked TCODConsole.waitForKeypress(true); // a little something so that you can watch the movement in a action. just click any key to move } return 0; }
public void ComputePath(int origX, int origY, int destX, int destY) { if (_currentPath == null) { _currentPath = new TCODPath(_currentMap, 1.14f); } _currentPath.compute(origX, origY, destX, destY); _currentX = origX; _currentY = origY; _destX = destX; _destY = destY; }
public bool moveAI(int plaX, int plaY, TCODMap map) { counter = counter - speed; if (counter <= 0) { walk = true; counter = counter + 4; } if (walk) { walk = false; switch (ai) { case AIType.unmoveable: return(checkAttack(plaX, plaY)); case AIType.forgetful: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } case AIType.guard: TCODPath tmpPath = new TCODPath(map); tmpPath.compute(x, y, origX, origY); path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1 && tmpPath.size() < 3) { path.walk(ref x, ref y, false); return(false); } else if (path.size() == 1) { return(checkAttack(plaX, plaY)); } else { tmpPath.walk(ref x, ref y, false); return(false); } case AIType.warrior: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 8 && path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } case AIType.psycho: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } } return(false); } return(false); }
public void Update() { if (LastLevel < Level) { LevelUp(); LastLevel = Level; } if (HP <= MaxHP / 3 && Game.Current.RNG.Next(5) == 0) { BleedDirectly(); } if (TurnTimeout > 0) { TurnTimeout--; return; } if (AIType == AITypes.Zombie) { Point positionLast = new Point(Position.X, Position.Y); // Don't have a target? Let's find one! bool computedFOV = false; bool wandered = false; if (Target == null) { if (!computedFOV) { Area.Current.Map.computeFov(Position.X, Position.Y, ViewRadius, true, TCODFOVTypes.BasicFov); computedFOV = true; } if (Area.Current.Map.isInFov(Game.Current.Player.Position.X, Game.Current.Player.Position.Y)) { Target = Game.Current.Player; } } // Is our target dead or something? if (Target != null && Target.HP < 1) { Target = null; } // OK, so we're chasing a target... can we still see him? if (Target != null) { if (!computedFOV) { Area.Current.Map.computeFov(Position.X, Position.Y, ViewRadius, true, TCODFOVTypes.BasicFov); computedFOV = true; } if (Area.Current.Map.isInFov(Target.Position.X, Target.Position.Y)) { foreach (Character c in Area.Current.Characters) { if (c != this && c != Target) { Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, false); } } if (!Pathfinder.compute(Position.X, Position.Y, Target.Position.X, Target.Position.Y)) { foreach (Character c in Area.Current.Characters) { Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, true); } if (!Pathfinder.compute(Position.X, Position.Y, Target.Position.X, Target.Position.Y)) { if (!wandered) { Wander(); wandered = true; } } } else { foreach (Character c in Area.Current.Characters) { Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, true); } } } } if (Pathfinder.size() > 1) { int x, x2 = Position.X; int y, y2 = Position.Y; Pathfinder.get(0, out x, out y); MoveToPosition(new Point(x, y)); if (Position.X == x && Position.Y == y) { Pathfinder.walk(ref x2, ref y2, true); } else { Target = null; if (!wandered) { Wander(); wandered = true; } } TurnTimeout += 5 - Speed; } int dx, dy; Pathfinder.getDestination(out dx, out dy); if (Pathfinder.size() < 2 && Target != null && Target.Position.X == dx && Target.Position.Y == dy) { MeleeAttack(Target); idleTimer = 0; TurnTimeout += 2; } if (Target == null && Pathfinder.size() < 2) { if (!wandered) { Wander(); wandered = true; } } // Wander if you aren't attacking an enemy and have been standing still for too long if (positionLast == Position) { idleTimer += 1; } else { idleTimer = 0; } if (idleTimer > 3) { idleTimer = 0; if (!wandered) { Wander(); wandered = true; } } } }
public bool moveAI(int plaX, int plaY, TCODMap map) { counter = counter - speed; if (counter <= 0) { walk = true; counter = counter + 4; } if (walk) { walk = false; switch (ai) { case AIType.unmoveable: return checkAttack(plaX, plaY); case AIType.forgetful: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } case AIType.guard: TCODPath tmpPath = new TCODPath(map); tmpPath.compute(x, y, origX, origY); path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1 && tmpPath.size() < 3) { path.walk(ref x, ref y, false); return false; } else if (path.size() == 1) { return checkAttack(plaX, plaY); } else { tmpPath.walk(ref x, ref y, false); return false; } case AIType.warrior: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 8 && path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } case AIType.psycho: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } } return false; } return false; }