예제 #1
0
        protected override void UsePower(ManagerHelper mH)
        {
            if (CurrentPower() > abilityUse && !mH.GetAbilityManager().HasReachedLargeRockCap())
            {
                Vector2 tempPos;

                if (GetPercentHealth() < .5)
                {
                    tempPos = new Vector2(64) * lastDamagerDirection + GetOriginPosition();
                }
                else
                {
                    tempPos = new Vector2(64) * PathHelper.Direction(rotation) + GetOriginPosition();
                }
                tempPos.X = tempPos.X - (tempPos.X % 32) + 16;
                tempPos.Y = tempPos.Y - (tempPos.Y % 32) + 16;

                if (tempPos.X > 0 && tempPos.X < mH.GetLevelSize().X&&
                    tempPos.Y > 0 && tempPos.Y < mH.GetLevelSize().Y&&
                    !PathHelper.IsNodeBlocked(tempPos))
                {
                    mH.GetAbilityManager().AddLargeRock(tempPos, affiliation);

                    base.UsePower(mH);
                    UpdatePowerStatistic();
                }
            }
        }
예제 #2
0
        private Vector2 BomberOrigin(ManagerHelper mH)
        {
            float x, y;

            //check change in x
            if ((GetOriginPosition().X - target.GetOriginPosition().X) <= 0)
            {
                x = mH.GetLevelSize().X + 150; //REPLACE NUMBER???
            }
            else
            {
                x = -150; //REPLACE NUMBER???
            }
            //check change in y
            if ((GetOriginPosition().Y - target.GetOriginPosition().Y) <= 0)
            {
                y = mH.GetLevelSize().Y + 150;
            }
            else
            {
                y = -150;
            }

            return(new Vector2(x, y));
        }
예제 #3
0
        //This method will be used to dictate the AI's behavior in this public class
        public override void Update(ManagerHelper mH)
        {
            double distanceToTarget = PathHelper.DistanceSquared(GetOriginPosition(), targetPosition);

            if (distanceToTarget < 300 * 300 && !hasBombed)
            {
                Bomb(mH);
                hasBombed = true;
            }

            if (distanceToTarget < 50 * 50)
            {
                drawTarget = false;
            }

            //remove thyself
            if (position.X < -200 || position.X > mH.GetLevelSize().X + 200 || position.Y < -200 ||
                position.Y > mH.GetLevelSize().Y + 200)
            {
                mH.GetNPCManager().Remove(this);
            }

            var newTargetSpriteIndex =
                (int)
                (targetSprite.GetTotalFrames() *
                 Math.Max(0,
                          Math.Min(1000 * 1000, 1000 * 1000 - PathHelper.DistanceSquared(GetOriginPosition(), targetPosition))) /
                 1000 * 1000);

            targetSprite.SetFrameIndex(newTargetSpriteIndex);

            SpriteUpdate(mH);
            targetSprite.Update(mH);
        }
예제 #4
0
        public void Initialize(ManagerHelper mH, int r)
        {
            if (mH.GetGametype() is Survival)
            {
                randomness = 0;
            }
            else
            {
                randomness = r;
            }

            length   = (int)mH.GetLevelSize().X / (int)nodeSize.X;
            width    = (int)mH.GetLevelSize().Y / (int)nodeSize.Y;
            managers = mH;

            //Node Collections
            field = new Node[length + 1, width + 1];

            //Set up field
            for (int i = 0; i <= length; i++)
            {
                for (int j = 0; j <= width; j++)
                {
                    field[i, j] = new Node(null, 0, 0, false, i, j);
                }
            }

            open   = new List <Node>(length * width);
            closed = new List <Node>(length * width);
        }
예제 #5
0
        public override void Update(ManagerHelper mH)
        {
            if (isExplosive && drawTime <= 0)
            {
                mH.GetParticleManager().AddExplosion(GetOriginPosition(), this.creator, damage);
                isExplosive = false;
            }

            if (position.X < 0 || position.X > mH.GetLevelSize().X ||
                position.Y < 0 || position.Y > mH.GetLevelSize().Y)
            {
                SetDrawTime(0);
            }

            if (drawTime > 0)
            {
                drawTime -= mH.GetGameTime().ElapsedGameTime.TotalSeconds;

                SpriteUpdate(mH);

                //Spawn cool things to make it look better
                if (mH.GetRandom().NextDouble() < 0.5f)
                {
                    EffectSpawnCode(mH);
                }
            }

            existenceTime -= mH.GetGameTime().ElapsedGameTime.TotalSeconds;
        }
예제 #6
0
        protected override void UsePower(ManagerHelper mH)
        {
            if (CurrentPower() > abilityUse)
            {
                Vector2 tempPos = new Vector2(64) * PathHelper.Direction(rotation) + GetOriginPosition();
                tempPos.X = tempPos.X - (tempPos.X % 32) + 16;
                tempPos.Y = tempPos.Y - (tempPos.Y % 32) + 16;

                if (tempPos.X > 0 && tempPos.X < mH.GetLevelSize().X&&
                    tempPos.Y > 0 && tempPos.Y < mH.GetLevelSize().Y&&
                    !PathHelper.IsNodeBlocked(tempPos))
                {
                    mH.GetAbilityManager().AddLargeRock(tempPos, affiliation);

                    base.UsePower(mH);
                    UpdatePowerStatistic();
                }
            }
        }
예제 #7
0
        public void LoadContent(ManagerHelper mH)
        {
            foreach (Camera c in cameras)
            {
                c.dimensions.X = (int)mH.GetLevelSize().X / 2;
                c.dimensions.Y = (int)mH.GetLevelSize().Y / 2;
            }

            foreach (HUD h in huds)
            {
                h.LoadContent(mH);
            }

            if (SplitScreen != null)
            {
                SplitScreen.LoadContent(mH.GetTextureManager());
            }

            pauseScreen.LoadContent(mH.GetTextureManager());
            pauseInstructions.LoadContent(mH.GetTextureManager());
        }
예제 #8
0
        protected void HoverPath(ManagerHelper mH, Vector2 p, int r)
        {
            bool    validPoint;
            Vector2 randPoint;
            Vector2 originNode = GetOriginPosition() / mH.GetPathHelper().GetNodeSize();

            do
            {
                validPoint = true;
                randPoint  = originNode + new Vector2(mH.GetRandom().Next(-1 * r / 32, r / 32), mH.GetRandom().Next(-1 * r / 32, r / 32));

                if ((randPoint.X > 0 && randPoint.X < mH.GetLevelSize().X / 32) &&
                    (randPoint.Y > 0 && randPoint.Y < mH.GetLevelSize().Y / 32))
                {
                    foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers())
                    {
                        foreach (Vector2 n in e.GetFrameBlockers())
                        {
                            if ((n.X + (int)e.GetOriginPosition().X) == randPoint.X &&
                                (n.Y + (int)e.GetOriginPosition().Y) == randPoint.Y)
                            {
                                validPoint = false;
                                break;
                            }
                        }

                        if (!validPoint)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    validPoint = false;
                }
            } while (!validPoint);

            mH.GetPathHelper().FindClearPath(GetOriginPosition(), randPoint * 32, mH, path);
        }
예제 #9
0
        protected void RandomPath(ManagerHelper mH)
        {
            bool    validPoint;
            Vector2 randPoint;

            pathTimerEnd = 10;

            do
            {
                validPoint = true;
                randPoint  = new Vector2(mH.GetRandom().Next((int)mH.GetLevelSize().X),
                                         mH.GetRandom().Next((int)mH.GetLevelSize().Y)) / mH.GetPathHelper().GetNodeSize();

                foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers())
                {
                    foreach (Vector2 n in e.GetFrameBlockers())
                    {
                        if (n.Equals(randPoint))
                        {
                            validPoint = false;
                            break;
                        }
                        else
                        {
                            validPoint = true;
                        }
                    }

                    if (!validPoint)
                    {
                        break;
                    }
                }
            } while (!validPoint);

            mH.GetPathHelper().FindClearPath(GetOriginPosition(), randPoint * 32, mH, path);
        }
예제 #10
0
        public override void Update(ManagerHelper mH)
        {
            foreach (Sprite section in poolSections)
            {
                section.Turn(10000.0f / (section.GetFrame().Width *section.GetFrame().Width) * mH.GetDeltaSeconds());
            }

            foreach (NPC a in mH.GetNPCManager().GetNPCs())
            {
                if (!(a is Bomber))
                {
                    float tempDistance = PathHelper.DistanceSquared(GetOriginPosition(), a.GetOriginPosition());

                    if (tempDistance < 15 * 15)
                    {
                        //TODO: Modify
                        a.position = mH.GetLevelSize() * new Vector2(mH.GetRandom().Next(2), mH.GetRandom().Next(2));
                    }
                    else if (tempDistance < frame.Width / 2 * frame.Width / 2)
                    {
                        float tempRot = PathHelper.Direction(a.GetOriginPosition(), GetOriginPosition()) -
                                        MathHelper.Pi / 9;
                        a.AddAcceleration(new Vector2(DWMath.Cos(tempRot), DWMath.Sin(tempRot)) * 4);
                    }
                }
            }

            foreach (Particle e in mH.GetParticleManager().GetParticles())
            {
                float tempDistance = PathHelper.DistanceSquared(GetOriginPosition(), e.GetOriginPosition());

                if (tempDistance < 15 * 15)
                {
                    e.SetDrawTime(0);
                }
                else if (tempDistance < (frame.Width / 2) * (frame.Width / 2))
                {
                    float tempRot = PathHelper.Direction(e.GetOriginPosition(), GetOriginPosition()) + MathHelper.Pi / 9;
                    e.AddAcceleration(new Vector2((float)DWMath.Cos(tempRot), (float)DWMath.Sin(tempRot)) * 100);
                }
            }

            base.Update(mH);
        }
예제 #11
0
        protected override void PosUpdate(ManagerHelper mH)
        {
            //Update position
            Vector2 tempPos     = position + velocity * mH.GetDeltaSeconds();
            Vector2 tempOPos    = tempPos + origin;
            float   distSquared = 1000000;

            //Collisions
            foreach (Impassable e in mH.GetEnvironmentManager().GetImpassables())
            {
                if (distSquared > PathHelper.DistanceSquared(e.GetOriginPosition(), tempOPos))
                {
                    int tempVect = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempOPos, e);
                    if (tempVect != -1)
                    {
                        velocity = CollisionHelper.CollideDirectional(velocity, tempVect);
                    }
                }
            }

            foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers())
            {
                if (distSquared > PathHelper.DistanceSquared(e.GetOriginPosition(), tempOPos))
                {
                    int tempVect = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempOPos, e);
                    if (tempVect != -1)
                    {
                        velocity = CollisionHelper.CollideSimple(tempVect, velocity);
                    }
                }
            }
            tempPos = position + velocity * mH.GetDeltaSeconds();

            if (
                !(tempPos.X < buffer || tempPos.X > mH.GetLevelSize().X - frame.Width - buffer || tempPos.Y < buffer ||
                  tempPos.Y > mH.GetLevelSize().Y - frame.Height - buffer))
            {
            }
            else
            {
                if (tempPos.X <= buffer)
                {
                    tempPos.X = buffer;
                }
                else if (tempPos.X > mH.GetLevelSize().X - frame.Width - buffer)
                {
                    tempPos.X = mH.GetLevelSize().X - frame.Width - buffer;
                }

                if (tempPos.Y <= buffer)
                {
                    tempPos.Y = buffer;
                }
                else if (tempPos.Y > mH.GetLevelSize().Y - frame.Height - buffer)
                {
                    tempPos.Y = mH.GetLevelSize().Y - frame.Height - buffer;
                }
            }

            position = tempPos;

            //Update frames
            frame.X = frameIndex * frame.Width;
            frame.Y = modeIndex * frame.Height;
        }
예제 #12
0
        protected virtual void PosUpdate(ManagerHelper mH)
        {
            //Update position
            Vector2 tempPos     = position + velocity * mH.GetDeltaSeconds();
            Vector2 tempOPos    = tempPos + origin;
            float   distSquared = 1000000;

            if (float.IsNaN(tempPos.X) || float.IsNaN(tempPos.Y))
            {
                //TODO: Do not leave this in.
                throw new Exception("Not sure how this happened.");
            }

            //Collisions
            foreach (NPC a in mH.GetNPCManager().GetNPCs()) //first go through every single npc
            {
                if (a.GetAffiliation() != affiliation && distSquared > PathHelper.DistanceSquared(a.GetOriginPosition(), tempOPos))
                {
                    Vector2 tempVect = CollisionHelper.IntersectPixelsSimple(this, a);
                    if (tempVect != new Vector2(-1))
                    {
                        velocity = CollisionHelper.CollideRandom(GetOriginPosition(), tempVect) * movementSpeed;
                    }
                }
            }

            foreach (LargeRock r in mH.GetAbilityManager().GetLargeRocks())
            {
                if (distSquared > PathHelper.DistanceSquared(r.GetOriginPosition(), tempOPos))
                {
                    int tempVect = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempOPos, r);
                    if (tempVect != -1)
                    {
                        velocity = CollisionHelper.CollideSimple(tempVect, velocity);
                    }
                }
            }

            foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers())
            {
                if (distSquared > PathHelper.DistanceSquared(e.GetOriginPosition(), tempOPos))
                {
                    int tempVect = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempOPos, e);
                    if (tempVect != -1)
                    {
                        if (e is SwitchBox)
                        {
                            SwitchBox box = (SwitchBox)e;
                            box.lowerHealth();
                        }
                        velocity = CollisionHelper.CollideSimple(tempVect, velocity);
                    }
                }
            }

            foreach (Impassable e in mH.GetEnvironmentManager().GetImpassables())
            {
                if (distSquared > PathHelper.DistanceSquared(e.GetOriginPosition(), tempOPos))
                {
                    int tempVect = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempOPos, e);
                    if (tempVect != -1)
                    {
                        velocity = CollisionHelper.CollideDirectional(velocity, tempVect);
                    }
                }
            }

            tempPos = position + velocity * mH.GetDeltaSeconds();

            if (
                !(tempPos.X < buffer || tempPos.X > mH.GetLevelSize().X - frame.Width - buffer || tempPos.Y < buffer ||
                  tempPos.Y > mH.GetLevelSize().Y - frame.Height - buffer))
            {
            }
            else
            {
                if (tempPos.X <= buffer)
                {
                    tempPos.X = buffer;
                }
                else if (tempPos.X > mH.GetLevelSize().X - frame.Width - buffer)
                {
                    tempPos.X = mH.GetLevelSize().X - frame.Width - buffer;
                }

                if (tempPos.Y <= buffer)
                {
                    tempPos.Y = buffer;
                }
                else if (tempPos.Y > mH.GetLevelSize().Y - frame.Height - buffer)
                {
                    tempPos.Y = mH.GetLevelSize().Y - frame.Height - buffer;
                }
            }

            position = tempPos;

            //Update frames
            frame.X = frameIndex * frame.Width;
            frame.Y = modeIndex * frame.Height;

            UpdateProtection(mH);
        }
