Esempio n. 1
0
        public GameObject testBottom(GameObject a, Vector2 offset, ref Vector2 depth)
        {
            Rectangle aRectangle = new Rectangle((int)a.Position.X, (int)(a.Position.Y + a.AnimationTable.SpriteSourceRectangle.Height * a.Scale + offset.Y), (int)(a.AnimationTable.SpriteSourceRectangle.Width * a.Scale), (int)offset.Y + 2);
            // Boolean collision = false;
               // System.Console.WriteLine(aRectangle);
            foreach (GameObject b in objects)
            {
                if (!b.Equals(a) && b.Solid)
                {
                    Rectangle bRectangle = new Rectangle((int)b.Position.X, (int)b.Position.Y, b.AnimationTable.SpriteSourceRectangle.Width, b.AnimationTable.SpriteSourceRectangle.Height);

                    depth = RectangleExtensions.GetIntersectionDepth(aRectangle, bRectangle);
                        if (depth != Vector2.Zero)
                        {
                            return a;
                        }
                    }
            }

            return null;
        }
Esempio n. 2
0
        public List<GameObject> testBottom(GameObject a, Vector2 offset, ref Vector2 depth, Boolean ignoreSolidFlag = false)
        {
            List<GameObject> hit = new List<GameObject>();

             Rectangle aRectangle = new Rectangle((int)a.Position.X, (int)(a.Position.Y + a.AnimationTable.SpriteSourceRectangle.Height * a.Scale + offset.Y), (int)(a.AnimationTable.SpriteSourceRectangle.Width * a.Scale), (int)offset.Y + 2);
             // Boolean collision = false;
             // System.Console.WriteLine(aRectangle);
             foreach (GameObject b in objects)
             {
                 if (!b.Equals(a) && (b.Solid || ignoreSolidFlag))
                 {
                     Rectangle bRectangle = new Rectangle((int)b.Position.X, (int)b.Position.Y, b.AnimationTable.SpriteSourceRectangle.Width, b.AnimationTable.SpriteSourceRectangle.Height);

                     depth = RectangleExtensions.GetIntersectionDepth(aRectangle, bRectangle);
                     if (depth != Vector2.Zero)
                     {
                         hit.Add(b);
                     }
                 }
             }

             return hit;
        }
Esempio n. 3
0
        public GameObject testLeft(GameObject a, Vector2 offset)
        {
            Rectangle aRectangle = new Rectangle((int)(a.Position.X + offset.X), (int)a.Position.Y, (int)offset.X, (int)(a.AnimationTable.SpriteSourceRectangle.Height * a.Scale));
            // Boolean collision = false;

            foreach (GameObject b in objects)
            {
                if (!b.Equals(a) && b.Solid)
                {
                    Rectangle bRectangle = new Rectangle((int)b.Position.X, (int)b.Position.Y, b.AnimationTable.SpriteSourceRectangle.Width, b.AnimationTable.SpriteSourceRectangle.Height);

                    if (aRectangle.Intersects(bRectangle))
                        return a;
                }
            }

            return null;
        }
Esempio n. 4
0
        public Vector2 testCollision(GameObject a, GameObject b)
        {
            Rectangle aRectangle = new Rectangle((int)(a.Position.X - (a.Width / 2)), (int)(a.Position.Y - (a.Height / 2)), (int)(a.AnimationTable.SpriteSourceRectangle.Width * a.Scale), (int)(a.AnimationTable.SpriteSourceRectangle.Height * a.Scale));
            Rectangle bRectangle = new Rectangle((int)(b.Position.X - (b.Width / 2)), (int)(b.Position.Y - (b.Height / 2)), (int)(b.AnimationTable.SpriteSourceRectangle.Width * b.Scale), (int)(b.AnimationTable.SpriteSourceRectangle.Height * b.Scale));

                return RectangleExtensions.GetIntersectionDepth(aRectangle, bRectangle);
        }
Esempio n. 5
0
        public List<GameObject> testTop(GameObject a, Vector2 offest, Boolean ignoreSolidFlag = false)
        {
            List<GameObject> hit = new List<GameObject>();

            Rectangle aRectangle = new Rectangle((int)a.Position.X, (int)(a.Position.Y + offest.Y), (int)(a.AnimationTable.SpriteSourceRectangle.Width * a.Scale), (int)offest.Y);
            // Boolean collision = false;

            foreach (GameObject b in objects)
            {
                if (!b.Equals(a) && (ignoreSolidFlag || b.Solid))
                {
                    Rectangle bRectangle = new Rectangle((int)b.Position.X, (int)b.Position.Y, b.AnimationTable.SpriteSourceRectangle.Width, b.AnimationTable.SpriteSourceRectangle.Height);

                    if (aRectangle.Intersects(bRectangle))
                        hit.Add(b);
                }
            }

            return hit;
        }
Esempio n. 6
0
 //Adds a game object to this layer
 public void add(GameObject obj)
 {
     objects.Add(obj);
 }
Esempio n. 7
0
 //Removes a game object from this layer
 public Boolean remove(GameObject obj)
 {
     return objects.Remove(obj);
 }
Esempio n. 8
0
        protected void loadLayers()
        {
            player = new Player(new Vector2(100, 100), animationTables["player"], controller);
            player.setAnimation("stand");
            player.ZOrder =1;

            layers.Add("main", new Layer(1f, 1f, 1));
            layers.Add("drops", new Layer(1f, 1f, 2));
            layers.Add("background", new Layer(1f, 0.01f, 1));
            layers.Add("cloud1", new Layer(1f, 0.1f, 10));
            layers.Add("cloud2", new Layer(1f, 0.6f, 5));
            layers.Add("cloud3", new Layer(1f, 1.1f, 3));
            layers.Add("cloud4", new Layer(1f, 1.5f, -1));
            layers.Add("acid", new Layer(1f, 1f, 1));
            layers.Add("smokestack", new Layer(1f, 1f, -1));
            layers.Add("building", new Layer(1f, 1f, -1));
            for (int i = 0; i < 1000; i++)
            {
                layers["drops"].add(new Droplet(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), animationTables["drops"]));

            }

            for (int i = 0; i < 450; i++)
            {
                layers["acid"].add(new Droplet(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), animationTables["acid"]));

            }

            for (int i = 0; i < 32; i++)
            {
                GameObject cloud = new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"]));
                cloud.setAnimation("cloud1");
                layers["cloud1"].add(cloud);

                cloud = new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"]));
                cloud.setAnimation("cloud2");
                layers["cloud2"].add(new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"])));

                cloud = new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"]));
                cloud.setAnimation("cloud3");
                cloud.ZOrder = -1;
                layers["cloud3"].add(new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"])));

                  cloud = new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"]));
                cloud.setAnimation("cloud2");
                cloud.ZOrder = -1;
                layers["cloud4"].add(new GameObject(new Vector2(randomNum.Next(400) + 40, randomNum.Next(90000) + 100), new AnimationTable(animationTables["clouds"])));
            }
            for (int i = 0; i < 10; i++)
            {
                GameObject smokestack = new GameObject(new Vector2(30, 10000+ (i*198)),new AnimationTable(animationTables["buildings"]));
                smokestack.ZOrder = i;
                smokestack.setAnimation("smokestack");
                layers["smokestack"].add(smokestack);
            }

            GameObject building = new GameObject(new Vector2(240, 10000 +(11*198) -256), new AnimationTable(animationTables["buildings"]));
            building.setAnimation("powerplant");
            layers["building"].add(building);

            GameObject background = new GameObject(new Vector2(96, 0), animationTables["background"]);
            background.ZOrder = 1000000;
            layers["main"].add(player);
            layers["background"].add(background);
        }