Exemple #1
0
 public Triangle(Vector2 p1, Vector2 p2, Vector2 p3)
 {
     points[0] = p1;
     points[1] = p2;
     points[2] = p3;
     cr = new CollisionRect(int.MaxValue,int.MaxValue);
 }
Exemple #2
0
        public Tile(object imageName = null, SpriteBatch sb = null, int frameWidth = 0, int frameHeight = 0)
        {
            img = new List<Texture2D>();

            if (imageName != null)
            {
                if (imageName.GetType() == typeof(Texture2D))
                    img.Add((Texture2D)imageName);
                else if (imageName.GetType() == typeof(String))
                    img.Add(g.Content.Load<Texture2D>((String)imageName));
                else throw new Exception("Error type in Tile initializing");

                if (frameWidth == 0) frameWidth = img[0].Width;
                if (frameHeight == 0) frameHeight = img[0].Height;
                contour = new Rectangle(0, 0, frameWidth, frameHeight);
                center = new Vector2(frameWidth / 2, frameHeight / 2);
                currFrameRect = new Rectangle(0,0,frameWidth,frameHeight);
                this.frameWidth = frameWidth;
                this.frameHeigth = frameHeigth;
            }

            passable = true;
            options = new Dictionary<string, string>();
            this.sb = sb;
            position = new Vector2(0, 0);
            collisionContur = CreateContour(contour);
            cr = new CollisionRect(int.MaxValue, int.MaxValue);
            luaEvents = new Dictionary<string, List<LuaFunction>>();
        }
Exemple #3
0
 public Triangle(Vector2 p1, Vector2 p2, Vector2 p3)
 {
     points[0] = p1;
     points[1] = p2;
     points[2] = p3;
     cr        = new CollisionRect(int.MaxValue, int.MaxValue);
 }
Exemple #4
0
 public CollisionRect Reindex(Vector2 offset, Rectangle collisionRectangle)
 {
     foreach (Tile t in tiles)
     {
         cr = t.Reindex(offset + position, collisionRectangle);
     }
     return(cr);
 }
Exemple #5
0
 public static bool isNear(CollisionRect a, CollisionRect b)
 {
     if   (a.x - 1 <= b.x &&
           a.x + 1 >= b.x &&
           a.y - 1 <= b.y &&
           a.y + 1 >= b.y   ) return true;
     else return false;
 }
Exemple #6
0
 public CollisionRect Reindex(Vector2 offset, Rectangle collisionRectangle)
 {
     foreach (Triangle trgl in collisionContur)
     {
         cr = trgl.Reindex(offset + position, collisionRectangle);
     }
     return(cr);
 }
Exemple #7
0
 public Actor(Rectangle profile, string name = "",float angle = 0)
 {
     this.profile = profile;
     this.name = name;
     this.position = new Vector2(profile.X,profile.Y);
     this.angle = angle;
     tiles = new List<Tile>();
     cr = new CollisionRect(int.MaxValue,int.MaxValue);
     RotateSpeed = 2.7f;
     luaEvents = new Dictionary<string, List<LuaFunction>>();
 }
Exemple #8
0
 public Actor(String name, Tile t,int x,int y)
 {
     profile = new Rectangle();
     this.name = name;
     this.position = new Vector2(x,y);
     tiles = new List<Tile>();
     cr = new CollisionRect(int.MaxValue, int.MaxValue);
     RotateSpeed = 2.7f;
     AddTile(t, 0, 0);
     luaEvents = new Dictionary<string, List<LuaFunction>>();
 }
Exemple #9
0
 public Actor(Rectangle profile, string name = "", float angle = 0)
 {
     this.profile  = profile;
     this.name     = name;
     this.position = new Vector2(profile.X, profile.Y);
     this.angle    = angle;
     tiles         = new List <Tile>();
     cr            = new CollisionRect(int.MaxValue, int.MaxValue);
     RotateSpeed   = 2.7f;
     luaEvents     = new Dictionary <string, List <LuaFunction> >();
 }
