Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------Game1.cs-----------
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System.Collections.Generic;
- namespace PhysicsStudio_XNA
- {
- /// <summary>
- /// This is the main type for your game.
- /// </summary>
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- SpriteFont spriteFont;
- public const int WINDOW_HEIGHT = 800;
- public const int WINDOW_WIDTH = 600;
- public int tree;
- public TitleScreen titleScreen;
- public SATDemo satDemo;
- public SeparatingAxisTest separatingAxisTest;
- public SATWithAABB sATWithAABB;
- //Mouse Position Test
- public MouseState MouseTestState;
- static int CounterTest;
- GameState currentState;
- public static Dictionary<string, Texture2D> m_textureLibrary = new Dictionary<string, Texture2D>();
- public static Dictionary<string, SpriteFont> m_fontLibrary = new Dictionary<string, SpriteFont>();
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- //graphics.IsFullScreen = true;
- graphics.PreferredBackBufferHeight = WINDOW_HEIGHT;
- graphics.PreferredBackBufferWidth = WINDOW_WIDTH;
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- Mouse.WindowHandle = this.Window.Handle;
- //enable the mousepointer
- IsMouseVisible = true;
- currentState = GameState.TitleScreen;
- //sets the windows mouse handle to client bounds handle
- //Button.
- base.Initialize();
- }
- public void RequestSATDemo()
- {
- currentState = GameState.RequestSATDemo;
- }
- /// <summary>
- /// LoadContent will be called once per game and is the place to load
- /// all of your content.
- /// </summary>
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- m_textureLibrary.Add("Pixel", Content.Load<Texture2D>("White_Pixel"));
- m_fontLibrary.Add("Font", Content.Load<SpriteFont>("MotorwerkOblique"));
- titleScreen = new TitleScreen();
- satDemo = new SATDemo();
- separatingAxisTest = new SeparatingAxisTest();
- sATWithAABB = new SATWithAABB();
- // TODO: use this.Content to load your game content here
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// game-specific content.
- /// </summary>
- public void RequestSeparatingAxisTest()
- {
- currentState = GameState.SeparatingAxisTest;
- }
- public void RequestSATWithAABB()
- {
- currentState = GameState.SATWithAABB;
- }
- /// <summary>
- /// Allows the game to run logic such as updating the world,
- /// checking for collisions, gathering input, and playing audio.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Update(GameTime gameTime)
- {
- MouseTestState = Mouse.GetState();
- switch (currentState)
- {
- case GameState.TitleScreen:
- {
- titleScreen.Update(gameTime);
- break;
- }
- case GameState.SeparatingAxisTest:
- {
- separatingAxisTest.Update(gameTime);
- break;
- }
- case GameState.SATWithAABB:
- {
- sATWithAABB.Update(gameTime);
- break;
- }
- case GameState.Exit:
- {
- Exit();
- break;
- }
- default:
- {
- titleScreen.Update(gameTime);
- break;
- }
- }
- base.Update(gameTime);
- }
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- spriteBatch.Begin();
- spriteBatch.DrawString(m_fontLibrary["Font"], MouseTestState.ToString(), new Vector2(0, 0), Color.White);
- switch (currentState)
- {
- case GameState.TitleScreen:
- {
- titleScreen.Draw(spriteBatch, spriteFont);
- break;
- }
- case GameState.SeparatingAxisTest:
- {
- separatingAxisTest.Draw(gameTime, spriteBatch);
- break;
- }
- case GameState.SATWithAABB:
- {
- sATWithAABB.Draw(gameTime, spriteBatch);
- break;
- }
- case GameState.Exit:
- {
- Exit();
- break;
- }
- default:
- {
- titleScreen.Update(gameTime);
- break;
- }
- }
- spriteBatch.End();
- // TODO: Add your drawing code here
- base.Draw(gameTime);
- }
- }
- }
- ----------TitleScreen.cs
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace PhysicsStudio_XNA
- {
- public class TitleScreen : Screen
- {
- List<Button> buttonList = new List<Button>();
- public Menu mainMenu;
- public TitleScreen()
- {
- mainMenu = new Menu(new Vector2(200, 100), buttonList, 0);
- buttonList.Add(new PushButton("Separating Axis Test"));
- buttonList.Add(new PushButton("SAT With AABB"));
- buttonList.Add(new PushButton("Awesome"));
- buttonList.Add(new PushButton("Awesomere"));
- buttonList.Add(new PushButton("Awesomere"));
- }
- public override void Initialize()
- {
- }
- public override void Update(GameTime gametime)
- {
- mainMenu.Update(gametime);
- }
- public void Draw(SpriteBatch sB, SpriteFont sF)
- {
- mainMenu.Draw(sB, sF);
- }
- }
- }
- ------------PushButton.cs---------
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace PhysicsStudio_XNA
- {
- public class PushButton : Button
- {
- #region Fields
- string m_text;
- SpriteFont m_font;
- Color m_static, m_onClick, m_onHover;
- Texture2D m_sprite2D, m_onClick2D;
- static public int Pbuttoncount;
- //click processing
- bool m_clickedInside = false,
- m_releasedInside = false,
- m_OnClicked = false,
- selected = false;
- //drawing
- Rectangle drawRectangle;
- #endregion
- #region Constructers
- // construter for simple black text PushButton
- public PushButton(string Text)
- {
- m_text = Text;
- drawRectangle = new Rectangle((int)Menu.m_position.X, (int)Menu.m_position.Y + (15 * Pbuttoncount), 200, 15);
- ButtonRegion = new Rectangle((int)Position.X, (int)Position.Y, 200, 15);
- Pbuttoncount++;
- }
- // Constructer that uses colors for Static, OnClick And Onhover
- public PushButton(Rectangle ButtonRegion, SpriteFont Font, string Text, Color Static, Color OnClick, Color OnHover)
- {
- m_buttonRegion = ButtonRegion;
- m_font = Font;
- m_text = Text;
- m_static = Static;
- m_onClick = OnClick;
- m_onHover = OnHover;
- // drawRectangle = ButtonPosition(m_buttonRegion);
- }
- // Constructer that uses Textures for Static, OnClick And Onhover
- public PushButton(Rectangle ButtonRegion, Texture2D Sprite2D, Texture2D OnClick2D)
- {
- m_buttonRegion = ButtonRegion;
- m_sprite2D = Sprite2D;
- m_onClick2D = OnClick2D;
- //drawRectangle = ButtonPosition(m_buttonRegion);
- }
- #endregion
- #region Private Methods
- //public Rectangle ButtonPosition(Rectangle MenuRegion)
- //{
- // return new Rectangle();
- //}
- #endregion
- #region Public Methods
- public override void Update(GameTime gameTime)
- {
- MouseState currentMouse = Mouse.GetState();
- selected = MouseState(drawRectangle, currentMouse);
- m_clickedInside = ClickInside(currentMouse, m_lastMouseState);
- ReleaseInside(currentMouse, m_lastMouseState);
- if (selected && m_clickedInside && m_releasedInside)
- {
- //fire off some event to let our user know that we had a click event.
- m_OnClicked = true;
- }
- else
- {
- m_OnClicked = false;
- }
- m_lastMouseState = currentMouse;
- }
- public override void Draw(SpriteBatch spriteBatch, SpriteFont spriteFont, int buttonCount, Vector2 Position)
- {
- spriteBatch.Draw(Game1.m_textureLibrary["Pixel"], new Rectangle((int)Position.X + 10, (int)(Position.Y + 15 * buttonCount), 180, 15), Color.Wheat);
- if (selected)
- {
- spriteBatch.DrawString(Game1.m_fontLibrary["Font"], m_text, new Vector2(Position.X + 15, Position.Y + 15 * buttonCount), Color.Orange);
- }
- else
- {
- spriteBatch.DrawString(Game1.m_fontLibrary["Font"], m_text, new Vector2(Position.X + 15, Position.Y + 15 * buttonCount), Color.Black);
- }
- }
- #endregion
- }
- }
- -------Menu.cs---------
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace PhysicsStudio_XNA
- {
- public class Menu
- {
- #region Fields
- List<Button> m_buttonList;
- float m_transparency;
- public int n = 0;
- public Rectangle buttonRegion, m_menuRegion, m_dimensions;
- static public Vector2 m_position;
- int m_WINDOW_HEIGHT = Game1.WINDOW_HEIGHT;
- int m_WINDOW_WIDTH = Game1.WINDOW_WIDTH;
- private Game1 m_managerClass;
- #endregion
- #region Constructer
- public Menu(Vector2 Position, List<Button> ButtonList, float Transparency)
- {
- m_position = Position;
- m_buttonList = ButtonList;
- m_transparency = Transparency;
- m_managerClass = new Game1();
- }
- #endregion
- #region Properties
- public Rectangle MenuRegion
- {
- get { return m_menuRegion; }
- set { m_menuRegion = value; }
- }
- static public Vector2 Position
- {
- get { return m_position; }
- }
- #endregion
- #region Public Methods
- public void Update(GameTime gametime)
- {
- for (int i = 0; i < m_buttonList.Count; i++)
- {
- m_buttonList[i].Update(gametime);
- if (m_buttonList[0].OnClicked)
- {
- SeperatingAxisTest();
- }
- }
- }
- public void Draw(SpriteBatch sB, SpriteFont sF)
- {
- sB.Draw(Game1.m_textureLibrary["Pixel"], new Rectangle((int)m_position.X - 5, (int)m_position.Y - 10, (m_buttonList[0].ButtonRegion.Width + 10), (m_buttonList[0].ButtonRegion.Height * m_buttonList.Count) + 20), Color.Blue);
- for (int i = 0; i < m_buttonList.Count; i++)
- {
- m_buttonList[i].Draw(sB, sF, i, new Vector2(Position.X, Position.Y));
- }
- }
- #endregion
- #region Protected Methods
- #endregion
- #region Private Methods
- private void SeperatingAxisTest()
- {
- m_managerClass.RequestSeparatingAxisTest();
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement