Beispiel #1
0
        public void Update(GameTime time)
        {
            UpdateFrame(time);
            if (!InBounds() && gotYat && !Actions.Gameover)
            {
                Actions.Gameover = true;
            }
            float aX = moveSpeed * (float)Math.Cos(attackAngle);
            float aY = moveSpeed * (float)Math.Sin(attackAngle);

            Position.X += aX * Settings.gameSpeed;
            Position.Y += aY * Settings.gameSpeed;
            if (gotYat)
            {
                yat.BirdAngle = attackAngle;
                float cX = yatHoldDistance * (float)Math.Cos(attackAngle);
                float cY = yatHoldDistance * (float)Math.Sin(attackAngle);
                yat.Vector = new Vector2(Position.X + cX, Position.Y + cY);
                float deg = MathHelper.ToDegrees(attackAngle);
                if (deg > 90 && deg < 270)
                {
                    attackAngle = MathHelper.ToRadians(deg + (1 * Settings.gameSpeed));
                }
                else if (deg < 90 && deg > -90)
                {
                    attackAngle = MathHelper.ToRadians(deg - (1 * Settings.gameSpeed));
                }
            }
            if (Attacking && !gotYat)
            {
                Rectangle birdy = GetBoundingBox();
                if (yat != null && !gotYat && !yat.Invulnerable)
                {
                    Rectangle yatBox = yat.GetBoundingBox();
                    if (birdy.Intersects(yatBox))
                    {
                        //TODO
                        gotYat = true;
                        yat.BeingCarriedByBird = true;
                        yat.BirdAngle          = attackAngle;

#if DEBUG
                        Debugger.Log(1, "Main", string.Format("Bird has grabbed yat.\n", GetHashCode()));
#endif
                    }
                }
            }
            else if (!Attacking && !gotYat)
            {
                if (Rand.Next(attackChance) == 0 && InBounds() && !yat.Invulnerable && yat.HitGround) //Attack if by chance and In bounds, and the yat isn't invulnerable
                {
                    Attacking = true;
                    Vector2 yatPos = yat.Vector;
                    attackAngle = (float)Math.Atan2(yatPos.Y - Position.Y, yatPos.X - Position.X);
                    Play();
#if DEBUG
                    Debugger.Log(1, "Main", string.Format("Bird has started to attack at a {0}° angle.\n", MathHelper.ToDegrees(attackAngle)));
#endif
                }
            }
            xpgen.Update(time);
        }
Beispiel #2
0
        public void Update(GameTime time)
        {
            if (Visible)
            {
                UpdateFrame(time);
                if (!Shooting)
                {
                    if (CanMove(faceDirection))
                    {
                        if (faceDirection == Direction.Right)
                        {
                            Position.X += 1 * Settings.gameSpeed;
                        }
                        else
                        {
                            Position.X -= 1 * Settings.gameSpeed;
                        }
                    }
                    else
                    {
                        faceDirection = (faceDirection == Direction.Right) ? Direction.Left : Direction.Right;
                    }
                }

                if (yat != null)
                {
                    Vector2 yatPos = yat.Vector;
                    if (yatPos.Y + yat.Height == Position.Y + frameSize.Y)
                    {
                        float distance = Vector2.Distance(yatPos, Position);
                        if (distance < attackDistance && !Shooting && fireball.Ready())
                        {
                            Attacking         = true;
                            Shooting          = true;
                            fireball.Position = Position;
                            fireball.Play();
                            if (yatPos.X < Position.X)
                            {
                                faceDirection          = Direction.Left;
                                fireball.faceDirection = Direction.Right;
                            }
                            else
                            {
                                faceDirection          = Direction.Right;
                                fireball.faceDirection = Direction.Left;
                            }
                        }
                    }
                    else
                    {
                        Attacking = false;
                    }

                    if (yat.Attacking)
                    {
                        Rectangle hammer = yat.GetBoundingBox();
                        Rectangle bb     = GetBoundingBox();
                        if (hammer.Intersects(bb))
                        {
#if DEBUG
                            Debugger.Log(1, "Main", string.Format("Yat killed mushroom.\n", GetHashCode()));
#endif
                            Score.Points += 1500;
                            Visible       = false;
                            Play();
                            xpgen.Generate(Rand.Next(1, 5), Position);
                        }
                    }
                }
            }
            if (Shooting)
            {
                fireball.Update(time);
                bool      hitYat = false;
                Rectangle fb     = fireball.GetBoundingBox();
                Rectangle theyat = yat.GetBoundingBox();
                if (fb.Intersects(theyat) && !yat.Invulnerable)
                {
                    yat.healthLeft -= fireball.power;
                    hitYat          = true;
#if DEBUG
                    Debugger.Log(1, "Main", string.Format("Fireball inflicted {0} damage on yat. Yat's health left {1}\n", fireball.power, yat.healthLeft));
#endif
                }

                if (fireball.faceDirection == Direction.Left)
                {
                    fireball.Position.X += fireballSpeed * Settings.gameSpeed;
                }
                else
                {
                    fireball.Position.X -= fireballSpeed * Settings.gameSpeed;
                }

                float distanceTraveled = Vector2.Distance(Position, fireball.Position);
                if (distanceTraveled > attackDistance || hitYat)
                {
                    fireball.Position = Position;
                    Shooting          = false;
                    Attacking         = false;
                }
            }
            xpgen.Update(time);
        }