Beispiel #1
0
        private bool IsInAgentSensorRange(MovingAgent agent, Vector2 playerPos, Vector2 endPoint1, Vector2 endPoint2)
        {
            Rectangle agentBounds = agent.Bounds;

            // getting the 4 points of the agent
            Vector2 bottomLeft  = new Vector2(agentBounds.Left, agentBounds.Top);
            Vector2 bottomRight = new Vector2(agentBounds.Left + agentBounds.Width, agentBounds.Top);
            Vector2 topLeft     = new Vector2(agentBounds.Left, agentBounds.Top + agentBounds.Height);
            Vector2 topRight    = new Vector2(bottomRight.X, topLeft.Y);

            return
                (IsPointInTriangle(bottomLeft, playerPos, endPoint1, endPoint2) ||
                 IsPointInTriangle(bottomRight, playerPos, endPoint1, endPoint2) ||
                 IsPointInTriangle(topLeft, playerPos, endPoint1, endPoint2) ||
                 IsPointInTriangle(topRight, playerPos, endPoint1, endPoint2));
        }
Beispiel #2
0
        //public void InitializeSensors()
        //{
        //    SensorList.Add(new RangeFinder()
        //    {
        //        Type = (int)Enums.SensorType.RangeFinder,
        //        Rotation = (float)Math.PI / 6,
        //        Key = Keys.P,
        //        MaxDistance = 50,//150,
        //        Index = 0,
        //        DirectionText = "Right"
        //    });

        //    SensorList.Add(new RangeFinder()
        //    {
        //        Type = (int)Enums.SensorType.RangeFinder,
        //        Rotation = 0,
        //        Key = Keys.P,
        //        MaxDistance = 60,//150,
        //        Index = 1,
        //        DirectionText = "Middle"
        //    });

        //    SensorList.Add(new RangeFinder()
        //    {
        //        Type = (int)Enums.SensorType.RangeFinder,
        //        Rotation = -1 * (float)Math.PI / 6,
        //        Key = Keys.P,
        //        MaxDistance = 50,//150,
        //        Index = 2,
        //        DirectionText = "Left"
        //    });

        //    SensorList.Add(new AdjacentAgentSensor()
        //    {
        //        Type = (int)Enums.SensorType.AgentSensor,
        //        Radius = 150,
        //        Key = Keys.O,
        //    });

        //    SensorList.Add(new PieSliceSensor() // - 60 to 60 degrees
        //    {
        //        Type = (int)Enums.SensorType.PieSliceSensor,
        //        Key = Keys.I,
        //        Rotation1 = -1 * (float)Math.PI / 3,
        //        Rotation2 = (float)Math.PI / 3,
        //        MaxDistance = 150,
        //        DisplayText = "(1,0) - Straight Ahead",
        //        Index = 0
        //    });

        //    SensorList.Add(new PieSliceSensor() // 60 to 120 degrees
        //    {
        //        Type = (int)Enums.SensorType.PieSliceSensor,
        //        Key = Keys.I,
        //        Rotation1 = (float)Math.PI / 3,
        //        Rotation2 = 2 * (float)Math.PI / 3,
        //        MaxDistance = 150,
        //        DisplayText = "(0,1) - Right",
        //        Index = 1
        //    });

        //    SensorList.Add(new PieSliceSensor() // 120 to 240 degrees
        //    {
        //        Type = (int)Enums.SensorType.PieSliceSensor,
        //        Key = Keys.I,
        //        Rotation1 = 2 * (float)Math.PI / 3,
        //        Rotation2 = 4 * (float)Math.PI / 3,
        //        MaxDistance = 150,
        //        DisplayText = "(-1,0) - Backwards",
        //        Index = 2
        //    });

        //    SensorList.Add(new PieSliceSensor() // 240 to 300 degrees
        //    {
        //        Type = (int)Enums.SensorType.PieSliceSensor,
        //        Key = Keys.I,
        //        Rotation1 = 4 * (float)Math.PI / 3,
        //        Rotation2 = 5 * (float)Math.PI / 3,
        //        MaxDistance = 150,
        //        DisplayText = "(0,-1) - Left",
        //        Index = 3
        //    });
        //}

        #endregion

        public void Update(GameTime gameTime, KeyboardState keyboardStateCurrent, KeyboardState keyboardStatePrevious,
                           MouseState mouseStateCurrent, MouseState mouseStatePrevious, List <GameAgent> agentAIList,
                           int levelWidth, int levelHeight)
        {
            if (!HasControl)
            {
                return;
            }

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 mouseStateCurrentVec = new Vector2(mouseStateCurrent.X, mouseStateCurrent.Y);

            Rotation = Utils.GetRotationToTarget(mouseStateCurrentVec, Position);

            // movement
            if (keyboardStateCurrent.IsKeyDown(Keys.Up) || keyboardStateCurrent.IsKeyDown(Keys.W))
            {
                //Position += new Vector2(0, -1) * Speed;
                Vector2 nextPos = new Vector2(0, -1) * Speed + Position; //Utils.CalculateRotatedMovement(new Vector2(0, -1), Rotation) * Speed + Position;

                if (IsValidMove(nextPos, agentAIList, levelWidth, levelHeight))
                {
                    Position = nextPos;
                }
            }
            if (keyboardStateCurrent.IsKeyDown(Keys.Down) || keyboardStateCurrent.IsKeyDown(Keys.S))
            {
                //Position += new Vector2(0, 1) * Speed;
                Vector2 nextPos = new Vector2(0, 1) * Speed + Position;//Utils.CalculateRotatedMovement(new Vector2(0, 1), Rotation) * Speed + Position;

                if (IsValidMove(nextPos, agentAIList, levelWidth, levelHeight))
                {
                    Position = nextPos;
                }
            }
            if (keyboardStateCurrent.IsKeyDown(Keys.A) || keyboardStateCurrent.IsKeyDown(Keys.Left))
            {
                //Position += new Vector2(-1, 0) * Speed;
                Vector2 nextPos = new Vector2(-1, 0) * Speed + Position; //Utils.CalculateRotatedMovement(new Vector2(-1, 0), Rotation) * Speed + Position;

                if (IsValidMove(nextPos, agentAIList, levelWidth, levelHeight))
                {
                    Position = nextPos;
                }
            }
            if (keyboardStateCurrent.IsKeyDown(Keys.D) || keyboardStateCurrent.IsKeyDown(Keys.Right))
            {
                //Position += new Vector2(1, 0) * Speed;
                Vector2 nextPos = new Vector2(1, 0) * Speed + Position; //Utils.CalculateRotatedMovement(new Vector2(1, 0), Rotation) * Speed + Position;

                if (IsValidMove(nextPos, agentAIList, levelWidth, levelHeight))
                {
                    Position = nextPos;
                }
            }

            // the player moved over a npc or wall, the player will take damage equal to that agent
            foreach (GameAgent intersectingAgent in agentAIList.Where(ga => ga.Bounds.Intersects(Bounds)).ToList())
            {
                // if the player ran over an enemy, the enemy will take damage equal to that enemy
                if (intersectingAgent.Type == (int)Enums.AgentType.Enemy)
                {
                    MovingAgent movingAgent = (MovingAgent)intersectingAgent;

                    if (MaxHealth > movingAgent.Health)
                    {
                        TakeDamage(movingAgent.Health);
                        movingAgent.TakeDamage(movingAgent.Health);
                    }
                    else
                    {
                        TakeDamage(movingAgent.Health);
                    }
                }
                else if (intersectingAgent.Type == (int)Enums.AgentType.Wall)
                {
                    TakeDamage(Health);
                }
                else if (intersectingAgent.Type == (int)Enums.AgentType.Item)
                {
                    Item item = (Item)intersectingAgent;
                    item.GetItem();
                    agentAIList.Remove(item);
                }
            }

            foreach (Attack attack in skillList)
            {
                if (attack.IsUnlocked)
                {
                    attack.Update(gameTime, keyboardStateCurrent, mouseStateCurrent);
                }
            }

            // if the object is active on the screen
            if (Moving)
            {
                // if the image is a sprite sheet
                // and if enough time has passed to where we need to move to the next frame
                if (TotalFrames > 1 && (animElapsed += gameTime.ElapsedGameTime) > AnimationInterval)
                {
                    if (++currentFrame == TotalFrames)
                    {
                        currentFrame = 0;
                    }

                    // move back by the animation interval (in miliseconds)
                    animElapsed -= AnimationInterval;
                }
            }

            // power recharge rate
            if (Power < MaxPower)
            {
                Power += 0.10f;                  //0.08f;
            }
            else
            {
                Power = MaxPower;
            }

            // health recharge rate
            if (Health < 0)
            {
                Health = 0;
            }
            else if (Health < MaxHealth)
            {
                Health += 0.02f;
            }
            else
            {
                Health = MaxHealth;
            }

            // go into berserker mode every 1000 points
            if (Score % 1000 == 0 && Score != 0)
            {
                skillList[(int)Enums.PlayerSkills.Default].CoolDown  = 0;
                skillList[(int)Enums.PlayerSkills.Default].MinDamage = 10;
                skillList[(int)Enums.PlayerSkills.Default].MaxDamage = 20;
                Color     = Color.Red;
                tempScore = Score;
                if (!berserkerSoundPlayed)
                {
                    PulseGame.Current.berserkerSound.Play();
                    berserkerSoundPlayed = true;
                }
            }
            if ((berserkerSoundPlayed) && ((Score - tempScore) >= berserkerLength))
            {
                skillList[(int)Enums.PlayerSkills.Default].CoolDown  = 50;
                skillList[(int)Enums.PlayerSkills.Default].MinDamage = 5;
                skillList[(int)Enums.PlayerSkills.Default].MaxDamage = 10;
                Color = Color.White;
                berserkerSoundPlayed = false;
            }
        }