Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
                }
            }
        }