Advertisement
Guest User

Untitled

a guest
Nov 4th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.30 KB | None | 0 0
  1. public class Game1 : Microsoft.Xna.Framework.Game
  2. {
  3. GraphicsDeviceManager graphics;
  4. SpriteBatch spriteBatch;
  5.  
  6. Vector2 MousePositionY;
  7.  
  8. Texture2D MousePointer;
  9.  
  10. enum GameStates
  11. {
  12. Menu, Editor,
  13. };
  14.  
  15. GameStates gamestate = GameStates.Menu;
  16.  
  17. PlayerManager mainCharacter;
  18.  
  19. MapClass Map1;
  20.  
  21. Camera camera;
  22.  
  23. int[,] MapGeneratorArray;
  24.  
  25.  
  26. SpriteFont Arial;
  27.  
  28. Sprite Leg1;
  29. Sprite Leg2;
  30. Sprite Arm1;
  31. Sprite Arm2;
  32. Sprite Head;
  33. Sprite Body;
  34.  
  35. Texture2D TileText;
  36.  
  37. int MapHeigth, MapWidth;
  38.  
  39. int BlockSize = 64;
  40.  
  41. bool controllbool;
  42.  
  43. Rectangle MouseRect;
  44.  
  45. int TileIdet = 0;
  46. List<Rectangle> TileId = new List<Rectangle>();
  47.  
  48. public Game1()
  49. {
  50. graphics = new GraphicsDeviceManager(this);
  51. Content.RootDirectory = "Content";
  52. }
  53.  
  54.  
  55. protected override void Initialize()
  56. {
  57. graphics.PreferredBackBufferHeight = 1080;
  58. graphics.PreferredBackBufferWidth = 1920;
  59.  
  60. MapGeneratorArray = new int[,];
  61.  
  62.  
  63. IsMouseVisible = true;
  64.  
  65.  
  66.  
  67. graphics.ApplyChanges();
  68.  
  69. Map1 = new MapClass();
  70.  
  71. base.Initialize();
  72. }
  73.  
  74.  
  75. protected override void LoadContent()
  76. {
  77.  
  78. TileMap.Content = Content;
  79.  
  80. spriteBatch = new SpriteBatch(GraphicsDevice);
  81.  
  82. MousePointer = Content.Load<Texture2D>(@"Images/MousePointer");
  83.  
  84. Leg1 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/leg1"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
  85. Leg2 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/leg2"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
  86. Arm2 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Arm2"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
  87. Arm1 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Arm1"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
  88. Head = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Head"), new Rectangle(0, 0, 64, 64), new Vector2(0), 1);
  89. Body = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Body"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
  90.  
  91.  
  92. TileText = Content.Load<Texture2D>("TileText");
  93. Arial= Content.Load<SpriteFont>("Arial");
  94.  
  95. camera = new Camera(GraphicsDevice.Viewport);
  96.  
  97. mainCharacter = new PlayerManager(Leg1, Leg2, Arm1, Arm2, Head, Body, 1, 30, 40, new Rectangle(0,0, 1920, 1080));
  98.  
  99. Map1.Generate(MapGeneratorArray, 64);
  100.  
  101. }
  102.  
  103.  
  104. protected override void UnloadContent()
  105. { // TODO: Unload any non ContentManager content here
  106. }
  107.  
  108.  
  109. protected override void Update(GameTime gameTime)
  110. {
  111. KeyboardState keyboard =
  112. Keyboard.GetState();
  113. MouseState mouse = Mouse.GetState();
  114. Rectangle MouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1);
  115.  
  116.  
  117.  
  118. if (keyboard.IsKeyDown(Keys.Escape))
  119. this.Exit();
  120.  
  121.  
  122. switch(gamestate)
  123. {
  124.  
  125. case GameStates.Menu:
  126.  
  127.  
  128. if (keyboard.IsKeyDown(Keys.Up))
  129. {
  130.  
  131. MapHeigth++; controllbool = false;
  132.  
  133. }
  134.  
  135. if (keyboard.IsKeyDown(Keys.Down))
  136. {
  137.  
  138. MapHeigth--; controllbool = false;
  139.  
  140. }
  141. if (keyboard.IsKeyDown(Keys.Left))
  142. {
  143.  
  144. MapWidth--; controllbool = false;
  145.  
  146. }
  147. if (keyboard.IsKeyDown(Keys.Right))
  148. {
  149.  
  150. MapWidth++; controllbool = false;
  151.  
  152. }
  153.  
  154.  
  155. if (keyboard.IsKeyDown(Keys.Enter))
  156. {
  157. MapGeneratorArray = new int[MapHeigth, MapWidth];
  158.  
  159. MapGeneratorArray[1, 1] = 1;
  160.  
  161. for (int x = 0; x < MapWidth; x++)
  162. for (int y = 0; y < MapHeigth; y++)
  163. {
  164.  
  165. TileId.Add(new Rectangle(x * BlockSize, y * BlockSize, BlockSize, BlockSize));
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. Map1.Generate(MapGeneratorArray, BlockSize);
  175.  
  176. gamestate = GameStates.Editor;
  177.  
  178.  
  179. }
  180.  
  181.  
  182.  
  183.  
  184. break;
  185.  
  186.  
  187.  
  188. case GameStates.Editor:
  189.  
  190. mainCharacter.HandleSpriteMovement(gameTime);
  191. mainCharacter.Update(gameTime);
  192.  
  193.  
  194.  
  195. foreach (CollisionTiles tile in Map1.CollisionTiles)
  196. {
  197. mainCharacter.Collision(tile.Rectangle, Map1.Width, Map1.Height);
  198. camera.Update(mainCharacter.Position, Map1.Width, Map1.Height);
  199.  
  200. }
  201.  
  202. if (keyboard.IsKeyDown(Keys.Down) && controllbool == true)
  203. {
  204.  
  205. TileIdet--; controllbool = false;
  206.  
  207. }
  208.  
  209. if (keyboard.IsKeyDown(Keys.Up) && controllbool == true)
  210. {
  211.  
  212. TileIdet++; controllbool = false;
  213.  
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. if (keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down))
  225. {
  226.  
  227. controllbool = true;
  228.  
  229. }
  230.  
  231.  
  232.  
  233. for (int i = 0; i < TileId.Count; i++)
  234. {
  235. for (int y = 0; y < MapWidth; y++)
  236. {
  237. for (int x = 0; x < MapHeigth; x++)
  238. {
  239.  
  240.  
  241. if (TileId[i].Contains(mouse.X, mouse.Y) && mouse.LeftButton == ButtonState.Pressed)
  242. {
  243.  
  244.  
  245. MapGeneratorArray[x, y] = TileIdet;
  246. Map1.CollisionTiles.Clear();
  247. Map1.Generate(MapGeneratorArray, BlockSize);
  248. break;
  249.  
  250.  
  251.  
  252.  
  253.  
  254. }
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. }
  264. }
  265. }
  266. break;
  267.  
  268. }
  269.  
  270.  
  271.  
  272.  
  273.  
  274. base.Update(gameTime);
  275. }
  276.  
  277. /// <summary>
  278. /// This is called when the game should draw itself.
  279. /// </summary>
  280. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  281. protected override void Draw(GameTime gameTime)
  282. {
  283.  
  284. MouseState mouse = Mouse.GetState();
  285.  
  286.  
  287.  
  288. switch (gamestate)
  289. {
  290.  
  291. case GameStates.Menu:
  292.  
  293. spriteBatch.Begin();
  294.  
  295.  
  296. spriteBatch.DrawString(Arial, MapHeigth.ToString(), new Vector2(100, 400), Color.White);
  297. spriteBatch.DrawString(Arial, MapWidth.ToString(), new Vector2(100, 420), Color.White);
  298.  
  299.  
  300. spriteBatch.End();
  301.  
  302.  
  303. break;
  304.  
  305. case GameStates.Editor:
  306. spriteBatch.Begin(SpriteSortMode.Deferred,
  307. BlendState.AlphaBlend,
  308. null, null, null, null,
  309. camera.Transform);
  310.  
  311. foreach (Rectangle tele in TileId)
  312. {
  313. spriteBatch.Draw(TileText, new Rectangle(tele.X, tele.Y, 64, 64), Color.White);
  314. }
  315.  
  316.  
  317.  
  318. Map1.Draw(spriteBatch);
  319.  
  320.  
  321.  
  322. mainCharacter.Draw(spriteBatch);
  323. spriteBatch.End();
  324.  
  325. break;
  326.  
  327. }
  328.  
  329.  
  330.  
  331.  
  332.  
  333. base.Draw(gameTime);
  334. }
  335. }
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement