Ejemplo n.º 1
0
        public virtual void Update(ManagerHelper mH)
        {
            #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
            position += velocity * mH.GetDeltaSeconds();

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

            originPosition = position + origin;

            //Update frame
            if (frameIndex < 0)
            {
                frameIndex = 0;
            }
            else if (frameIndex >= totalFrames)
            {
                frameIndex = totalFrames;
            }

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

            UpdateFrame();
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
        }