public override void Update() { var rect = new Rect(Text.GetGlobalBounds()); var mousePressed = Mouse.IsButtonPressed(Mouse.Button.Left); if (rect.Contains(Game.MousePosition)) { if (mousePressed && rect.Contains(Game.MousePressStart)) { if (!IsPressed) NotifyOnClick(); IsPressed = true; Text.Scale = new Vector2f(0.9f, 0.9f); } else { IsPressed = false; Text.Scale = new Vector2f(1.1f, 1.1f); } } else { Text.Scale = new Vector2f(1.0f, 1.0f); } rect = new Rect(Text.GetGlobalBounds()); Text.Origin = (Vector2f)new Vector(rect.Width * 0.25, rect.Height * 0.25); }
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; } }
public Rect(Rect v) { this.Position = v.Position; this.Size = v.Size; }
/// <summary>Check intersection between two rects.</summary> /// <param name="rect"> Rect to test.</param> /// <param name="overlap">Rect to be filled with overlapping rect.</param> /// <returns>True if rects overlap.</returns> public bool Intersects(Rect rect, out Rect overlap) { var left = Math.Max(X, rect.X); var top = Math.Max(Y, rect.Y); var right = Math.Min(X + Width, rect.X + rect.Width); var bottom = Math.Min(Y + Height, rect.Y + rect.Height); if ((left < right) && (top < bottom)) { overlap = new Rect(left, top, right - left, bottom - top); return true; } else { overlap = new Rect(); return false; } }
/// <summary>Check intersection between two rects.</summary> /// <param name="rect"> rect to test.</param> /// <returns>True if rects overlap.</returns> public bool Intersects(Rect rect) { return Math.Max(X, rect.X) < Math.Min(X + Width, rect.X + rect.Width) && Math.Max(Y, rect.Y) < Math.Min(Y + Height, rect.Y + rect.Height); }
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; } }