Example #1
0
        public override void Update()
        {
            var delta = (float)Game.Delta.TotalSeconds;
            var rect = new Rect(new Vector(0, 0), Game.Target.GetView().Size);
            var steps = (int)(Speed / 50);
            var step = Speed / steps;

            for (int i = 0; i < steps; i++)
            {
                Position += Direction * step * delta;

                foreach (var enemy in Space.GetGroup<Enemy>("Enemies"))
                {
                    var radius = Bullet.BodyRadius + enemy.Radius;

                    if (Position.IsInRangeOf(enemy.Position, radius))
                    {
                        this.IsDeleted = true;
                        enemy.OffsetHealth(Damage);
                        break;
                    }
                }
            }

            if (!rect.Contains(Position))
            {
                this.IsDeleted = true;
                return;
            }
        }
Example #2
0
        private void Spawn()
        {
            var viewSize = (Vector)Game.Target.GetView().Size;
            var pos = new Vector();

            var percent = MathExtender.Random.NextDouble();
            var side = MathExtender.Random.Next(0, 4);

            if (side == 0)
            {
                pos.X = viewSize.X * percent;
                pos.Y = -Enemy.BodyRadius * 2;
            }
            else if (side == 1)
            {
                pos.X = viewSize.X * percent;
                pos.Y = viewSize.Y + Enemy.BodyRadius * 2;
            }
            else if (side == 2)
            {
                pos.X = -Enemy.BodyRadius * 2;
                pos.Y = viewSize.Y * percent;
            }
            else
            {
                pos.X = viewSize.X + Enemy.BodyRadius * 2;
                pos.Y = viewSize.Y * percent;
            }

            Space.Add(new Enemy(pos));
        }
Example #3
0
        public Bullet(Player owner, Vector direction, double damage)
            : base(Sorting.Group, "Bullets", 3)
        {
            Shape = new CircleShape(BodyRadius, 3);
            Shape.FillColor = BodyColor;
            Shape.Origin = new Vector2f(BodyRadius, BodyRadius);

            Direction = direction;
            Position = owner.Position + direction * Player.BodyRadius;
            Damage = damage;
        }
Example #4
0
        public Flame(Player owner, Vector direction, double damage)
            : base(Sorting.Group, "Flames", 0)
        {
            Owner = owner;
            BodyShape = new CircleShape(BodyRadius, 5);
            BodyShape.FillColor = BodyColor;
            BodyShape.Origin = new Vector2f(BodyRadius, BodyRadius);

            Direction = direction;
            Position = owner.Position + direction * Player.BodyRadius;
            Damage = damage;

            Game.Sounds.Prepare(ref SFX_FireLoop, "Campfire");
        }
Example #5
0
        public Corpse(float bodyRadius, float meleeRadius, Vector position, Vector facing)
            : base(Sorting.Group, "Corpses", -1)
        {
            BodyShape = new CircleShape(bodyRadius, 8);
            BodyShape.FillColor = Color;
            BodyShape.Origin = new Vector2f(bodyRadius, bodyRadius);

            MeleeShape = new CircleShape(meleeRadius, 3);
            MeleeShape.FillColor = Color;
            MeleeShape.Origin = new Vector2f(meleeRadius, meleeRadius);

            Position = position;
            MeleeShape.Rotation = (float)facing.Angle;
            MeleeShape.Position = (Vector2f)(Position + facing * meleeRadius * 2);
        }
Example #6
0
        public Powerup(PowerupType type, double amount, Vector position)
            : base(Sorting.Group, "Powerups", 3)
        {
            BodyShape = new RectangleShape();
            BodyShape.Size = new Vector2f(BodyRadius, BodyRadius);
            BodyShape.Origin = BodyShape.Size * 0.5f;
            BodyShape.FillColor = BodyColor;

            Type = type;
            Amount = amount;
            Position = position;

            Game.Sounds.Prepare(ref SFX_Create, "Blip2", 10, 1.0f);
            Game.Sounds.Prepare(ref SFX_Pickup, "Powerup1", 10, 1.0f);

            SFX_Create.Play();
        }
Example #7
0
        public Enemy(Vector position)
            : base(Sorting.Group, "Enemies", 2)
        {
            var roll = MathExtender.Roll(Chance_Fast, Chance_Big);

            if (roll == 0)
            {
                Color = new Color(255, 0, 255);
                Speed = 150;
                Health = new Stat(50);
                Radius = BodyRadius * 0.75f;
                MeleeTime = TimeSpan.FromSeconds(0.4);
                MeleeDamage = -5;
            }
            else if (roll == 1)
            {
                Color = new Color(0, 255, 0);
                Speed = 25;
                Health = new Stat(5000);
                Radius = BodyRadius * 2.0f;
                MeleeTime = TimeSpan.FromSeconds(0.8);
                MeleeDamage = -75;
            }
            else
            {
                Color = new Color(255, 0, 0);
                Speed = 50;
                Health = new Stat(100);
                Radius = BodyRadius;
                MeleeTime = TimeSpan.FromSeconds(1.5);
                MeleeDamage = -10;
            }

            Position = position;
            BodyShape.FillColor = Color;
            BodyShape.Radius = Radius;
            BodyShape.Origin = new Vector2f(Radius, Radius);
            MeleeRadius = Radius / 2.0f;
            MeleeShape = new CircleShape(MeleeRadius, 3);
            MeleeShape.Origin = new Vector2f(MeleeRadius, MeleeRadius);
            MeleeShape.FillColor = Color;

            ApplyDifficulty();
        }
Example #8
0
 /// <summary>Gets whether or not this vector in within a certain range of another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>Whether or not this vector is in range.</returns>
 public bool IsInRangeOf(Vector v, double range)
 {
     var x = this.X - v.X;
     var y = this.Y - v.Y;
     return (range * range) >= (x * x + y * y);
 }
Example #9
0
 /// <summary>Gets the distance between this and another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>The distance.</returns>
 public double DistanceTo(Vector v)
 {
     return (this - v).Length;
 }
Example #10
0
 /// <summary>Gets the dot product relative to another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>The dot product.</returns>
 public double DotProduct(Vector v)
 {
     return this.X * v.X + this.Y * v.Y;
 }
Example #11
0
 /// <summary>Gets the angle between this and another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>The angle in degrees.</returns>
 public double AngleBetweenVector(Vector v)
 {
     return MathExtender.RadianToDegree(Math.Acos(v.Normal.DotProduct(this.Normal)));
 }
Example #12
0
 /// <summary>Gets the directional vector from this to another vector in degrees.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>The direction.</returns>
 public Vector DirectionTo(Vector v)
 {
     return (v - this).Normal;
 }
Example #13
0
 /// <summary>Get whether or not this vector is parallel to another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>Whether or not this vector is parallel.</returns>
 public bool IsParallelTo(Vector v)
 {
     return (this.X / v.X) == (this.Y / v.Y);
 }
Example #14
0
 public Rect(SFML.Window.Vector2f position, SFML.Window.Vector2f size)
 {
     this.Position = new Vector(position);
     this.Size = new Vector(size);
 }
Example #15
0
 public Rect(double x = 0, double y = 0, double width = 0, double height = 0)
 {
     this.Position = new Vector(x, y);
     this.Size = new Vector(width, height);
 }
Example #16
0
 /// <summary>Check if a point is inside the rect's area.</summary>
 /// <param name="x">X coordinate of the point to test.</param>
 /// <param name="y">Y coordinate of the point to test.</param>
 /// <returns>True if the point is inside.</returns>
 public bool Contains(Vector v)
 {
     return (v.X >= X) && (v.X < X + Width)
         && (v.Y >= Y) && (v.Y < Y + Height);
 }
Example #17
0
        private void Move()
        {
            var delta = (float)Game.Delta.TotalSeconds;
            var direction = new Vector();

            if (Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                direction.Y -= 1;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                direction.Y += 1;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                direction.X -= 1;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                direction.X += 1;
            }

            Movement += direction * Speed * delta;
            var newPosition = Position + Movement;
            var viewSize = Game.Target.GetView().Size;

            if (newPosition.X < 0 || newPosition.X > viewSize.X)
            {
                newPosition.X = Position.X;
            }

            if (newPosition.Y < 0 || newPosition.Y > viewSize.Y)
            {
                newPosition.Y = Position.Y;
            }

            Position = newPosition;
            Movement.X = Movement.Y = 0;
        }
Example #18
0
 /// <summary>Check intersection between two rects.</summary>
 /// <param name="position"> Position of the rect to test.</param>
 /// <param name="size"> rect to test.</param>
 /// <returns>True if r overlap.</returns>
 public bool Intersects(Vector position, Vector size)
 {
     return Math.Max(X, position.X) < Math.Min(X + Width, position.X + size.X)
         && Math.Max(Y, position.Y) < Math.Min(Y + Height, position.Y + size.Y);
 }
Example #19
0
 public void Move(Vector offset)
 {
     Movement += offset;
 }
Example #20
0
 public Rect(Vector position, Vector size)
 {
     this.Position = position;
     this.Size = size;
 }
Example #21
0
 public Rect(SFML.Graphics.FloatRect v)
 {
     this.Position = new Vector(v.Left, v.Top);
     this.Size = new Vector(v.Width, v.Height);
 }
Example #22
0
 public Vector(Vector v)
 {
     this.X = v.X;
     this.Y = v.Y;
 }
Example #23
0
 public MenuButton(string str, uint size, Vector position)
 {
     Text = new Text(str, Game.Assets.Fonts["PixelPlay"], size);
     Text.Position = (Vector2f)position;
     Text.Color = Color.White;
 }
Example #24
0
 /// <summary>Get whether or not this vector is opposite to another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>Whether or not this vector is opposite.</returns>
 public bool IsOppositeTo(Vector v)
 {
     var x = this.X / v.X;
     return (x < 0) && (x == (this.Y / v.Y));
 }
Example #25
0
        public override void Update()
        {
            var flameCount = Space.CountGroup("Flames");
            SFX_FireLoop.Volume = Math.Min(SFX_FireLoop.Volume = flameCount, 25);

            if (SFX_FireLoop.Status != SoundStatus.Playing && flameCount > 0)
            {
                SFX_FireLoop.Play();
            }

            var rotation = MathExtender.Random.Next(1, 15);
            BodyShape.Rotation = (BodyShape.Rotation + rotation) % 360;

            var phase = Math.Max(0, LifeTime.TotalSeconds / InitialLifeTime.TotalSeconds);
            var red = (byte)Math.Min(MathExtender.Lerp(0, 3 * 255, phase), 255);
            var green = (byte)MathExtender.Lerp(0, 255, phase);
            BodyShape.FillColor = new Color(red, green, 0, green);

            var rect = new Rect(new Vector(0, 0), Game.Target.GetView().Size);

            if (Range < MaxRange)
            {
                var newPosition = Position + Direction * Speed * Game.Delta.TotalSeconds;

                if (rect.Contains(newPosition))
                {
                    Range += Position.DistanceTo(newPosition);
                    Position = newPosition;
                }

                if (Range >= MinRange && MathExtender.Chance(Range / (MaxRange * 2)))
                {
                    Range = MaxRange;
                }
            }

            LifeTime -= Game.Delta;

            foreach (var enemy in Space.GetGroup<Enemy>("Enemies"))
            {
                var radius = Bullet.BodyRadius + enemy.Radius;

                if (MathExtender.Chance(0.25) && Position.IsInRangeOf(enemy.Position, radius * 1.5))
                {
                    enemy.OffsetHealth(Damage);
                    Range = MaxRange;

                    if (AttachedTo == null)
                    {
                        var scale = (enemy.Radius / Flame.BodyRadius) * 1.25f * Size;
                        BodyShape.Scale = new Vector2f(scale, scale);
                        AttachedTo = enemy;
                    };
                }
            }

            if (AttachedTo != null)
            {
                Position = AttachedTo.Position;
                AttachedTo.OffsetHealth(Damage);

                if (AttachedTo.Health.IsMinimum)
                    AttachedTo = null;
            }
            else
            {
                var x = MathExtender.Clamp(BodyShape.Scale.X * (MathExtender.Random.Next(20) - 10), 1, 1.75);
                var y = MathExtender.Clamp(BodyShape.Scale.Y * (MathExtender.Random.Next(40) - 20), 1, 1.75);
                BodyShape.Scale = new Vector2f((float)x, (float)y) * Size;
            }

            if (LifeTime <= TimeSpan.Zero)
            {
                SFX_FireLoop.Volume = Math.Max(SFX_FireLoop.Volume - 1, 0);
                IsDeleted = true;
            }
        }
Example #26
0
 /// <summary>Gets the manhattan distance between this and another vector.</summary>
 /// <param name="v">The other vector.</param>
 /// <returns>The manhattan distance.</returns>
 public double ManhattanDistanceTo(Vector v)
 {
     return Math.Abs(this.X - v.X) + Math.Abs(this.Y - v.Y);
 }
Example #27
0
 public Rect(Rect v)
 {
     this.Position = v.Position;
     this.Size = v.Size;
 }