Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. public class Game1 : Microsoft.Xna.Framework.Game
  2. {
  3. GraphicsDeviceManager graphics;
  4. SpriteBatch spriteBatch;
  5.  
  6. Tile tl = new Tile();
  7.  
  8. public Game1()
  9. {
  10. graphics = new GraphicsDeviceManager(this);
  11. Content.RootDirectory = "Content";
  12.  
  13. graphics.PreferredBackBufferWidth = 1280;
  14. graphics.PreferredBackBufferHeight = 960;
  15. //graphics.IsFullScreen = true;
  16.  
  17.  
  18. }
  19.  
  20. protected override void Initialize()
  21. {
  22. // TODO: Add your initialization logic here
  23.  
  24. base.Initialize();
  25. }
  26.  
  27. protected override void LoadContent()
  28. {
  29. spriteBatch = new SpriteBatch(GraphicsDevice);
  30. Content.RootDirectory = "Content";
  31. }
  32.  
  33. protected override void UnloadContent()
  34. {
  35. // TODO: Unload any non ContentManager content here
  36. }
  37.  
  38. protected override void Update(GameTime gameTime)
  39. {
  40. // Allows the game to exit
  41. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  42. this.Exit();
  43.  
  44. // TODO: Add your update logic here
  45.  
  46. base.Update(gameTime);
  47. }
  48.  
  49. /// <summary>
  50. /// This is called when the game should draw itself.
  51. /// </summary>
  52. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  53. ///
  54.  
  55. inputForm iForm = new inputForm();
  56.  
  57. bool[,] centerPiece = new bool[,] { { false, true, false }, { true, true, true }, { false, true, false } };
  58. bool[,] cornerPiece = new bool[,] { { false, true, false }, { true, true, false }, { false, false, false } };
  59. bool[,] stairPiece = new bool[,] { { false, true, false }, { true, true, true }, { false, false, false } };
  60. bool[,] straightPiece = new bool[,] { { false, true, false }, { false, true, false }, { false, true, false } };
  61. protected override void Draw(GameTime gameTime)
  62. {
  63. GraphicsDevice.Clear(Color.White);
  64.  
  65. // Draw the sprite.
  66. spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
  67.  
  68. //Draw centerPiece
  69. tl.centerPiece(spriteBatch, centerPiece);
  70.  
  71. spriteBatch.End();
  72.  
  73. base.Draw(gameTime);
  74.  
  75. //iForm.Show();
  76. }
  77. }
  78.  
  79. public class Tile : Microsoft.Xna.Framework.Game
  80. {
  81. GraphicsDeviceManager graphics;
  82. public float spacing = 32f;
  83. public Texture2D squareTex;
  84.  
  85. public Vector2 IMGCenter()
  86. {
  87. Vector2 imageCenter = new Vector2(4 / 2f, 4 / 2f);
  88. return imageCenter;
  89. }
  90.  
  91. public Vector2 screenView()
  92. {
  93. Viewport viewport = GraphicsDevice.Viewport;
  94. Vector2 screenCenter = new Vector2(viewport.Width / 2f, viewport.Height / 2f);
  95. return screenCenter;
  96. }
  97.  
  98. public Tile()
  99. {
  100.  
  101. }
  102.  
  103. public void centerPiece(SpriteBatch batch, bool[,] squareCombo)
  104. {
  105. for (int x = 0; x < squareCombo.GetLength(0); x++)
  106. {
  107. for (int y = 0; y < squareCombo.GetLength(1); y++)
  108. {
  109. if (squareCombo[x, y] == true)
  110. {
  111. Vector2 offset = new Vector2(x, y) * spacing;
  112. Vector2 position = IMGCenter() + offset;
  113.  
  114. batch.Draw(squareTex, screenView(), null, Color.White, 0f, position, 1f, SpriteEffects.None, 0f);
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. Viewport viewport = GraphicsDevice.Viewport;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement