コード例 #1
0
ファイル: Rock.cs プロジェクト: indietom/Outer-Space
        // Method(s)
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            // Move
            Position += new Vector2((float)Math.Cos(Direction) * 3, (float)Math.Sin(Direction) * 3);

            // Hit Player
            if (Box.Intersects(level.Player.Box))
            {
                Dead = true;
                level.CreatePieces(Position, Texture);
                level.Player.TakeDamage(20, 0, DamageType.rock);
                Camera.ScreenShakeTimer = 30;
            }

            // Outside screen
            if (Position.Y - Texture.Height / 2 > Globals.ScreenSize.Y)
            {
                Dead = true;
            }
        }
コード例 #2
0
        // Method(s)
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            // Move
            Position += new Vector2((float)Math.Cos(Direction) * 2.5f, (float)Math.Sin(Direction) * 2.5f);

            // Hit Player
            if (Box.Intersects(level.Player.Box))
            {
                Dead = true;
                level.CreatePieces(Position, Texture);
                level.Player.TakeDamage(15, 0, DamageType.rock, false);
                Camera.ScreenShakeTimer = 30;
            }

            // Outside screen
            if (Position.Y - Texture.Height / 2 > Globals.ScreenSize.Y)
            {
                Dead = true;
            }
        }
コード例 #3
0
ファイル: Shot.cs プロジェクト: kraban/Outer-Space
        // Method(s)

        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            timer--;

            if (firstFrame)
            {
                SoundManager.shoot.Play();
                firstFrame = false;
            }

            // Move
            if (changeSpeed != Speed)
            {
                Speed = MathHelper.Lerp(Speed, changeSpeed, 0.1f);
            }
            Position += new Vector2((float)Math.Cos(Direction) * Speed, (float)Math.Sin(Direction) * Speed);

            // Outside screen
            if (OutsideScreen())
            {
                Dead = true;
            }

            HitTarget(level, this);

            // Hit rock
            if (level.GameObjects.Any(item => item.GetType().Name == "Rock" && item.Box.Intersects(Box)))
            {
                Rock rock = (Rock)level.GameObjects.First(item => item.GetType().Name == "Rock" && item.Box.Intersects(Box));
                level.CreatePieces(rock.Position, rock.Texture);
                rock.Dead = true;
                Dead      = true;
            }
        }
コード例 #4
0
ファイル: Enemy.cs プロジェクト: indietom/Outer-Space
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            if (level.Started)
            {
                // Shoot
                ShootTimer--;
                if (ShootTimer < 0 && ShipLocation == level.Player.ShipLocation && Weapons[SelectedWeapon].Disabled < 0)
                {
                    ShootTimer = 180;
                    Weapons[SelectedWeapon].ShootMethods[Weapons[SelectedWeapon].Action](Position, Direction, 0, level, false);
                }

                // Move
                if (Globals.Randomizer.Next(0, 1001) < 2)
                {
                    if (ShipLocation < level.Player.ShipLocation)
                    {
                        ShipLocation++;
                        DirectionSpeed = -0.0005f;
                    }
                    else if (ShipLocation > level.Player.ShipLocation)
                    {
                        ShipLocation--;
                        DirectionSpeed = 0.0005f;
                    }
                }

                // Die
                if (Health.Value <= 0)
                {
                    Dead = true;

                    // Pieces
                    level.CreatePieces(Position, Texture);
                }
            }
        }
コード例 #5
0
ファイル: Shot.cs プロジェクト: kraban/Outer-Space
        // Method(s)
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            timer--;

            if (firstFrame)
            {
                SoundManager.shoot.Play();
                firstFrame = false;
            }

            // Move
            if (changeSpeed != Speed)
            {
                Speed = MathHelper.Lerp(Speed, changeSpeed, 0.1f);
            }
            Position += new Vector2((float)Math.Cos(Direction) * Speed, (float)Math.Sin(Direction) * Speed);

            // Outside screen
            if (OutsideScreen())
            {
                Dead = true;
            }

            HitTarget(level, this);

            // Hit rock
            if (level.GameObjects.Any(item => item.GetType().Name == "Rock" && item.Box.Intersects(Box)))
            {
                Rock rock = (Rock)level.GameObjects.First(item => item.GetType().Name == "Rock" && item.Box.Intersects(Box));
                level.CreatePieces(rock.Position, rock.Texture);
                rock.Dead = true;
                Dead = true;
            }
        }
コード例 #6
0
        public override void UpdateLevel(Level level)
        {
            base.UpdateLevel(level);

            // Move to normal position after knockback
            Position = new Vector2(Position.X, (float)MathHelper.Lerp(Position.Y, Texture.Height + 40, 0.1f));

            if (level.Started)
            {
                // Shoot
                ShootTimer--;
                if (ShootTimer < 0 && ShipLocation == level.Player.ShipLocation && Weapons[SelectedWeapon].Disabled < 0)
                {
                    ShootTimer = 180;
                    KnockBack  = -3;
                    Weapons[SelectedWeapon].Method(this, Weapons[SelectedWeapon], 0, level, false);
                }

                // Change weapon if not easy difficulty
                if (EnemyDifficulty != Difficulty.Easy && CurrentWeapon.Disabled > 0 && Globals.Randomizer.Next(0, 101) < 2)
                {
                    for (int i = 0; i < Weapons.Count(); i++)
                    {
                        if (Weapons[i].Disabled <= 0)
                        {
                            SelectedWeapon = i;
                        }
                    }
                }

                // Dodge if hard difficulty
                dodgeCooldown--;
                if (EnemyDifficulty == Difficulty.Hard && dodgeCooldown < 0 && (Health.Value / Health.MaxValue) < 0.7)
                {
                    foreach (Shot shot in level.GameObjects.Where(item => item is Shot))
                    {
                        if (shot.Direction > Math.PI)
                        {
                            shot.Direction -= (float)Math.PI * 2f;
                        }
                        if (Globals.Distance(Position, shot.Position) < 100 && Math.Abs(Math.Atan2(Position.Y - shot.Position.Y, Position.X - shot.Position.X) - shot.Direction) < 0.3f)
                        {
                            dodgeCooldown = 180;
                            if (Globals.Randomizer.Next(0, 101) < 30)
                            {
                                if (ShipLocation == Location.left)
                                {
                                    ShipLocation = Location.middle;
                                }
                                else if (ShipLocation == Location.middle)
                                {
                                    ShipLocation = Location.left;
                                }
                                else
                                {
                                    ShipLocation = Location.middle;
                                }
                            }
                        }
                    }
                }

                // Move
                MoveTimer -= 1;
                if (Globals.Randomizer.Next(0, 1001) < 3 + (Health.Value / Health.MaxValue) * 5 && MoveTimer < 0)
                {
                    if (ShipLocation < level.Player.ShipLocation)
                    {
                        ShipLocation++;
                        DirectionSpeed = -0.0005f;
                        ShootTimer     = 60;
                    }
                    else if (ShipLocation > level.Player.ShipLocation)
                    {
                        ShipLocation--;
                        DirectionSpeed = 0.0005f;
                        ShootTimer     = 60;
                    }
                }

                // Die
                if (Health.Value <= 0)
                {
                    Dead = true;
                    SoundManager.explosion.Play();
                    // Pieces
                    level.CreatePieces(Position, Texture);
                }
            }
        }