Exemplo n.º 1
0
 public void SetShrub(int x, int y, Shrub shrub)
 {
     if (shrub == null)
     {
         SetShrub(x, y, 0);
     }
     else
     {
         SetShrub(x, y, shrub.ID);
     }
 }
Exemplo n.º 2
0
        public static void LoadShrubs()
        {
            // Load all Shrubs subclasses, within the current (calling) assembly.

            var a       = Assembly.GetCallingAssembly();
            var classes = AttributeHelper.GetTypeSubclasses(a, typeof(Shrub));

            Logger.Log("Loading custom shrubs from assembly '{0}'...".Form(a.GetName().Name), ConsoleColor.Cyan);

            foreach (var t in classes)
            {
                bool found = false;
                foreach (var c in t.GetConstructors())
                {
                    if (c.GetParameters().Length == 0)
                    {
                        found = true;
                        var instance = (c.Invoke(new object[] { }));

                        Shrub s = instance as Shrub;
                        if (!Loaded.ContainsKey(s.ID))
                        {
                            Loaded.Add(s.ID, s);
                            if (HighestID < s.ID)
                            {
                                HighestID = s.ID;
                            }
                            Logger.Log("  > " + s.ID + " '" + s.Name + "'");
                            break;
                        }
                        else
                        {
                            Logger.LogError("There is already a shrub registered for ID {0}! '{1}' tried to register with the same ID as '{2}'".Form(s.ID, s.Name, Loaded[s.ID].Name));
                            break;
                        }
                    }
                }
                if (!found)
                {
                    Logger.LogError("There is no zero-argument constructor for custom shrub '{0}'! It will not be registred!".Form(t.FullName));
                }
            }
        }
Exemplo n.º 3
0
        public void Init()
        {
            ShrubTexture = Main.ContentMangager.Load <Texture2D>("Textures/Shrubbery");
            Shrub.LoadShrubs();

            IDs = new byte[Map.Area];

            Random r = new Random();

            for (int x = 0; x < Map.Width; x++)
            {
                for (int y = 0; y < Map.Height; y++)
                {
                    if (r.Next(0, 8) == 0)
                    {
                        SetShrub(x, y, (byte)r.Next(0, Shrub.HighestID + 1));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Draw(SpriteBatch spr)
        {
            int   width  = Map.Width;
            int   height = Map.Height;
            byte  lastID = 0;
            Shrub s      = null;

            var bounds = Map.TileDrawBounds;

            Logger.Log(bounds.X + ", " + bounds.Right);

            for (int x = bounds.X; x < bounds.Right; x++)
            {
                for (int y = bounds.Y; y < bounds.Bottom; y++)
                {
                    int  index = x + y * width;
                    byte id    = IDs[index];

                    if (id != 0)
                    {
                        if (lastID != id)
                        {
                            lastID = id;
                            s      = Shrub.Get(id);
                        }

                        if (s != null)
                        {
                            var colour = s.GetColour(x, y, Map);
                            var source = s.TextureBounds;
                            var dest   = new Rectangle(x * 16, y * 16 - (source.Height - 16), source.Width, source.Height);

                            spr.Draw(ShrubTexture, dest, source, colour, 0f, Vector2.Zero, SpriteEffects.None, Map.GetDepth(y * 16, DepthBias.SHRUBBERY));
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void Dispose()
 {
     Shrub.UnloadShrubs();
     ShrubTexture.Dispose();
 }
Exemplo n.º 6
0
 public Shrub GetShrub(int x, int y)
 {
     return(Shrub.Get(GetShrubID(x, y)));
 }