예제 #1
0
        public virtual void LoadContent()
        {
            Texture = game.Content.Load <Texture2D>(TextureName);
            // Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            //batch to draw the bounding box
            boundingBatch = new PrimitiveBatch(game.GraphicsDevice);

            if (Physical)
            {
                //create the physics body and geometry
                uint[] data = new uint[Texture.Width * Texture.Height];

                //Transfer the texture data to the array
                Texture.GetData(data);
                //get geom, assign to static body
                Vertices verts      = Vertices.CreatePolygon(data, Texture.Width, Texture.Height);
                Vector2  polyOrigin = verts.GetCentroid();
                Origin.X = (float)Math.Round(polyOrigin.X);
                Origin.Y = (float)Math.Round(polyOrigin.Y);

                PhysicsBody          = BodyFactory.Instance.CreatePolygonBody(physicsManager.Simulator, verts, 1);
                PhysicsBody.Position = WorldPosition;
                PhysicsBody.IsStatic = true;
                PhysicsGeometry      = GeomFactory.Instance.CreatePolygonGeom(physicsManager.Simulator, PhysicsBody, verts, 0);
            }

            BoundingBox = new Rectangle((int)WorldPosition.X - Texture.Width / 2, (int)WorldPosition.Y - Texture.Height / 2, Texture.Width, Texture.Height);
        }
예제 #2
0
        protected override void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (components != null)
                    {
                        foreach (GUIComponent c in components)
                        {
                            c.Dispose();
                        }
                        components.Clear();
                    }

                    if (batch != null)
                    {
                        batch.Dispose();
                        batch = null;
                    }

                    if (primBatch != null)
                    {
                        primBatch.Dispose();
                        primBatch = null;
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     // TODO: Add your initialization code here
     batch     = new PrimitiveBatch(Game.GraphicsDevice);
     textBatch = new SpriteBatch(Game.GraphicsDevice);
     font      = Game.Content.Load <SpriteFont>(@"Fonts\Console");
 }
예제 #4
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     // TODO: Add your initialization code here
     batch           = new SpriteBatch(Game.GraphicsDevice);
     font            = Game.Content.Load <SpriteFont>(@"Fonts\Console");
     primBatch       = new PrimitiveBatch(Game.GraphicsDevice);
     Bounds          = new Rectangle(Convert.ToInt32(Location.X), Convert.ToInt32(Location.Y), Convert.ToInt32(boxDimensions.X), Convert.ToInt32(boxDimensions.Y));
     BackgroundColor = Color.WhiteSmoke;
     CurrentColour   = BackgroundColor;
 }
예제 #5
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     // TODO: Add your initialization code here
     batch             = new SpriteBatch(Game.GraphicsDevice);
     font              = Game.Content.Load <SpriteFont>(@"Fonts\Console");
     primBatch         = new PrimitiveBatch(Game.GraphicsDevice);
     captionPosition   = new Vector2(Location.X + textPaddingSide, Location.Y + textPaddingTopAndBottom);
     captionDimensions = font.MeasureString(Caption);
     titleBarBounds    = new Rectangle(Convert.ToInt32(Bounds.X), Convert.ToInt32(Bounds.Y), Convert.ToInt32(Bounds.Width), Convert.ToInt32(captionDimensions.Y + (2 * textPaddingTopAndBottom)));
 }
예제 #6
0
        protected override void LoadContent()
        {
            input     = (InputHandler)Game.Services.GetService(typeof(IInputHandler));
            batch     = new PrimitiveBatch(GraphicsDevice);
            textBatch = new SpriteBatch(GraphicsDevice);

            font          = Game.Content.Load <SpriteFont>(@"Fonts\Console");
            textHeight    = font.MeasureString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").Y;
            consoleHeight = Convert.ToInt32(textHeight * maxLines + (maxLines * 2));
            bounds        = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, 0);
            base.LoadContent();
        }
예제 #7
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     // TODO: Add your initialization code here
     batch     = new SpriteBatch(Game.GraphicsDevice);
     font      = Game.Content.Load <SpriteFont>(@"Fonts\Console");
     primBatch = new PrimitiveBatch(Game.GraphicsDevice);
     //get the height of this font (we use capital Y because it's generally pretty tall)
     fontDimensions = font.MeasureString("Y");
     //set bounds
     Bounds = new Rectangle(Convert.ToInt32(Location.X), Convert.ToInt32(Location.Y), Convert.ToInt32(Length), Convert.ToInt32(fontDimensions.Y + (textPaddingTopAndBottom * 2)));
     //set position of the text
     textPosition = new Vector2(Location.X + textPaddingSide, Location.Y + textPaddingTopAndBottom);
 }
