예제 #1
0
        public void Update()
        {
            time       += 0.06f;
            position.X += (float)(radius * Math.Cos(time)) * (counterClockwise ? -1 : 1);
            position.Y += (float)(radius * Math.Sin(time));
            hitBox.X    = (int)position.X;
            hitBox.Y    = (int)position.Y;

            texture.Update();
        }
예제 #2
0
 public void Update()
 {
     if (hit)
     {
         hitTexture.Update();
     }
     else
     {
         normalTexture.Update();
     }
 }
예제 #3
0
        public int Update(List <Wall> walls)
        {
            int jump;

            if (isNormal)
            {
                normalSprite.Update();
            }
            else
            {
                isNormal = flySprite.Update();
            }

            jump = ProcessKeyboard();

            motion.Y += 0.3F;

            position += motion;
            UpdateHitBox();

            #region Wall collision checking
            foreach (Wall w in walls)
            {
                if (this.hitBox.Intersects(w.hitBox) && w.hitable)
                {
                    Vector2 unit = motion;
                    unit.Normalize();
                    while (this.hitBox.Intersects(w.hitBox))
                    {
                        this.position -= unit;
                        UpdateHitBox();
                    }

                    if (this.hitBox.Left < w.hitBox.Right && this.hitBox.Right > w.hitBox.Left)
                    {
                        if (this.hitBox.Bottom <= w.hitBox.Top)
                        {
                            this.position.Y = w.hitBox.Y - 48;
                        }
                        else
                        {
                            this.position.Y = w.hitBox.Bottom;
                        }
                        motion.Y *= -1;
                        motion.Y -= motion.Y / 3F;
                        if (Math.Abs(motion.Y) > 1)
                        {
                            hitWall.Play(1.0F, 0.0F, 0.0F);
                        }
                    }

                    if (this.hitBox.Top < w.hitBox.Bottom && this.hitBox.Bottom > w.hitBox.Top)
                    {
                        if (this.hitBox.Right <= w.hitBox.Left)
                        {
                            this.position.X = w.hitBox.X - 57;
                        }
                        else
                        {
                            this.position.X = w.hitBox.Right - 7;
                        }
                        motion.X *= -1;
                        motion.X -= motion.X / 3F;
                        if (Math.Abs(motion.X) > 1)
                        {
                            hitWall.Play(1.0F, 0.0F, 0.0F);
                        }
                    }
                }
            }
            #endregion

            return(jump);
        }
예제 #4
0
        public void Update(Angel angel, List <Wall> walls, List <Fish> otherfish)
        {
            Vector2 direction = new Vector2(angel.hitBox.X - hitBox.X, angel.hitBox.Y - hitBox.Y);

            angle = (float)Math.Acos(direction.X / direction.Length());
            if (direction.Y < 0)
            {
                angle *= -1;
            }

            if (angel.position.X > this.position.X && this.motion.X < 7)
            {
                this.motion.X += 0.25f;
            }
            else if (angel.position.X < this.position.X && this.motion.X > -7)
            {
                this.motion.X -= 0.25f;
            }
            if (angel.position.Y > this.position.Y && this.motion.Y < 7)
            {
                this.motion.Y += 0.25f;
            }
            else if (angel.position.Y < this.position.Y && this.motion.Y > -7)
            {
                this.motion.Y -= 0.25f;
            }

            position += motion;
            UpdateHitBox();

            texture.Update();

            foreach (Wall w in walls)
            {
                if (this.hitBox.Intersects(w.hitBox))
                {
                    Vector2 unit = motion;
                    unit.Normalize();
                    while (this.hitBox.Intersects(w.hitBox))
                    {
                        this.position -= unit;
                        UpdateHitBox();
                    }

                    if (this.hitBox.Left < w.hitBox.Right && this.hitBox.Right > w.hitBox.Left)
                    {
                        if (this.hitBox.Bottom <= w.hitBox.Top)
                        {
                            this.position.Y = w.hitBox.Y - 48;
                        }
                        else
                        {
                            this.position.Y = w.hitBox.Bottom;
                        }
                        motion.Y *= -1;
                    }

                    if (this.hitBox.Top < w.hitBox.Bottom && this.hitBox.Bottom > w.hitBox.Top)
                    {
                        if (this.hitBox.Right <= w.hitBox.Left)
                        {
                            this.position.X = w.hitBox.X - 48;
                        }
                        else
                        {
                            this.position.X = w.hitBox.Right;
                        }
                        motion.X *= -1;
                    }
                }
            }
            foreach (Fish w in otherfish)
            {
                if (w == this)
                {
                    continue;
                }
                if (this.hitBox.Intersects(w.hitBox))
                {
                    Vector2 unit = motion;
                    unit.Normalize();
                    while (this.hitBox.Intersects(w.hitBox))
                    {
                        this.position -= unit;
                        UpdateHitBox();
                    }

                    if (this.hitBox.Left < w.hitBox.Right && this.hitBox.Right > w.hitBox.Left)
                    {
                        if (this.hitBox.Bottom <= w.hitBox.Top)
                        {
                            this.position.Y = w.hitBox.Y - 48;
                        }
                        else
                        {
                            this.position.Y = w.hitBox.Bottom;
                        }
                        motion.Y *= -1;
                    }

                    if (this.hitBox.Top < w.hitBox.Bottom && this.hitBox.Bottom > w.hitBox.Top)
                    {
                        if (this.hitBox.Right <= w.hitBox.Left)
                        {
                            this.position.X = w.hitBox.X - 48;
                        }
                        else
                        {
                            this.position.X = w.hitBox.Right;
                        }
                        motion.X *= -1;
                    }
                }
            }
        }