Example #1
0
 public Entity(EntityType type, int x, int y)
 {
     Type = type.Id;
     Health = 100;
     Area = new Rectangle(x * 24, y * 24 - ((type.Height - 1) * 24), type.Width * 24, type.Height * 24);
     Solid = type.Solid;
     Events = new List<Event>();
     AltSprite = false;
 }
Example #2
0
 public bool Add(int x, int y, EntityType type)
 {
     if (Get(x, y) != null) { return false; }
     Entities.Add(new Entity(type, x, y));
     return true;
 }
Example #3
0
 public void Initialize(ContentManager content)
 {
     Texture = content.Load<Texture2D>("furniture");
     Types[0] = new EntityType(1, "Door", content.Load<Texture2D>("Entities/door"), 1, 3, true, EntityType.EntityFunction.Door);
     //Entities.Add(new Entity(Types[0], 10, 10));
 }
Example #4
0
        /// <summary>
        /// Returns wether an entity can be placed
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool CanPlaceEntity(EntityType type, int x, int y)
        {
            if (Blocks[x, y + 1] == null) { return false; }
            for (int x_upto = x; x_upto < x + type.Width; x_upto++)
            {
                for (int y_upto = y; y_upto > y - type.Height; y_upto--)
                {
                    if (!inBounds(x_upto, y_upto)) { continue; }
                    if (Blocks[x_upto, y_upto] != null) { return false; }
                    if (Fluids.Water.Blocks[x_upto, y_upto] != 0) { return false; }
                    if (Flora.Flora[x_upto, y_upto] != null) { return false; }
                }
            }

            Rectangle rect = new Rectangle(x * 24, y * 24, type.Width * 24, type.Height * 24);
            foreach (Entity entity in Entities.Entities)
            {
                if (entity.Area.Intersects(rect))
                    return false;
            }

            return true;
        }