Advertisement
Guest User

Game1.cs

a guest
Jun 30th, 2019
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework.Input;
  6.  
  7. namespace EngineTest.MacOS
  8. {
  9. public class Game1 : Game
  10. {
  11. GraphicsDeviceManager graphics;
  12. SpriteBatch spriteBatch;
  13.  
  14. private List<Entity> _entities;
  15.  
  16.  
  17. public Game1()
  18. {
  19. graphics = new GraphicsDeviceManager(this);
  20. Content.RootDirectory = "Content";
  21. graphics.IsFullScreen = false;
  22. graphics.PreferredBackBufferHeight = 720;
  23. graphics.PreferredBackBufferWidth = 1280;
  24.  
  25. }
  26.  
  27. protected override void Initialize()
  28. {
  29.  
  30. base.Initialize();
  31.  
  32. }
  33.  
  34.  
  35. protected override void LoadContent()
  36. {
  37.  
  38. spriteBatch = new SpriteBatch(GraphicsDevice);
  39. var playerTexture = Content.Load<Texture2D>("box");
  40. var blockTexture = Content.Load<Texture2D>("Block");
  41. var font = Content.Load<SpriteFont>("font");
  42. _entities = new List<Entity>()
  43. {
  44. new Player(playerTexture)
  45. {
  46. Position = new Vector2(100, 200),
  47. },
  48. new Block(blockTexture)
  49. {
  50. Position = new Vector2(120, 384),
  51. },
  52. new Block(blockTexture)
  53. {
  54. Position = new Vector2(120, 368),
  55. },
  56. new Block(blockTexture)
  57. {
  58. Position = new Vector2(120, 352),
  59. },
  60. new Block(blockTexture)
  61. {
  62. Position = new Vector2(120, 336),
  63. },
  64. };
  65. for (var i = 0f; i < 1280/16f; i++)
  66. {
  67. _entities.Add(
  68. new Block(blockTexture)
  69. {
  70. Position = new Vector2(i*16, 400),
  71.  
  72. }
  73. );
  74. }
  75.  
  76. }
  77.  
  78.  
  79. protected override void Update(GameTime gameTime)
  80. {
  81.  
  82. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  83. Exit();
  84. foreach (var entity in _entities)
  85. entity.Update(gameTime, _entities);
  86.  
  87. base.Update(gameTime);
  88. }
  89.  
  90. protected override void Draw(GameTime gameTime)
  91. {
  92. graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  93.  
  94. spriteBatch.Begin();
  95. foreach (var entity in _entities)
  96. entity.Draw(spriteBatch);
  97. spriteBatch.End();
  98.  
  99. base.Draw(gameTime);
  100. }
  101. }
  102. }
Advertisement
RAW Paste Data Copied
Advertisement