public static bool shootable(MainGrid grid, AbstractEntity ent)
        {
            Tank ourPlayer = grid.getTank(grid.Playername);

            if (ourPlayer.Location.X == ent.Location.X)
            {
                // Our player facing north or south
                if ((ourPlayer.Location.Y > ent.Location.Y & ourPlayer.Direction == 0) || (ourPlayer.Location.Y < ent.Location.Y & ourPlayer.Direction == 2))
                {
                    foreach (StoneWall stone in grid.StoneWalls.Values.ToList<StoneWall>())
                    {
                        // intercepting stones
                        if (MotionLogic.isInBetween(ent, ourPlayer, stone))
                        {
                            return false;
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }

            }
            else if (ourPlayer.Location.Y == ent.Location.Y)
            {
                // our player facing east or west
                if ((ourPlayer.Location.X > ent.Location.X & ourPlayer.Direction == 3) || (ourPlayer.Location.X < ent.Location.X & ourPlayer.Direction == 1))
                {
                    foreach (StoneWall stone in grid.StoneWalls.Values.ToList<StoneWall>())
                    {
                        // intercepting stones
                        if (MotionLogic.isInBetween(ent, ourPlayer, stone))
                        {
                            return false;
                        }
                    }
                    return true;

                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
Example #2
0
 // Get path for an entity
 public Stack<Node> getPathByEntity(AbstractEntity ent)
 {
     int X = (int)ent.Location.X;
     int Y = (int)ent.Location.Y;
     return getPathByNode(nodes[X, Y]);
 }
Example #3
0
 // Get next node for an entity
 public Vector2 getNextNode(AbstractEntity ent)
 {
     Stack<Node> path = getPathByEntity(ent);
     if (path.Count < 2)
     {
         return mg.Tanks[player].Location;
     }
     path.Pop();
     Node n = path.Pop();
     return new Vector2(n.getX(), n.getY());
 }