Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Vector2 MousePositionY;
- Texture2D MousePointer;
- enum GameStates
- {
- Menu, Editor,
- };
- GameStates gamestate = GameStates.Menu;
- PlayerManager mainCharacter;
- MapClass Map1;
- Camera camera;
- int[,] MapGeneratorArray;
- SpriteFont Arial;
- Sprite Leg1;
- Sprite Leg2;
- Sprite Arm1;
- Sprite Arm2;
- Sprite Head;
- Sprite Body;
- Texture2D TileText;
- int MapHeigth, MapWidth;
- int BlockSize = 64;
- bool controllbool;
- Rectangle MouseRect;
- int TileIdet = 0;
- List<Rectangle> TileId = new List<Rectangle>();
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- graphics.PreferredBackBufferHeight = 1080;
- graphics.PreferredBackBufferWidth = 1920;
- MapGeneratorArray = new int[,];
- IsMouseVisible = true;
- graphics.ApplyChanges();
- Map1 = new MapClass();
- base.Initialize();
- }
- protected override void LoadContent()
- {
- TileMap.Content = Content;
- spriteBatch = new SpriteBatch(GraphicsDevice);
- MousePointer = Content.Load<Texture2D>(@"Images/MousePointer");
- Leg1 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/leg1"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
- Leg2 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/leg2"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
- Arm2 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Arm2"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
- Arm1 = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Arm1"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
- Head = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Head"), new Rectangle(0, 0, 64, 64), new Vector2(0), 1);
- Body = new Sprite(true, new Vector2(0), Content.Load<Texture2D>(@"Images/Body"), new Rectangle(0, 0, 64, 128), new Vector2(0), 1);
- TileText = Content.Load<Texture2D>("TileText");
- Arial= Content.Load<SpriteFont>("Arial");
- camera = new Camera(GraphicsDevice.Viewport);
- mainCharacter = new PlayerManager(Leg1, Leg2, Arm1, Arm2, Head, Body, 1, 30, 40, new Rectangle(0,0, 1920, 1080));
- Map1.Generate(MapGeneratorArray, 64);
- }
- protected override void UnloadContent()
- { // TODO: Unload any non ContentManager content here
- }
- protected override void Update(GameTime gameTime)
- {
- KeyboardState keyboard =
- Keyboard.GetState();
- MouseState mouse = Mouse.GetState();
- Rectangle MouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1);
- if (keyboard.IsKeyDown(Keys.Escape))
- this.Exit();
- switch(gamestate)
- {
- case GameStates.Menu:
- if (keyboard.IsKeyDown(Keys.Up))
- {
- MapHeigth++; controllbool = false;
- }
- if (keyboard.IsKeyDown(Keys.Down))
- {
- MapHeigth--; controllbool = false;
- }
- if (keyboard.IsKeyDown(Keys.Left))
- {
- MapWidth--; controllbool = false;
- }
- if (keyboard.IsKeyDown(Keys.Right))
- {
- MapWidth++; controllbool = false;
- }
- if (keyboard.IsKeyDown(Keys.Enter))
- {
- MapGeneratorArray = new int[MapHeigth, MapWidth];
- MapGeneratorArray[1, 1] = 1;
- for (int x = 0; x < MapWidth; x++)
- for (int y = 0; y < MapHeigth; y++)
- {
- TileId.Add(new Rectangle(x * BlockSize, y * BlockSize, BlockSize, BlockSize));
- }
- Map1.Generate(MapGeneratorArray, BlockSize);
- gamestate = GameStates.Editor;
- }
- break;
- case GameStates.Editor:
- mainCharacter.HandleSpriteMovement(gameTime);
- mainCharacter.Update(gameTime);
- foreach (CollisionTiles tile in Map1.CollisionTiles)
- {
- mainCharacter.Collision(tile.Rectangle, Map1.Width, Map1.Height);
- camera.Update(mainCharacter.Position, Map1.Width, Map1.Height);
- }
- if (keyboard.IsKeyDown(Keys.Down) && controllbool == true)
- {
- TileIdet--; controllbool = false;
- }
- if (keyboard.IsKeyDown(Keys.Up) && controllbool == true)
- {
- TileIdet++; controllbool = false;
- }
- if (keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down))
- {
- controllbool = true;
- }
- for (int i = 0; i < TileId.Count; i++)
- {
- for (int y = 0; y < MapWidth; y++)
- {
- for (int x = 0; x < MapHeigth; x++)
- {
- if (TileId[i].Contains(mouse.X, mouse.Y) && mouse.LeftButton == ButtonState.Pressed)
- {
- MapGeneratorArray[x, y] = TileIdet;
- Map1.CollisionTiles.Clear();
- Map1.Generate(MapGeneratorArray, BlockSize);
- break;
- }
- }
- }
- }
- 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)
- {
- MouseState mouse = Mouse.GetState();
- switch (gamestate)
- {
- case GameStates.Menu:
- spriteBatch.Begin();
- spriteBatch.DrawString(Arial, MapHeigth.ToString(), new Vector2(100, 400), Color.White);
- spriteBatch.DrawString(Arial, MapWidth.ToString(), new Vector2(100, 420), Color.White);
- spriteBatch.End();
- break;
- case GameStates.Editor:
- spriteBatch.Begin(SpriteSortMode.Deferred,
- BlendState.AlphaBlend,
- null, null, null, null,
- camera.Transform);
- foreach (Rectangle tele in TileId)
- {
- spriteBatch.Draw(TileText, new Rectangle(tele.X, tele.Y, 64, 64), Color.White);
- }
- Map1.Draw(spriteBatch);
- mainCharacter.Draw(spriteBatch);
- spriteBatch.End();
- break;
- }
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement