public override void Update(float dt) { if (IsDead()) { return; } base.Update(dt); if (Game.DEBUG_MOUSE_CONTROLS) { Rotation = (float)Utils.GetAngle(Position, new Vector2f((Mouse.GetPosition(Game.Window).X *Game.ResScale) + ((VideoMode.DesktopMode.Width - Game.Window.GetView().Size.X) / 2), Mouse.GetPosition(Game.Window).Y *Game.ResScale)); return; } if (CanRotate) { if (RotateVelocity < RotateSpeedMax) { RotateVelocity = Math.Min(RotateVelocity + (RotateAcc * dt), RotateSpeedMax); } Rotate(RotateVelocity * dt); } }
protected override void Tick(object source = null, System.Timers.ElapsedEventArgs e = null) { // Calculate random path to Hill if (Waypoint.Equals(new Vector2f(-1, -1))) { int pointCount = Utils.RandomInt(10, 20); float originalAngle = (float)Utils.GetAngle(Game.Hill.Position, Obj.Position); Vector2f destination = Utils.GetPointInDirection(Game.Hill.Position, originalAngle, Game.Hill.Radius - 2); float originalDistance = Utils.Distance(Obj.Position, destination); Vector2f pos; for (int i = 0; i < pointCount; i++) { pos = Utils.GetPointInDirection(Obj.Position, (float)(Utils.GetAngle(Obj.Position, destination)), (originalDistance / pointCount) * (i + 1)); if (i != pointCount - 1 && (i + 1) % 2 == 0) { pos += Utils.GetPointInDirection(new Vector2f(), originalAngle + (Utils.RandomInt() == 1 ? 90 : -90), Utils.RandomInt(10, 60)); } AddWaypointToPath(pos); } PossibleLandmineAtWaypoint = Utils.RandomInt(0, WaypointPath.Count - 1); //Debug_ShowWaypoints(); } base.Tick(source, e); }
public override void Update(float dt) { if (Game.Player != null && Game.Player.HasPowerup(Powerup.FREEZE_TIME)) { return; } base.Update(dt); if (LeavingArea && WaypointPath.Count > 0) { if (!Obj.CanMove) { // Rotate to first waypoint in path float targetAngle = (float)Utils.GetAngle(Obj.Position, WaypointPath[0]); if (Obj.Rotation != targetAngle) { Obj.Rotation = Utils.RotateTowards(Obj.Rotation, targetAngle, 1); } else { Obj.CanMove = true; } } else { Obj.Rotation = (float)Utils.GetAngle(Obj.Position, WaypointPath[WaypointPath.Count - 1]); } } else if ((!ReachedBeach && WaypointPath.Count > 1)) { Obj.Rotation = (float)Utils.GetAngle(Obj.Position, WaypointPath[WaypointPath.Count - 1]); } }
protected override void Tick(object source = null, System.Timers.ElapsedEventArgs e = null) { if (!ReachedBeach && Waypoint.Equals(new Vector2f(-1, -1))) { // Generate path to Beach int pointCount = Utils.RandomInt(3, 8); float originalAngle = (float)Utils.GetAngle(Game.Island.Position, Obj.Position); Vector2f destination = Utils.GetPointInDirection(Game.Island.Position, originalAngle, Game.Island.Radius); float originalDistance = Utils.Distance(Obj.Position, destination); Vector2f pos; for (int i = 0; i < pointCount; i++) { pos = Utils.GetPointInDirection(Obj.Position, (float)(Utils.GetAngle(Obj.Position, destination)), (originalDistance / pointCount) * (i + 1)); if (i != pointCount - 1 && (i + 1) % 2 == 0) { pos += Utils.GetPointInDirection(new Vector2f(), originalAngle + (Utils.RandomInt() == 1 ? 90 : -90), Utils.RandomInt(4, 20)); } AddWaypointToPath(pos); } //Debug_ShowWaypoints(); } base.Tick(source, e); }
public override void Update(float dt) { if (Game.Player != null && Game.Player.HasPowerup(Powerup.FREEZE_TIME)) { return; } base.Update(dt); if (WaypointPath.Count > 1) { float targetAngle = (float)Utils.GetAngle(Obj.Position, WaypointPath[1]); Obj.Rotation = Utils.RotateTowards(Obj.Rotation, targetAngle, 1); } }
public void OnRowboatReachedBeach(Rowboat rowboat) { const float gapX = 4; for (int i = 0; i < rowboat.AmountOfInfantry; i++) { Infantryman enemy = new Infantryman(Game); enemy.SetPosition(Utils.GetPointInDirection( Game.Island.Position, (float)Utils.GetAngle(Game.Island.Position, rowboat.Position) - ((rowboat.AmountOfInfantry / 2) * gapX) + (i * gapX), Game.Island.Radius - 5) ); enemy.Death += OnEnemyDeath; EnemyCount++; Game.Layer_Objects.AddChild(enemy); } }
public void OnShipReachedBeach(Ship ship) { const float gapX = 4; for (int i = 0; i < ship.AmountOfInfantry; i++) { Infantryman enemy = new Infantryman(Game, Utils.RandomInt(0, 5000), ship); enemy.SetPosition(Utils.GetPointInDirection( Game.Island.Position, (float)Utils.GetAngle(Game.Island.Position, ship.Position) - ((ship.AmountOfInfantry / 2) * gapX) + (i * gapX), Game.Island.Radius - 5) ); enemy.Death += OnEnemyDeath; EnemyCount++; Game.Layer_Objects.AddChild(enemy); } }
private void Tick(Object source, ElapsedEventArgs e) { if (!Game.IsRunning()) { return; } int l = 0; int c = 0; for (int py = 0; py < Points.Count; py++) { for (int px = 0; px < Points[py].Count; px++) { // Update Point Points[py][px].Update(UpdateTimerDeltaTime); // Update Display Objects if (px == 0 || py == 0) { continue; } if (Points[py][px].PointLeft != null) { Lines[l].Size = new Vector2f(Utils.Distance(Points[py][px].PointLeft.Position, Points[py][px].Position), Lines[l].Size.Y); Lines[l].Position = Points[py][px].Position; Lines[l].Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointLeft.Position); l++; } if (Points[py][px].PointAbove != null) { Lines[l].Size = new Vector2f(Utils.Distance(Points[py][px].PointAbove.Position, Points[py][px].Position), Lines[l].Size.Y); Lines[l].Position = Points[py][px].Position; Lines[l].Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointAbove.Position); l++; } Corners[c++].Position = Points[py][px].Position; } } }
public virtual void Update(float dt) { // Get T (Waypoint or Target) if (Target != null) { T = Target.Position; } else if (Waypoint.X != -1 && Waypoint.Y != 1) { T = Waypoint; } else { return; } // Move Towards Target/Waypoint if (!Obj.DefaultVelocityApplication && UpdateMoveAngle) { Obj.MoveAngle = (float)Utils.GetAngle(Obj.Position, T, false); } Obj.MoveRight = (Obj.X + Range.X < T.X); Obj.MoveLeft = (Obj.X - Range.X > T.X); if (Obj.CanMoveVertically) { Obj.MoveUp = (Obj.Y - Range.Y > T.Y); Obj.MoveDown = (Obj.Y + Range.Y < T.Y); } if (Target == null && (ForcedStop || !Obj.IsMoving())) { // On Reach Waypoint OnWaypointReached(); ForcedStop = false; Obj.StopMoving(); } }
protected override void Tick(object source = null, System.Timers.ElapsedEventArgs e = null) { if (!Waypoint.Equals(new Vector2f(-1, -1))) { base.Tick(source, e); return; } if (!ReachedBeach) { // Generate path to Beach int pointCount = Utils.RandomInt(10, 20); float originalAngle = (float)Utils.GetAngle(Game.Island.Position, Obj.Position); Vector2f destination = Utils.GetPointInDirection(Game.Island.Position, originalAngle, Game.Island.Radius + 132.5f); float originalDistance = Utils.Distance(Obj.Position, destination); Vector2f pos; for (int i = 0; i < pointCount; i++) { pos = Utils.GetPointInDirection(Obj.Position, (float)(Utils.GetAngle(Obj.Position, destination)), (originalDistance / pointCount) * (i + 1)); if (i != pointCount - 1 && (i + 1) % 2 == 0) { pos += Utils.GetPointInDirection(new Vector2f(), originalAngle + (Utils.RandomInt() == 1 ? 90 : -90), Utils.RandomInt(10, 40)); } AddWaypointToPath(pos); } //Debug_ShowWaypoints(); } else if (((Ship)Obj).AmountOfInfantry <= 0) { // Generate path off screen LeavingArea = true; Obj.CanMove = false; // Can't move until Ship rotates to first waypoint in path if (Obj.Model is AnimatedSprite) { Obj.Model.Sprite.Color = new Color(255, 255, 255, 100); if (Obj.FlashOnDamageBright) { Obj.FlashOnDamageOriginalColor = Obj.Model.Color; // just in case the Ship's Colour has already been changed temporarily } Obj.Model.Play(); } else { Obj.Model.Color = new Color(255, 255, 255, 100); if (Obj.FlashOnDamageBright) { Obj.FlashOnDamageOriginalColor = Obj.Model.Color; // just in case the Ship's Colour has already been changed temporarily } } int pointCount = Utils.RandomInt(4, 15); float originalAngle = (float)Utils.GetAngle(Game.Island.Position, Obj.Position) + (Utils.RandomInt(50, 80) * (Utils.RandomInt() == 1 ? 1 : -1)); Vector2f intersectPoint = Utils.RaycastAgainstBounds(Game.Bounds, Game.Center, Utils.GetPointInDirection(Game.Center, originalAngle, Game.Size.X)); Vector2f destination = Utils.GetPointInDirection(intersectPoint, originalAngle, 200); float originalDistance = Utils.Distance(Obj.Position, destination); Vector2f pos; for (int i = 0; i < pointCount; i++) { pos = Utils.GetPointInDirection(Obj.Position, (float)(Utils.GetAngle(Obj.Position, destination)), (originalDistance / pointCount) * (i + 1)); if (i != pointCount - 1 && (i + 1) % 2 == 0) { pos += Utils.GetPointInDirection(new Vector2f(), originalAngle + (Utils.RandomInt() == 1 ? 90 : -90), Utils.RandomInt(10, 40)); } AddWaypointToPath(pos); } } base.Tick(source, e); }
public WaterRipples(Game Game, Vector2f Size, int Gap = 90, int LineThickness = 8, Color Colour = default(Color)) { this.Game = Game; //Colour = new Color(94, 190, 255, 255); // Generate Points int GAP_HALF = Gap / 2; int yc = 0; for (int py = -GAP_HALF; py < Size.Y + Gap; py += Gap) { Points.Add(new List <WaterRipplePoint>()); for (int px = -GAP_HALF; px < Size.X + Gap; px += Gap) { WaterRipplePoint p = new WaterRipplePoint(px, py); if (Points[yc].Count != 0) { p.PointLeft = Points[yc][Points[yc].Count - 1]; } if (yc != 0) { p.PointAbove = Points[yc - 1][Points[yc].Count]; } Points[yc].Add(p); } yc++; } // add random additional points int yCount = Points.Count; for (int py = 1; py < yCount; py++) { int xCount = Points[py].Count; int px; for (px = 1; px < xCount; px++) { // add random additional points along the y axis (just add them at the end of the current x List) if (Utils.RandomInt(0, 3) == 0) { continue; } WaterRipplePoint pointY = new WaterRipplePoint(Points[py][px].X + (Utils.RandomInt((int)(Gap * 0.1), (int)(Gap * 0.4)) * (Utils.RandomInt() == 1 ? 1 : -1)), Points[py][px].Y + GAP_HALF); pointY.PointAbove = Points[py][px]; Points[py].Add(pointY); if (py < Points.Count - 1) { Points[py + 1][px].PointAbove = pointY; } } for (px = 1; px < xCount; px++) { // add random additional points along the x axis if (Utils.RandomInt(0, 3) == 0) { continue; } WaterRipplePoint pointX = new WaterRipplePoint(Points[py][px - 1].X + GAP_HALF, Points[py][px].Y + (Utils.RandomInt((int)(Gap * 0.1), (int)(Gap * 0.4)) * (Utils.RandomInt() == 1 ? 1 : -1))); pointX.PointLeft = Points[py][px - 1]; pointX.MoveDirection.X = Utils.RandomInt() == 1 || px == Points[py].Count - 1 ? Points[py][px - 1].MoveDirection.X : Points[py][px + 1].MoveDirection.X; Points[py].Insert(px, pointX); Points[py][px + 1].PointLeft = Points[py][px]; px++; xCount++; } } Displace(); // Draw for (int py = 1; py < Points.Count; py++) { for (int px = 1; px < Points[py].Count; px++) { RectangleShape l; if (Points[py][px].PointLeft != null) { l = new RectangleShape(new Vector2f(Utils.Distance(Points[py][px].PointLeft.Position, Points[py][px].Position), LineThickness)); l.FillColor = Colour; l.Origin = new Vector2f(0, LineThickness / 2); l.Position = Points[py][px].Position; l.Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointLeft.Position); AddChild(l); Lines.Add(l); } if (Points[py][px].PointAbove != null) { l = new RectangleShape(new Vector2f(Utils.Distance(Points[py][px].PointAbove.Position, Points[py][px].Position), LineThickness)); l.FillColor = Colour; l.Origin = new Vector2f(0, LineThickness / 2); l.Position = Points[py][px].Position; l.Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointAbove.Position); AddChild(l); Lines.Add(l); } CircleShape corner = new CircleShape(LineThickness / 2); corner.FillColor = Colour; corner.Origin = new Vector2f(corner.Radius, corner.Radius); corner.Position = Points[py][px].Position; AddChild(corner); Corners.Add(corner); } } }