예제 #13
0
        public void FindClearPath(Vector2 pA, Vector2 pB, ManagerHelper mH, Path path)
        {
            counter = 0;

            open.Clear();
            closed.Clear();

            //Prevent excecution if current position or end position is bad
            if (pA.X < 0 || pA.X > mH.GetLevelSize().X || pA.Y < 0 || pA.Y > mH.GetLevelSize().Y ||
                pB.X < 0 || pB.X > mH.GetLevelSize().X || pB.Y < 0 || pB.Y > mH.GetLevelSize().Y)
            {
                return;
            }

            Vector2 end       = new Vector2((int)(pB.X / nodeSize.X), (int)(pB.Y / nodeSize.Y)),
                    beginning = new Vector2((int)(pA.X / nodeSize.X), (int)(pA.Y / nodeSize.Y));

            if (end == beginning)
            {
                return;
            }

            if (field[(int)end.X, (int)end.Y].GetBlocker())
            {
                end = FindOpenNodePoint(end, mH);
            }

            //Set up parent according to A*
            Node parent = field[(int)beginning.X, (int)beginning.Y];

            parent.SetFScore((int)(MathHelper.Distance(end.X, beginning.X) + MathHelper.Distance(end.Y, beginning.Y)));
            open.Add(parent);

            //Makes the end not a blocker
            field[(int)end.X, (int)end.Y].SetBlocker(false);

            #region Loop through array until end is found

            while (counter < 100 && !(parent.GetPosition() == end))
            {
                //Checks for instance of no solution
                if (open.Count == 0)
                {
                    break;
                }

                #region Find best new parent

                Node lowest = open.First();

                //Goes through each node on the open list and compares its score to the current low
                foreach (Node x in open)
                {
                    if (x.GetFScore() < lowest.GetFScore())
                    {
                        lowest = x;
                    }
                }

                //Once the lowest is found, switch it from the open to the closed list
                parent = lowest;
                open.Remove(lowest);
                closed.Add(lowest);

                #endregion

                #region Calculate F scores of adjacent nodes

                for (int i = (int)parent.GetPosition().X - 1; i <= (int)parent.GetPosition().X + 1; i++)
                {
                    for (int j = (int)parent.GetPosition().Y - 1; j <= (int)parent.GetPosition().Y + 1; j++)
                    {
                        //If node is invalid
                        if (i < 0 || j < 0 || i >= length || j >= width || field[i, j].GetBlocker() ||
                            closed.Contains(field[i, j]))
                        {
                            continue;
                        }

                        //Current node
                        Node current = field[i, j];

                        #region Calculate cell's info

                        current.SetParent(parent);

                        current.SetGScore(parent.GetGScore() + mH.GetRandom().Next(0, randomness));

                        //Calculate other scores
                        current.SetHScore((int)(MathHelper.Distance(current.GetPosition().X, end.X) + MathHelper.Distance(current.GetPosition().Y, end.Y)) * 10);
                        current.SetFScore(current.GetGScore() + current.GetHScore());

                        #endregion

                        //If the cell is already on the open list and has a better
                        if (open.Contains(current) && current.GetGScore() > parent.GetGScore())
                        {
                            current.SetFScore(current.GetGScore() + current.GetHScore());
                            current.SetParent(parent);
                        }
                        else
                        {
                            open.Add(current);
                        }
                    }
                }

                #endregion

                counter++;
            }

            #endregion

            #region Create Path

            //Once end is found, compile path together
            path.Clear();

            Node point = parent;
            while (!(point.GetPosition() == beginning))
            {
                if (!point.GetBlocker())
                {
                    path.Add(point.GetPosition() * nodeSize + new Vector2(16), mH);
                }
                point = point.GetParent();
            }

            #endregion
        }
예제 #14
0
        public override void Update(ManagerHelper mH)
        {
            elapsedTime = mH.GetGameTime().ElapsedGameTime.TotalSeconds;
            if (isExplosive && drawTime <= 0)
            {
                mH.GetParticleManager().AddExplosion(GetOriginPosition(), creator, damage);
                isExplosive = false;
            }

            if (drawTime > 0)
            {
                drawTime   -= mH.GetGameTime().ElapsedGameTime.TotalSeconds;
                pulseTimer += elapsedTime;
                frameTimer += elapsedTime;
                #region Tossable Update

                #region Keep it in the level

                //Update position
                Vector2 tempPos = position + velocity * mH.GetDeltaSeconds();

                //Check for collisions with environment
                foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers())
                {
                    int tempCollide = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempPos, e);

                    if (tempCollide != -1)
                    {
                        velocity = CollisionHelper.CollideDirectional(velocity, tempCollide);
                    }
                }

                tempPos = position + velocity * mH.GetDeltaSeconds();

                if ((tempPos.X < 0 || tempPos.X > mH.GetLevelSize().X - frame.Width - 0 || tempPos.Y < 0 ||
                     tempPos.Y > mH.GetLevelSize().Y - frame.Height - 0))
                {
                    if (tempPos.X <= 0)
                    {
                        velocity  = new Vector2(velocity.X * -1, velocity.Y);
                        tempPos.X = 0;
                    }
                    else if (tempPos.X > mH.GetLevelSize().X - frame.Width - 0)
                    {
                        velocity  = new Vector2(velocity.X * -1, velocity.Y);
                        tempPos.X = mH.GetLevelSize().X - frame.Width - 0;
                    }

                    if (tempPos.Y <= 0)
                    {
                        velocity  = new Vector2(velocity.X, velocity.Y * -1);
                        tempPos.Y = 0;
                    }
                    else if (tempPos.Y > mH.GetLevelSize().Y - frame.Height - 0)
                    {
                        velocity  = new Vector2(velocity.X, velocity.Y * -1);
                        tempPos.Y = mH.GetLevelSize().Y - frame.Height - 0;
                    }
                }
                position = tempPos;

                //Update frames
                frame.X = frameIndex * frame.Width;
                frame.Y = modeIndex * frame.Height;

                #endregion

                #region Finalize Direction

                foreach (Vector2 a in accelerations)
                {
                    if (!float.IsNaN(a.X) && !float.IsNaN(a.Y))
                    {
                        acceleration += a * mH.GetDeltaSeconds();
                    }
                }

                velocity += thrust * acceleration - drag * velocity;

                accelerations.Clear();
                acceleration = Vector2.Zero;

                #endregion

                //Update position
                originPosition = position + origin;

                //Update frame
                if (frameIndex < 1)
                {
                    frameIndex     = 0;
                    frameDirection = 1;
                }
                else if (frameIndex == totalFrames - 1)
                {
                    frameIndex     = totalFrames - 1;
                    frameDirection = -1;
                }

                if (pulseTimer > pulseTime)
                {
                    pulseTime /= 2;
                    pulseTimer = 0;
                }

                if (frameTimer > pulseTime / (totalFrames * 2))
                {
                    frameTimer  = 0;
                    frameIndex += frameDirection;
                }

                if (modeIndex < 0)
                {
                    modeIndex = 0;
                }
                else if (modeIndex >= totalModes)
                {
                    modeIndex = totalModes;
                }

                frame.X = frameIndex * frame.Width;
                frame.Y = modeIndex * frame.Height;

                #endregion

                //Spawn cool things to make it look better
                EffectSpawnCode(mH);
            }
            existenceTime -= mH.GetGameTime().ElapsedGameTime.TotalSeconds;
        }