Exemple #10
0
 public Actor(String name, Tile t, int x, int y)
 {
     profile       = new Rectangle();
     this.name     = name;
     this.position = new Vector2(x, y);
     tiles         = new List <Tile>();
     cr            = new CollisionRect(int.MaxValue, int.MaxValue);
     RotateSpeed   = 2.7f;
     AddTile(t, 0, 0);
     luaEvents = new Dictionary <string, List <LuaFunction> >();
 }
Exemple #11
0
 public static bool isNear(CollisionRect a, CollisionRect b)
 {
     if (a.x - 1 <= b.x &&
         a.x + 1 >= b.x &&
         a.y - 1 <= b.y &&
         a.y + 1 >= b.y)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #12
0
 public bool TryCollision(Actor act, Vector2 offsetActor, Vector2 globalOffset)
 {
     if (!CollisionRect.isNear(cr, act.cr))
     {
         return(false);
     }
     foreach (Tile t in act.tiles)
     {
         if (TryCollision(t, act.position + offsetActor + globalOffset, position + globalOffset, act.angle))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #13
0
 public bool TryCollision(Tile t, Vector2 tileOffset, Vector2 testOffset, float angle)
 {
     if (!CollisionRect.isNear(cr, t.cr))
     {
         return(false);
     }
     foreach (Tile myTile in tiles)
     {
         if (myTile.TryCollision(t, testOffset, tileOffset, angle))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #14
0
 public bool Collision(Actor act, Vector2 offset)
 {
     foreach (Tile t in data)
     {
         if (CollisionRect.isNear(act.cr, t.cr) &&
             act.Collision(t, offset, true))
         {
             if (onCollision != null)
             {
                 onCollision(this, act);
             }
             return(true);
         }
     }
     return(false);
 }
Exemple #15
0
        public Tile(object imageName = null, SpriteBatch sb = null, int frameWidth = 0, int frameHeight = 0)
        {
            img = new List <Texture2D>();

            if (imageName != null)
            {
                if (imageName.GetType() == typeof(Texture2D))
                {
                    img.Add((Texture2D)imageName);
                }
                else if (imageName.GetType() == typeof(String))
                {
                    img.Add(g.Content.Load <Texture2D>((String)imageName));
                }
                else
                {
                    throw new Exception("Error type in Tile initializing");
                }

                if (frameWidth == 0)
                {
                    frameWidth = img[0].Width;
                }
                if (frameHeight == 0)
                {
                    frameHeight = img[0].Height;
                }
                contour          = new Rectangle(0, 0, frameWidth, frameHeight);
                center           = new Vector2(frameWidth / 2, frameHeight / 2);
                currFrameRect    = new Rectangle(0, 0, frameWidth, frameHeight);
                this.frameWidth  = frameWidth;
                this.frameHeigth = frameHeigth;
            }

            passable        = true;
            options         = new Dictionary <string, string>();
            this.sb         = sb;
            position        = new Vector2(0, 0);
            collisionContur = CreateContour(contour);
            cr        = new CollisionRect(int.MaxValue, int.MaxValue);
            luaEvents = new Dictionary <string, List <LuaFunction> >();
        }
Exemple #16
0
 public bool Collision(Tile t, Vector2 tileOffset, bool collisionEventFlag = false)
 {
     if (!CollisionRect.isNear(cr, t.cr))
     {
         return(false);
     }
     foreach (Tile myTile in tiles)
     {
         if (myTile.Collision(t, this.position, tileOffset))
         {
             if (onCollision != null && collisionEventFlag)
             {
                 onCollision(this, t);
             }
             if (collisionEventFlag)
             {
                 Raise("oncollision", this, t);
             }
             return(true);
         }
     }
     return(false);
 }
Exemple #17
0
 public CollisionRect Reindex(Vector2 offset, Rectangle collisionRectangle)
 {
     foreach (Tile t in tiles)
     {
         cr = t.Reindex(offset + position, collisionRectangle);
     }
     return cr;
 }
Exemple #18
0
 public CollisionRect Reindex(Vector2 offset, Rectangle collisionRectangle)
 {
     foreach (Triangle trgl in collisionContur)
         cr = trgl.Reindex(offset + position, collisionRectangle);
     return cr;
 }