コード例 #1
0
        public Enemy(int xLoc, int yLoc, int eWidth, int eHeight, enemyType t)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width = eWidth;
            height = eHeight;

            last_dir = dir = PlayerDir.UP;
            cur_target = null;
            col_tok = null;
            //creates the lowest level of enemy
            if (t == enemyType.GRUNT)
            {
                eType = t;
                attack = 2;
                speed = 2;
                max_health = health = 10;
            }
            //creates the second level of enemy
            else if (t == enemyType.BEETLE)
            {
                eType = t;
                attack = 5;
                speed = 2;
                max_health = health = 10;
            }
            //creates toughest level of enemy
            else if (t == enemyType.BERSERKER)
            {
                eType = t;
                attack = 5;
                speed = 3;
                max_health = health = 15;
            }
            else if (t == enemyType.TROOPER)
            {
                eType = t;
                attack = 5;
                speed = 2;
                max_health = health = 20;

            }
        }
コード例 #2
0
 // tell the monsters what path to travel
 public void setPath(List<Node> _path)
 {
     path = _path;
     if (path.Count() == 0)
     {
         cur_target = null;
         return;
     }
     cur_target = path.First();
     path.Remove(path.First());
 }
コード例 #3
0
 public void nextTarget()
 {
     if (path.Count() == 0)
     {
         cur_target = null;
         return;
     }
     cur_target = path.First();
     path.Remove(path.First());
 }
コード例 #4
0
 Node SearchOpenList(Node to_find)
 {
     for (int i = 0; i < open_list.Count(); ++i)
     {
         Node temp = open_list.ElementAt(i);
         if ((temp.loc_x == to_find.loc_x) && (temp.loc_y == to_find.loc_y))
         {
             return temp;
         }
     }
     return null;
 }
コード例 #5
0
        List<Node> GetNeighbors(Node node)
        {
            Node top = new Node(node.loc_x, node.loc_y - 1, node.loc_x, node.loc_y);
            Node bottom = new Node(node.loc_x, node.loc_y + 1, node.loc_x, node.loc_y);
            Node left = new Node(node.loc_x - 1, node.loc_y, node.loc_x, node.loc_y);
            Node right = new Node(node.loc_x + 1, node.loc_y, node.loc_x, node.loc_y);

            List<Node> ret_val = new List<Node>();

            Tile t_top = back_layer.getTile(top.loc_x, top.loc_y);
            if (!t_top.hasCollision())
            {
                ret_val.Add(top);
            }

            Tile t_bottom = back_layer.getTile(bottom.loc_x, bottom.loc_y);
            if (!t_bottom.hasCollision())
            {
                ret_val.Add(bottom);
            }

            Tile t_left = back_layer.getTile(left.loc_x, left.loc_y);
            if (!t_left.hasCollision())
            {
                ret_val.Add(left);
            }

            Tile t_right = back_layer.getTile(right.loc_x, right.loc_y);
            if (!t_right.hasCollision())
            {
                ret_val.Add(right);
            }

            return ret_val;
        }
コード例 #6
0
        public List<Node> FindPath(int cur_x, int cur_y, int target_x, int target_y)
        {
            Node start = new Node(cur_x, cur_y, -1, -1);
            open_list.Add(start);

            Node last = null;
            List<Node> ret_val = new List<Node>();

            while (open_list.Count() > 0)
            {
                Node x = open_list.Min(nodey => nodey);
                open_list.Remove(x);
                which_list[x.loc_x, x.loc_y] = WhichList.CLOSED;
                closed_list[x.loc_x, x.loc_y] = x;

                List<Node> neighbors = GetNeighbors(x);
                for (int i = 0; i < neighbors.Count(); ++i)
                {
                    Node temp = neighbors.ElementAt(i);
                    temp.G = x.G + 10;

                    int t_H_x = Math.Abs(target_x - temp.loc_x) * 10;
                    int t_H_y = Math.Abs(target_y - temp.loc_y) * 10;
                    temp.H += t_H_x + t_H_y;

                    if (temp.loc_x == target_x && temp.loc_y == target_y)
                    {
                        last = temp;
                        break;
                    }

                    WhichList TheList = which_list[temp.loc_x, temp.loc_y];

                    if (TheList == WhichList.NONE)
                    {
                        which_list[temp.loc_x, temp.loc_y] = WhichList.OPEN;
                        open_list.Add(temp);
                    }
                    else if (TheList == WhichList.OPEN)
                    {
                        Node old_node = SearchOpenList(temp);
                        if (old_node.G > temp.G)
                        {
                            old_node.G = temp.G;
                            old_node.parent_x = temp.parent_x;
                            old_node.parent_y = temp.parent_y;
                        }
                    }
                }
            }

            if (last == null)
            {
                return ret_val;
            }
            else
            {
                int next_x = last.parent_x;
                int next_y = last.parent_y;
                ret_val.Add(last);
                while (next_x != -1 && next_y != -1)
                {
                    Node t = closed_list[next_x, next_y];
                    ret_val.Add(t);
                    next_x = t.parent_x;
                    next_y = t.parent_y;
                }

            }
            ret_val.Reverse();
            return ret_val;
        }