예제 #8
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (!disposed)
     {
         if (disposing)
         {
             if (batch != null)
             {
                 batch.Dispose();
                 batch = null;
             }
             if (primBatch != null)
             {
                 primBatch.Dispose();
                 primBatch = null;
             }
         }
     }
 }
예제 #9
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (!disposed)
     {
         if (disposing)
         {
             if (batch != null)
             {
                 batch.Dispose();
                 batch = null;
             }
             if (primBatch != null)
             {
                 primBatch.Dispose();
                 primBatch = null;
             }
             if (UpButton != null)
             {
                 UpButton.Dispose();
                 UpButton = null;
             }
             if (DownButton != null)
             {
                 DownButton.Dispose();
                 DownButton = null;
             }
             if (PosBar != null)
             {
                 PosBar.Dispose();
                 PosBar = null;
             }
             components.Clear();
             foreach (GUIComponent c in Items)
             {
                 c.Dispose();
             }
             Items.Clear();
         }
     }
 }
예제 #10
0
        protected override void LoadContent()
        {
            base.LoadContent();
            artBatch  = new SpriteBatch(GraphicsDevice);
            gridBatch = new PrimitiveBatch(GraphicsDevice);

            input   = (InputHandler)Game.Services.GetService(typeof(IInputHandler));
            camera  = (Camera)Game.Services.GetService(typeof(ICamera));
            console = (DeveloperConsole)Game.Services.GetService(typeof(IDeveloperConsole));

            guimanager = (GUIManager)Game.Services.GetService(typeof(IGUIManager));

            console.MessageHandler += new DeveloperConsole.DeveloperConsoleMessageHandler(ConsoleMessageHandler);
            LoadLevel(LevelFilename);

            InitEditor();
            //Random r = new Random();
            //for (var i = 0; i < 100; i++)
            //{
            //    DynamicObjects.Add(new DynamicLevelObject(Game, new Vector2(r.Next(200)-100, 50 - r.Next(400)), @"LevelArt\WallTest01"));
            //}
        }
예제 #11
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            // TODO: Add your initialization code here
            batch     = new SpriteBatch(Game.GraphicsDevice);
            font      = Game.Content.Load <SpriteFont>(@"Fonts\Console");
            primBatch = new PrimitiveBatch(Game.GraphicsDevice);

            // Set up visible items
            if (numItems > Items.Count)
            {
                numItems = Items.Count;
            }


            // Initialise the buttons
            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.Initialize();
                lbi.Parent = this;

                if (font.MeasureString(lbi.Name).X > maxWidth)
                {
                    maxWidth = font.MeasureString(lbi.Name).X;
                }
                lbi.OnMouseClick += new GUIListBoxItem.MouseClickHandler(SelectItem);
            }

            maxWidth += 20;

            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.boxDimensions.X = maxWidth;
            }

            // And set the initial locations
            UpdateList();

            components = new List <GUIComponent>();

            // Get width of the listbox
            float boxHeight = (numItems - 1) * Items[0].Bounds.Height;

            // Display Down button
            DownButton = new GUIButton(Game, new Vector2(maxWidth, boxHeight + 20), new Vector2(20, 20), "down", "+");
            DownButton.Initialize();
            DownButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollDown);
            DownButton.UpdateLocation(DownButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(DownButton);

            // Display Up button
            UpButton = new GUIButton(Game, new Vector2(maxWidth, 20), new Vector2(20, 20), "up", "-");
            UpButton.Initialize();
            UpButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollUp);
            UpButton.UpdateLocation(UpButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(UpButton);

            // Calculate bar intervals
            barIntervals = ((boxHeight - 20) / Items.Count);

            PosBar = new GUIButton(Game, new Vector2(maxWidth, 40), new Vector2(20, barIntervals * numItems), "bar", "");
            PosBar.BackgroundColor = HighlightColor;
            PosBar.AllowHold       = true;
            PosBar.Initialize();
            PosBar.OnMouseHold += new GUIButton.MouseClickHandler(DragScroll);
            PosBar.UpdateLocation(PosBar.Location + new Vector2(Location.X, Location.Y));
            components.Add(PosBar);

            currentItem = new GUILabel(Game, new Vector2(0, 0), new Vector2(maxWidth, 20), "label", "Select ...");
            currentItem.Initialize();
            currentItem.BackgroundColor = Color.AntiqueWhite;
            currentItem.UpdateLocation(currentItem.Location + new Vector2(Location.X, Location.Y));
            components.Add(currentItem);

            OpenCloseList = new GUIButton(Game, new Vector2(maxWidth, 0), new Vector2(20, 20), "openclose", "+");
            OpenCloseList.Initialize();
            OpenCloseList.OnMouseClick += new GUIButton.MouseClickHandler(OCList);
            OpenCloseList.UpdateLocation(OpenCloseList.Location + new Vector2(Location.X, Location.Y));
            components.Add(OpenCloseList);
        }