Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- {1,1,1,1,1,1,1,1,1,1}
- {0,0,0,0,0,0,0,0,0,0}
- {0,0,0,0,0,0,0,0,0,0}
- }
- class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D gameBackround;
- SpriteFont font;
- int[,] map ;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferWidth = 1920;
- graphics.PreferredBackBufferHeight = 1080;
- graphics.GraphicsProfile = GraphicsProfile.HiDef;
- }
- protected override void LoadContent()
- {
- this.IsMouseVisible = true;
- gameBackround = Content.Load<Texture2D>("level_01_A");//this is the background
- map = new int[gameBackround.Width / 64, gameBackround.Height / 64];
- font = Content.Load<SpriteFont>("Fonts/Font");
- spriteBatch = new SpriteBatch(GraphicsDevice);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.Draw(gameBackround, new Rectangle(0, -700, 3840, 1984), Color.White);
- DrawGrid(map, spriteBatch, font);
- base.Draw(gameTime);
- spriteBatch.End();
- }
- public void DrawGrid(int[,] gameMap, SpriteBatch spriteBatch, SpriteFont f)
- {
- for (int x = 0; x < gameMap.GetLength(1); x++)
- {
- for (int y = 0; y < gameMap.GetLength(0); y++)
- {
- spriteBatch.DrawString(f, x + " / " + y, new Vector2(x * 64, y * 64), Color.White);
- }
- }
- }
- var mouseState = Mouse.GetState();
- if (mouseState.LeftButton == ButtonState.Pressed)
- {
- // do something here
- }
- var xIndex = mouseState.X / 64;
- var yIndex = mouseState.Y / 64;
- map[xIndex, yIndex] = 1;
- if (xIndex >= 0 && xIndex < map.GetLength(0) && yIndex >= 0 && yIndex < map.GetLength(1)) {
- map[xIndex][yIndex] = 1;
- }
- var mouseState = Mouse.GetState();
- if (mouseState.LeftButton == ButtonState.Pressed)
- {
- var xIndex = mouseState.X / 64;
- var yIndex = mouseState.Y / 64;
- if (xIndex >= 0 && xIndex < map.GetLength(0) && yIndex >= 0 && yIndex < map.GetLength(1)) {
- map[xIndex][yIndex] = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement