TizzyT

TileTest

Nov 28th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.23 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Input;
  3.  
  4. namespace Game2
  5. {
  6. #if WINDOWS || LINUX
  7.     /// <summary>
  8.     /// The main class.
  9.     /// </summary>
  10.     public static class Program
  11.     {
  12.         static int screenW = 1024, screenH = 576;
  13.         static readonly TileMap Tilemap = new TileMap("C:\\Users\\tizzy\\Desktop\\map\\MSec\\");
  14.         static int worldCoordinateX = 1700;
  15.         static int worldCoordinateY = 0;
  16.         static VisualsManager VM = new VisualsManager();
  17.         static GameManager GM = new GameManager(screenW, screenH);
  18.         static int worldXOffset = 0;
  19.         static int worldYOffset = 0;
  20.         static bool coordinatesChanged = true;
  21.  
  22.         private static ushort testTile = 0;
  23.  
  24.         static void Main()
  25.         {
  26.             using (GM)
  27.             {
  28.                 GM.Logic += Game_Logic;
  29.                 GM.RenderQueue += Game_RenderQueue;
  30.                 GM.Load += Game_Load;
  31.                 GM.Run();
  32.             }
  33.         }
  34.  
  35.         private static void Game_Load(string LoadState)
  36.         {
  37.             switch (LoadState)
  38.             {
  39.                 case "Init":
  40.                     VM.LoadVisualAssetFromFile("player", "C:\\Users\\tizzy\\Desktop\\down0.png");
  41.                     VM.LoadVisualAssetFromFile("waterPond", "C:\\Users\\tizzy\\Desktop\\pond04.png");
  42.                     VM.LoadVisualAssetFromFile("Land", "C:\\Users\\tizzy\\Desktop\\landtile.png");
  43.                     break;
  44.             }
  45.         }
  46.  
  47.         private static void Game_RenderQueue(BufferQueue Buffer)
  48.         {
  49.             for (int y = 0; y < 21; y++)
  50.             {
  51.                 for (int x = 0; x < 35; x++)
  52.                 {
  53.                     switch (Tilemap.Tile(worldCoordinateX + x - 16, worldCoordinateY + y-9))
  54.                     {
  55.                         case 1:
  56.                             Buffer.Draw(VM["waterPond"], new Rectangle(x * 32 + worldXOffset - 32, y * 32 + worldYOffset - 32, 32, 32));
  57.                             break;
  58.                         case 2:
  59.                             Buffer.Draw(VM["Land"], new Rectangle(x * 32 + worldXOffset - 32, y * 32 + worldYOffset - 32, 32, 32));
  60.                             break;
  61.                     }
  62.                 }
  63.             }
  64.             Buffer.Draw(VM["player"], new Rectangle((screenW / 2) - 32, (screenH / 2) - 32, 64, 64));
  65.         }
  66.  
  67.         private static void Game_Logic(string GameState)
  68.         {
  69.             if (GM.KeyDown(Keys.Up))
  70.             {
  71.                 //worldCoordinateY -= 1;
  72.                 if (Tilemap.Tile(worldCoordinateX, worldCoordinateY - 1) != 0)
  73.                 {
  74.                     worldYOffset += 6;
  75.                     if (worldYOffset >= 32)
  76.                     {
  77.                         worldYOffset = 0;
  78.                         worldCoordinateY--;
  79.                     }
  80.                 }                
  81.             }
  82.             else if (GM.KeyDown(Keys.Down))
  83.             {
  84.                 //worldCoordinateY += 1;
  85.                 if (Tilemap.Tile(worldCoordinateX, worldCoordinateY + 1) != 0)
  86.                 {
  87.                     worldYOffset -= 6;
  88.                     if (worldYOffset <= -32)
  89.                     {
  90.                         worldYOffset = 0;
  91.                         worldCoordinateY++;
  92.                     }
  93.                 }
  94.             }
  95.             else if (GM.KeyDown(Keys.Left))
  96.             {
  97.                 //worldCoordinateX -= 1;
  98.                 if (Tilemap.Tile(worldCoordinateX - 1, worldCoordinateY) != 0)
  99.                 {
  100.                     worldXOffset += 6;
  101.                     if (worldXOffset >= 32)
  102.                     {
  103.                         worldXOffset = 0;
  104.                         worldCoordinateX--;
  105.                     }
  106.                 }
  107.             }
  108.             else if (GM.KeyDown(Keys.Right))
  109.             {
  110.                 //worldCoordinateX += 1;
  111.                 if (Tilemap.Tile(worldCoordinateX + 1, worldCoordinateY) != 0)
  112.                 {
  113.                     worldXOffset -= 6;
  114.                     if (worldXOffset <= -32)
  115.                     {
  116.                         worldXOffset = 0;
  117.                         worldCoordinateX++;
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment