Ejemplo n.º 1
0
 //this method will not look like this at all. just an idea infrastructure
 public void attack(Player checker, List<NPC> entities)
 {
     for (int k = 0; k < entities.Count; k++)
     {
         entities[k].takeDamage(damageFormula(checker, entities[k]));
     }
 }
Ejemplo n.º 2
0
 public void attack(NPC checker, Player entity)
 {
     //check to see if NPC attacks Player
     if (checker.withinRange)
     {
         confirmedHit(checker, entity);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            player = new Player(new Vector2(400, 300), "Player1");
            ListHolder.Instance.NPCList = new List<NPC>();
            ListHolder.Instance.WallList = new List<Wall>();
            ListHolder.Instance.setGame(this);
            ListHolder.Instance.player = player;

            //initialize map npc spawns
            MakeNPCList(levelOneLayout);
            pathfinding = new Pathfinding(level1);
            ListHolder.Instance.setPathFinder(pathfinding);
            //path = pathfinding.FindPath(startPoint, endPoint);
            //newPath = pathfinding.FindPath(TSP, TEP);

            Vector2 start = new Vector2(startPoint.X*50, startPoint.Y*50);
            Vector2 end = new Vector2(endPoint.X * 50, endPoint.Y * 50);
            npcMover = new NPC(start, "NPC");

               // pathEndPoint = new GameObject(Content.Load<Texture2D>("endPoint"),end);

            base.Initialize();
        }
Ejemplo n.º 4
0
        public bool wallCollision(Player player, List<Wall> walls)
        {
            foreach (Wall w in walls)
            {
                if (player.rectangle.Intersects(w.rectangle))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 5
0
 public void setPlayer(Player NewPlayer)
 {
     player=NewPlayer;
 }
Ejemplo n.º 6
0
        //Proximity Sensor
        public void Proximity(Player owner, int radius, List<NPC> npcs)
        {
            List<NPC> prox = new List<NPC>();
            int[] quadrant = new int[4];
            Vector2 main = new Vector2(owner.rectangle.Center.X, owner.rectangle.Center.Y); // reference point 1

            foreach (NPC npc in npcs)
            {
                Vector2 V2 = new Vector2(npc.rectangle.Center.X, npc.rectangle.Center.Y);
                Vector2 Distance = main - V2;

                if (Vector2.Distance(main, V2) < radius)
                {
                    prox.Add(npc);
                    float radians = (float)Math.Atan2(V2.Y - main.Y, V2.X - main.X);

                    npcAngle = MathHelper.ToDegrees(radians);

                    if (owner.rectangle.Center.Y > V2.Y)
                        npcAngle = (owner.faceDirection - npcAngle) % 360;
                    else
                        npcAngle = (360 - npcAngle + owner.faceDirection) % 360;

                    if (npcAngle >= 0 && npcAngle < 90)
                        quadrant[0]++;
                    else if (npcAngle >= 90 && npcAngle < 180)
                        quadrant[1]++;
                    else if (npcAngle >= 180 && npcAngle < 270)
                        quadrant[2]++;
                    else
                        quadrant[3]++;
                }
            }
            owner.proxList = prox;
            owner.quadrants = quadrant;
        }
Ejemplo n.º 7
0
        //wall sensor
        public bool WeaponSensor(Player owner, NPC npc, int weaponRange)
        {
            List<NPC> npcInFront = new List<NPC>();
            float[] npcSense = new float[3];

            //If face down

            setNPCDefaults(owner, npc, weaponRange);
            Vector2 distance = new Vector2();

            //straight down
            if (Intersects(main, sightRangeCenter, npcLeft, npcRight, out distance))
            {
                owner.npcSensors[1] = Vector2.Distance(main, distance);
                return true;
            }
            else
            {
                owner.npcSensors[0] = 0;
            }

            //left 45 degrees
            if (Intersects(npcLeft45, sightRangeLeft, npcLeft, npcRight, out distance))
            {
                owner.npcSensors[0] = Vector2.Distance(main, distanceLeft);
                return true;
            }
            else
            {
                owner.npcSensors[0] = 0;
            }

            //right 45 degrees
            if (Intersects(npcRight45, sightRangeRight, npcLeft, npcRight, out distance))
            {
                owner.npcSensors[2] = Vector2.Distance(main, distanceRight);
                return true;
            }
            else
            {
                owner.npcSensors[2] = 0;
            }
            owner.npcList = npcInFront;

            return false;
        }
Ejemplo n.º 8
0
        public void WallScan(Player owner, List<Wall> walls)
        {
            List<Wall> wallsInFront = new List<Wall>();
            float[] wallSense = new float[3];

            //If face down
            foreach (Wall wall in walls)
            {
                setWallDefaults(owner, wall);
                Vector2 distance = new Vector2();

                //straight down
                if (Intersects(main, sightRangeCenter, wallLeft, wallRight, out distance))
                {

                    owner.wallSensors[1] = Vector2.Distance(main, distance);
                }
                else
                {
                    owner.wallSensors[0] = 0;
                }

                //left 45 degrees
                if (Intersects(wallLeft45, sightRangeLeft, wallLeft, wallRight, out distance))
                {
                    owner.wallSensors[0] = Vector2.Distance(main, distanceLeft);
                }
                else
                {
                    owner.wallSensors[0] = 0;
                }

                //right 45 degrees
                if (Intersects(wallRight45, sightRangeRight, wallLeft, wallRight, out distance))
                {
                    owner.wallSensors[2] = Vector2.Distance(main, distanceRight);
                }
                else
                {
                    owner.wallSensors[2] = 0;
                }

                owner.wallList = wallsInFront;

            }
        }
Ejemplo n.º 9
0
        public void setWallDefaults(Player owner, Wall wall)
        {
            if (owner.faceDirection <= 235 && owner.faceDirection >= 135)
            {
                main = new Vector2(owner.rectangle.Center.X, owner.rectangle.Bottom); // reference point 1
                wallLeft = new Vector2(wall.rectangle.Left, wall.rectangle.Top);
                wallRight = new Vector2(wall.rectangle.Right, wall.rectangle.Top);
                wallCenter = new Vector2(main.X, wall.rectangle.Top);
                dTmp = Vector2.Distance(main, wallCenter);
                wallLeft45 = new Vector2((float)(main.X - dTmp * Math.Tan(45)), main.Y);
                wallRight45 = new Vector2((float)(main.X + dTmp * Math.Tan(45)), main.Y);
                sightRangeCenter = new Vector2(main.X, (main.Y + sightRange));
                sightRangeLeft = new Vector2(wallLeft45.X, sightRangeCenter.Y);
                sightRangeRight = new Vector2(wallRight45.X, sightRangeCenter.Y);
                distanceLeft = new Vector2(wallLeft45.X, wall.rectangle.Top);
                distanceRight = new Vector2(wallRight45.X, wall.rectangle.Top);
            }
            else if (owner.faceDirection <= 270 && owner.faceDirection <= 45)
            {
                main = new Vector2(owner.rectangle.Center.X, owner.rectangle.Top); // reference point 1
                wallLeft = new Vector2(wall.rectangle.Left, wall.rectangle.Bottom);
                wallRight = new Vector2(wall.rectangle.Right, wall.rectangle.Bottom);
                wallCenter = new Vector2(main.X, wall.rectangle.Bottom);
                dTmp = Vector2.Distance(main, wallCenter);
                wallLeft45 = new Vector2((float)(main.X - dTmp * Math.Tan(45)), main.Y);
                wallRight45 = new Vector2((float)(main.X + dTmp * Math.Tan(45)), main.Y);
                sightRangeCenter = new Vector2(main.X, (main.Y - sightRange));
                sightRangeLeft = new Vector2(wallLeft45.X, sightRangeCenter.Y);
                sightRangeRight = new Vector2(wallRight45.X, sightRangeCenter.Y);
                distanceLeft = new Vector2(wallLeft45.X, wall.rectangle.Bottom);
                distanceRight = new Vector2(wallRight45.X, wall.rectangle.Bottom);
            }
            else if (owner.faceDirection <= 315 && owner.faceDirection >= 225)
            {
                main = new Vector2(owner.rectangle.Left, owner.rectangle.Center.Y); // reference point 1
                wallLeft = new Vector2(wall.rectangle.Right, wall.rectangle.Top);
                wallRight = new Vector2(wall.rectangle.Right, wall.rectangle.Bottom);
                sightRangeCenter = new Vector2(main.X - sightRange, main.Y);
                wallCenter = new Vector2(wall.rectangle.Right, main.Y);
                dTmp = Vector2.Distance(main, wallCenter);
                wallLeft45 = new Vector2(main.X, (float)(main.Y - dTmp * Math.Tan(45)));
                wallRight45 = new Vector2(main.X, (float)(main.Y + dTmp * Math.Tan(45)));
                sightRangeCenter = new Vector2(main.X - sightRange, main.Y);
                sightRangeLeft = new Vector2(sightRangeCenter.X, wallLeft45.Y);
                sightRangeRight = new Vector2(sightRangeCenter.X, wallRight45.Y);
                distanceLeft = new Vector2(wall.rectangle.Right, wallLeft45.Y);
                distanceRight = new Vector2(wall.rectangle.Right, wallRight45.Y);
            }
            else if (owner.faceDirection >= 45 && owner.faceDirection <= 135)
            {
                main = new Vector2(owner.rectangle.Right, owner.rectangle.Center.Y); // reference point 1
                wallLeft = new Vector2(wall.rectangle.Left, wall.rectangle.Top);
                wallRight = new Vector2(wall.rectangle.Left, wall.rectangle.Bottom);
                sightRangeCenter = new Vector2(main.X + sightRange, main.Y);
                wallCenter = new Vector2(wall.rectangle.Left, main.Y);
                dTmp = Vector2.Distance(main, wallCenter);
                wallLeft45 = new Vector2(main.X, (float)(main.Y - dTmp * Math.Tan(45)));
                wallRight45 = new Vector2(main.X, (float)(main.Y + dTmp * Math.Tan(45)));
                sightRangeCenter = new Vector2(main.X + sightRange, main.Y);
                sightRangeLeft = new Vector2(sightRangeCenter.X, wallLeft45.Y);
                sightRangeRight = new Vector2(sightRangeCenter.X, wallRight45.Y);
                distanceLeft = new Vector2(wall.rectangle.Left, wallLeft45.Y);
                distanceRight = new Vector2(wall.rectangle.Left, wallRight45.Y);

            }
        }
Ejemplo n.º 10
0
        public void setNPCDefaults(Player owner, NPC npc, int weaponRange)
        {
            if (owner.faceDirection <= 235 && owner.faceDirection >= 135)
            {
                main = new Vector2(owner.rectangle.Center.X, owner.rectangle.Bottom); // reference point 1
                npcLeft = new Vector2(npc.rectangle.Left, npc.rectangle.Top);
                npcRight = new Vector2(npc.rectangle.Right, npc.rectangle.Top);
                npcCenter = new Vector2(main.X, npc.rectangle.Top);
                dTmp = Vector2.Distance(main, npcCenter);
                npcLeft45 = new Vector2((float)(main.X - dTmp * Math.Tan(45)), main.Y);
                npcRight45 = new Vector2((float)(main.X + dTmp * Math.Tan(45)), main.Y);
                sightRangeCenter = new Vector2(main.X, (main.Y + weaponRange));
                sightRangeLeft = new Vector2(npcLeft45.X, sightRangeCenter.Y);
                sightRangeRight = new Vector2(npcRight45.X, sightRangeCenter.Y);
                distanceLeft = new Vector2(npcLeft45.X, npc.rectangle.Top);
                distanceRight = new Vector2(npcRight45.X, npc.rectangle.Top);
            }
            else if (owner.faceDirection <= 270 && owner.faceDirection <= 45)
            {
                main = new Vector2(owner.rectangle.Center.X, owner.rectangle.Top); // reference point 1
                npcLeft = new Vector2(npc.rectangle.Left, npc.rectangle.Bottom);
                npcRight = new Vector2(npc.rectangle.Right, npc.rectangle.Bottom);
                npcCenter = new Vector2(main.X, npc.rectangle.Bottom);
                dTmp = Vector2.Distance(main, npcCenter);
                npcLeft45 = new Vector2((float)(main.X - dTmp * Math.Tan(45)), main.Y);
                npcRight45 = new Vector2((float)(main.X + dTmp * Math.Tan(45)), main.Y);
                sightRangeCenter = new Vector2(main.X, (main.Y - weaponRange));
                sightRangeLeft = new Vector2(npcLeft45.X, sightRangeCenter.Y);
                sightRangeRight = new Vector2(npcRight45.X, sightRangeCenter.Y);
                distanceLeft = new Vector2(npcLeft45.X, npc.rectangle.Bottom);
                distanceRight = new Vector2(npcRight45.X, npc.rectangle.Bottom);
            }
            else if (owner.faceDirection <= 315 && owner.faceDirection >= 225)
            {
                main = new Vector2(owner.rectangle.Left, owner.rectangle.Center.Y); // reference point 1
                npcLeft = new Vector2(npc.rectangle.Right, npc.rectangle.Top);
                npcRight = new Vector2(npc.rectangle.Right, npc.rectangle.Bottom);
                sightRangeCenter = new Vector2(main.X - weaponRange, main.Y);
                npcCenter = new Vector2(npc.rectangle.Right, main.Y);
                dTmp = Vector2.Distance(main, npcCenter);
                npcLeft45 = new Vector2(main.X, (float)(main.Y - dTmp * Math.Tan(45)));
                npcRight45 = new Vector2(main.X, (float)(main.Y + dTmp * Math.Tan(45)));
                sightRangeCenter = new Vector2(main.X - weaponRange, main.Y);
                sightRangeLeft = new Vector2(sightRangeCenter.X, npcLeft45.Y);
                sightRangeRight = new Vector2(sightRangeCenter.X, npcRight45.Y);
                distanceLeft = new Vector2(npc.rectangle.Right, npcLeft45.Y);
                distanceRight = new Vector2(npc.rectangle.Right, npcRight45.Y);
            }
            else if (owner.faceDirection >= 45 && owner.faceDirection <= 135)
            {
                main = new Vector2(owner.rectangle.Right, owner.rectangle.Center.Y); // reference point 1
                npcLeft = new Vector2(npc.rectangle.Left, npc.rectangle.Top);
                npcRight = new Vector2(npc.rectangle.Left, npc.rectangle.Bottom);
                sightRangeCenter = new Vector2(main.X + weaponRange, main.Y);
                npcCenter = new Vector2(npc.rectangle.Left, main.Y);
                dTmp = Vector2.Distance(main, npcCenter);
                npcLeft45 = new Vector2(main.X, (float)(main.Y - dTmp * Math.Tan(45)));
                npcRight45 = new Vector2(main.X, (float)(main.Y + dTmp * Math.Tan(45)));
                sightRangeCenter = new Vector2(main.X + weaponRange, main.Y);
                sightRangeLeft = new Vector2(sightRangeCenter.X, npcLeft45.Y);
                sightRangeRight = new Vector2(sightRangeCenter.X, npcRight45.Y);
                distanceLeft = new Vector2(npc.rectangle.Left, npcLeft45.Y);
                distanceRight = new Vector2(npc.rectangle.Left, npcRight45.Y);

            }
        }