Ejemplo n.º 1
0
 public Spring()
 {
     TargetHeight = 100;
     Height       = (float)Sgml.random_range(0, 100);
     Speed        = 0.001f;
     Velocity     = 0.001f;
 }
Ejemplo n.º 2
0
        public static void DrawPairsDebug()
        {
            int index = 0;

            Sgml.draw_text(new Vector2(20, 0), "[defined collisions]");

            foreach (var k in DefinedCollisionPairs)
            {
                Sgml.draw_text(new Vector2(20, (index + 1) * 30), k.Key.Object + "(" + k.Key.ColliderName + ")" + " - " + k.Value.Object + "(" + k.Value.ColliderName + ")" + " -->" + k.Key.CollisionAction);
                index++;
            }
        }
Ejemplo n.º 3
0
        public void ApplyAnimation(string sprite, string name)
        {
            obj   = Sgml.currentObject;
            cAnim = Animations.FirstOrDefault(x => x.Sprite == sprite && x.Name == name);

            if (cAnim != null)
            {
                if (!cAnim.Indexes.Contains((int)Sgml.floor(obj.ImageIndex)))
                {
                    obj.ImageIndex = cAnim.Indexes.Min();
                }
            }
        }
Ejemplo n.º 4
0
        public void UpdatePosition()
        {
            float newX    = (float)Sgml.lerp_aggressive(Position.X, TargetPosition.X, TransformSpeed);
            float newY    = (float)Sgml.lerp_aggressive(Position.Y, TargetPosition.Y, TransformSpeed);
            float newZoom = (float)Sgml.lerp_aggressive(Zoom, TargetZoom, TransformSpeed);

            Position.X = newX;
            Position.Y = newY;
            Zoom       = newZoom;

            Camera.Position = new Vector2(newX, newY);
            Camera.Zoom     = (float)Sgml.clamp(Zoom, 0.05, 30);
            Camera.Rotation = Rotation;
            //Camera.Origin = new Vector2(0, 0);
        }
Ejemplo n.º 5
0
        private Particle GenerateNewParticle()
        {
            Texture2D texture  = textures[random.Next(textures.Count)];
            Vector2   position = EmitterLocation;

            double  rr              = random.NextDouble() * 5;
            Vector2 velocity        = new Vector2((float)random.NextDouble() * 5 * Sgml.choose(1, -1), (float)random.NextDouble() * 5 * Sgml.choose(1, -1));
            float   angle           = 0;
            float   angularVelocity = 0.1f * (float)(random.NextDouble() * 5 - 1);
            Color   color           = new Color(
                (float)random.NextDouble(),
                (float)random.NextDouble(),
                (float)random.NextDouble());
            float size = (float)random.NextDouble();
            int   ttl  = 20 + random.Next(40);

            return(new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl, 1));
        }
Ejemplo n.º 6
0
        public static void PackTextures(Texture2D[] textures, int pageSize, int padding = 0)
        {
            // 0. preapare a list of rectangles
            List <Rectangle> cells = new List <Rectangle>();

            cells.Add(new Rectangle(0, 0, pageSize, pageSize));

            // 1. generate TexturePrepacked[] pro Texture2D[]
            TexturePrepacked[] prepacked = new TexturePrepacked[textures.Length];

            for (var i = 0; i < prepacked.Length; i++)
            {
                TexturePrepacked p = new TexturePrepacked();
                p.Tex     = textures[i];
                p.MaxSize = textures[i].Width * textures[i].Height;

                prepacked[i] = p;
            }

            // 2. sort input by maxsize
            prepacked = prepacked.OrderByDescending(x => x.MaxSize).ToArray();

            // 3. generate a new texture page
            RenderTarget2D page = Sgml.surface_create(pageSize, pageSize);

            // 4. find first to fit rectangle for each texture
            Sgml.surface_set_target(page);
            List <RectangleCadidate> candidates = new List <RectangleCadidate>();
            int successful = 0;

            foreach (TexturePrepacked t in prepacked)
            {
                candidates.Clear();
                foreach (Rectangle r in cells)
                {
                    if (t.FitsToRectangle(r, padding))
                    {
                        RectangleCadidate rc = new RectangleCadidate();
                        rc.r        = r;
                        rc.LeftArea = t.LeftArea(r);

                        candidates.Add(rc);
                    }
                }

                if (candidates.Count > 0)
                {
                    // Split this rectangle to two new rectangles
                    Rectangle r  = candidates.OrderBy(x => x.LeftArea).ToList()[0].r;
                    Rectangle r1 = new Rectangle(r.X + t.Tex.Width + padding, r.Y, r.Width - t.Tex.Width - padding, t.Tex.Height);
                    Rectangle r2 = new Rectangle(r.X, r.Y + t.Tex.Height + padding, r.Width, r.Height - t.Tex.Height - padding);

                    Sgml.draw_sprite(t.Tex, -2, new Vector2(r.X, r.Y));

                    cells.Remove(r);
                    cells.Add(r1);
                    cells.Add(r2);
                    successful++;
                }
            }
            Sgml.surface_reset_target();

            Sgml.surface_save(page, "kokotiSurface");
            Sgml.show_message(successful.ToString());
        }
Ejemplo n.º 7
0
 public bool Contains(Vector2 point)
 {
     return(Sgml.point_in_triangle(Point1, Point2, Point3, point) || Sgml.point_in_triangle(Point3, Point4, Point1, point));
 }