Advertisement
The_Spu

Untitled

Nov 21st, 2021
2,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.45 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using MonoGame.Extended;
  5. using MonoRogue.Cells;
  6. using MonoRogue.Entities;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Runtime.CompilerServices;
  13. using Myra.Graphics2D.UI;
  14. using Myra;
  15. using Microsoft.Xna.Framework.Content;
  16. using MonoRogue.UI;
  17. using System.Text.RegularExpressions;
  18.  
  19. namespace MonoRogue
  20. {
  21.     /// <summary>
  22.     /// This is the main type for your game.
  23.     /// </summary>
  24.  
  25.     public enum Scene { MainMenu, Game };
  26.     public enum Direction { North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest };
  27.  
  28.     public class Game1 : Game
  29.     {
  30.         private readonly string version = "0.0.0";
  31.         private Scene currentScene;
  32.         private readonly Random rng = new Random();
  33.         private readonly GraphicsDeviceManager graphicsManager;
  34.         private SpriteBatch spriteBatch;
  35.         private RenderTarget2D mapRenderTarget;
  36.         private MapObject cameraTarget;
  37.         private KeyboardState currentKeyboardState;
  38.         private KeyboardState previousKeyboardState;
  39.         private MouseState currentMouseState;
  40.         private MouseState previousMouseState;
  41.         private TextConsole textConsole;
  42.         private Desktop myraDesktop;
  43.  
  44.         // Managers
  45.         private FactionManager factionManager;
  46.  
  47.         // Settings
  48.         private bool showDebug;
  49.  
  50.         // Fonts
  51.         private SpriteFont font_bigblue_12;
  52.         //private SpriteFont font_trenchthin_12;
  53.  
  54.         // Textures
  55.         private List<Texture2D> NoiseTextures;
  56.  
  57.         // Maps
  58.         private Map currentMap;
  59.  
  60.         // Entities
  61.         private Player player;
  62.  
  63.         public Scene CurrentScene { get => currentScene; set => currentScene = value; }
  64.  
  65.         public void LoadMap(string mapName)
  66.         {
  67.             currentMap = new Map(graphicsManager.GraphicsDevice ,Content, $"Maps/{mapName}.txt", factionManager);
  68.             if (player == null)
  69.             {
  70.                 player = new Player(Content, currentMap.GetRandomEmptyFloor(), new List<Faction> { factionManager.PlayerFaction });
  71.             }
  72.             else
  73.             {
  74.                 player.ParentMap = currentMap;
  75.  
  76.                 Cell spawnPoint = currentMap.GetRandomEmptyFloor();
  77.                 player.ParentCell = spawnPoint;
  78.                 spawnPoint.Entity = player;
  79.                 player.X = spawnPoint.X;
  80.                 player.Y = spawnPoint.Y;
  81.             }
  82.             currentMap.UpdateCellVisibility(player);
  83.         }
  84.  
  85.         public Game1()
  86.         {
  87.             graphicsManager = new GraphicsDeviceManager(this)
  88.             {
  89.                 PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width,
  90.                 PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height,
  91.                 PreferMultiSampling = false,
  92.                 IsFullScreen = true,
  93.             };
  94.  
  95.             IsMouseVisible = true;
  96.             Content.RootDirectory = "Content";
  97.             //IsFixedTimeStep = true;            
  98.             //TargetElapsedTime = TimeSpan.
  99.         }
  100.  
  101.         /// <summary>
  102.         /// Allows the game to perform any initialization it needs to before starting to run.
  103.         /// This is where it can query for any required services and load any non-graphic
  104.         /// related content.  Calling base.Initialize will enumerate through any components
  105.         /// and initialize them as well.
  106.         /// </summary>
  107.         protected override void Initialize()
  108.         {
  109.             // Add your initialization logic here
  110.             graphicsManager.PreferredBackBufferWidth = 1920;
  111.             graphicsManager.PreferredBackBufferHeight = 1080;
  112.             graphicsManager.ApplyChanges();
  113.  
  114.             CurrentScene = Scene.Game;
  115.             factionManager = new FactionManager();
  116.  
  117.             base.Initialize();
  118.         }
  119.  
  120.         /// <summary>
  121.         /// LoadContent will be called once per game and is the place to load
  122.         /// all of your content.
  123.         /// </summary>
  124.         protected override void LoadContent()
  125.         {
  126.             // Create a new SpriteBatch, which can be used to draw textures
  127.             spriteBatch = new SpriteBatch(GraphicsDevice);
  128.  
  129.             // Use this.Content to load your game content below
  130.  
  131.             // Fonts
  132.             font_bigblue_12 = Content.Load<SpriteFont>("Fonts/BigBlue TerminalPlus 12");
  133.             // font_trenchthin_12 = Content.Load<SpriteFont>("Fonts/Trench Thin 12");
  134.  
  135.             // Procedurally generated textures.
  136.             NoiseTextures = new List<Texture2D>();
  137.             for (int i = 0; i < 32; i++)
  138.             {
  139.                 NoiseTextures.Add(TextureUtility.GenerateNoiseTexture(graphicsManager.GraphicsDevice, 16, 16));
  140.             }
  141.  
  142.             // Map initialization
  143.             LoadMap("pacman");
  144.  
  145.             // Myra
  146.             MyraEnvironment.Game = this;
  147.  
  148.             var consolePanel = new Panel();
  149.             var consoleGrid = new Grid
  150.             {
  151.                 RowSpacing = 8,
  152.                 ColumnSpacing = 8
  153.             };
  154.             var consoleLabel = new Label
  155.             {
  156.                 Id = "label",
  157.                 Text = ""
  158.             };
  159.             var consoleTextBox = new TextBox()
  160.             {
  161.             };
  162.  
  163.             textConsole = new TextConsole(consoleLabel, consoleTextBox, "grave.txt", 8);
  164.  
  165.             consolePanel.Top = (GraphicsDevice.Viewport.Height - 189);
  166.             consolePanel.Width = GraphicsDevice.Viewport.Width;
  167.  
  168.             consoleGrid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
  169.             consoleGrid.RowsProportions.Add(new Proportion(ProportionType.Auto));
  170.  
  171.             consoleTextBox.Top = 168;
  172.             consoleTextBox.Width = GraphicsDevice.Viewport.Width;
  173.  
  174.             consoleLabel.Width = GraphicsDevice.Viewport.Width;
  175.  
  176.             consoleGrid.Widgets.Add(consoleLabel);
  177.             consoleGrid.Widgets.Add(consoleTextBox);
  178.             consolePanel.Widgets.Add(consoleGrid);
  179.  
  180.             // Add it to the desktop
  181.             myraDesktop = new Desktop
  182.             {
  183.                 Root = consolePanel,
  184.  
  185.                 // Inform Myra that external text input is available
  186.                 // So it stops translating Keys to chars
  187.                 HasExternalTextInput = true
  188.             };
  189.  
  190.             // Provide that text input
  191.             Window.TextInput += (s, a) =>
  192.             {
  193.                 myraDesktop.OnChar(a.Character);
  194.             };
  195.  
  196.         }
  197.  
  198.         /// <summary>
  199.         /// UnloadContent will be called once per game and is the place to unload
  200.         /// game-specific content.
  201.         /// </summary>
  202.         protected override void UnloadContent()
  203.         {
  204.             // Unload any non ContentManager content here
  205.         }
  206.  
  207.         /// <summary>
  208.         /// Allows the game to run logic such as updating the world,
  209.         /// checking for collisions, gathering input, and playing audio.
  210.         /// </summary>
  211.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  212.         protected override void Update(GameTime gameTime)
  213.         {
  214.             /*
  215.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  216.                 Exit();
  217.             */
  218.  
  219.             // Add your update logic here
  220.  
  221.             UpdateGame(gameTime);
  222.         }
  223.  
  224.         private void UpdateGame(GameTime gameTime)
  225.         {
  226.             currentMap.UpdateCellVisibility(player);
  227.             cameraTarget = player;
  228.             currentKeyboardState = Keyboard.GetState();
  229.             currentMouseState = Mouse.GetState();
  230.  
  231.             HandleKeyboardInput();
  232.             HandleMouseInput();
  233.  
  234.             base.Update(gameTime);
  235.             previousKeyboardState = currentKeyboardState;
  236.             previousMouseState = currentMouseState;
  237.  
  238.             // Helpers
  239.             void HandleKeyboardInput()
  240.             {
  241.                 switch(CurrentScene)
  242.                 {
  243.                     default:
  244.                     case Scene.MainMenu:
  245.                         break;
  246.                     case Scene.Game:
  247.                         foreach (Keys key in currentKeyboardState.GetPressedKeys())
  248.                         {
  249.                             if (textConsole.MyraTextBox.IsKeyboardFocused == false)
  250.                             {
  251.                                 if (previousKeyboardState.IsKeyUp(key))
  252.                                 {
  253.                                     switch (key)
  254.                                     {
  255.                                         case Keys.Up:
  256.                                         case Keys.NumPad8:
  257.                                             player.MoveDirection(Direction.North);
  258.                                             currentMap.Tick();
  259.                                             break;
  260.                                         case Keys.Down:
  261.                                         case Keys.NumPad2:
  262.                                             player.MoveDirection(Direction.South);
  263.                                             currentMap.Tick();
  264.                                             break;
  265.                                         case Keys.Left:
  266.                                         case Keys.NumPad4:
  267.                                             player.MoveDirection(Direction.West);
  268.                                             currentMap.Tick();
  269.                                             break;
  270.                                         case Keys.Right:
  271.                                         case Keys.NumPad6:
  272.                                             player.MoveDirection(Direction.East);
  273.                                             currentMap.Tick();
  274.                                             break;
  275.                                         case Keys.NumPad9:
  276.                                             player.MoveDirection(Direction.NorthEast);
  277.                                             currentMap.Tick();
  278.                                             break;
  279.                                         case Keys.NumPad3:
  280.                                             player.MoveDirection(Direction.SouthEast);
  281.                                             currentMap.Tick();
  282.                                             break;
  283.                                         case Keys.NumPad1:
  284.                                             player.MoveDirection(Direction.SouthWest);
  285.                                             currentMap.Tick();
  286.                                             break;
  287.                                         case Keys.NumPad7:
  288.                                             player.MoveDirection(Direction.NorthWest);
  289.                                             currentMap.Tick();
  290.                                             break;
  291.                                         case Keys.NumPad5:
  292.                                             currentMap.Tick();
  293.                                             break;
  294.  
  295. #if DEBUG
  296.                                         case Keys.F1:
  297.                                             showDebug = !showDebug;
  298.                                             if (showDebug)
  299.                                             {
  300.                                                 textConsole.Write("\\c[#FFFFFF]Debug ON");
  301.                                             }
  302.                                             else
  303.                                             {
  304.                                                 textConsole.Write("\\c[#FFFFFF]Debug OFF");
  305.                                             }
  306.                                             break;
  307.                                         case Keys.F2:
  308.                                             if (player.FOVRadius < 255)
  309.                                             {
  310.                                                 player.FOVRadius = 255;
  311.                                                 textConsole.Write("\\c[#FFFFFF]Farsight ON");
  312.                                             }
  313.                                             else
  314.                                             {
  315.                                                 player.FOVRadius = 8;
  316.                                                 textConsole.Write("\\c[#FFFFFF]Farsight OFF");
  317.                                             }
  318.                                             break;
  319.                                         case Keys.F3:
  320.                                             if (player.FOVRadius < 255)
  321.                                             {
  322.                                                 player.FOVRadius = 255;
  323.                                                 foreach(Cell cell in currentMap.CellArray)
  324.                                                 {
  325.                                                     cell.BlocksFOV = false;
  326.                                                 }
  327.                                                 textConsole.Write("\\c[#FFFFFF]Fullsight ON");
  328.                                             }
  329.                                             break;
  330.                                         case Keys.F4:
  331.                                             Blinky blinky = new Blinky(Content, currentMap.GetCell(12, 14), new List<Faction> { factionManager.EnemyFaction }, player);
  332.                                             //Pinky pinky = new Pinky(Content, currentMap.GetCell(13, 14), new List<Faction> { factionManager.EnemyFaction }, player);
  333.                                             //Inky inky = new Inky(Content, currentMap.GetCell(14, 14), new List<Faction> { factionManager.EnemyFaction });
  334.                                             //Clyde clyde = new Clyde(Content, currentMap.GetCell(15, 14), new List<Faction> { factionManager.EnemyFaction });
  335.                                             break;
  336.                                         case Keys.F11:
  337.                                             graphicsManager.ToggleFullScreen();
  338.                                             graphicsManager.PreferredBackBufferWidth = GraphicsDevice.Viewport.Width;
  339.                                             graphicsManager.PreferredBackBufferHeight = GraphicsDevice.Viewport.Height;
  340.                                             graphicsManager.ApplyChanges();
  341.                                             break;
  342.                                         default:
  343.                                             return;
  344. #endif
  345.                                     }
  346.                                 }
  347.                             }
  348.                             // Text box is focused
  349.                             else
  350.                             {
  351.                                 if (previousKeyboardState.IsKeyUp(key))
  352.                                 {
  353.                                     switch (key)
  354.                                     {
  355.                                         case Keys.Enter:
  356.                                             if (textConsole.MyraTextBox.IsKeyboardFocused)
  357.                                             {
  358.                                                 ParseConsoleCommand(textConsole.MyraTextBox.Text);
  359.                                                 textConsole.MyraTextBox.Text = "";
  360.                                             }
  361.                                             break;
  362.                                     }
  363.                                 }
  364.                             }                            
  365.                         }
  366.                         break;
  367.                 }
  368.                
  369.             }
  370.             void HandleMouseInput()
  371.             {
  372.                 // TODO
  373.                 switch (CurrentScene)
  374.                 {
  375.                     case Scene.Game:
  376.                         break;
  377.                 }
  378.             }
  379.             void ParseConsoleCommand(string command)
  380.             {
  381.                 if (Regex.IsMatch(command, "^loadmap [a-zA-Z0-9]+$", RegexOptions.IgnoreCase))
  382.                 {
  383.                     string mapName = command.Split(' ')[1];
  384.  
  385.                     if (System.IO.File.Exists($"Maps/{mapName}.txt"))
  386.                     {
  387.                         LoadMap(mapName);
  388.                     }
  389.                     else
  390.                     {
  391.                         textConsole.Write("\\c[#FFFFFF]Invalid map name");
  392.                     }
  393.                 }
  394.                 else if (Regex.IsMatch(command, "^clear$", RegexOptions.IgnoreCase) || Regex.IsMatch(command, "^cs$", RegexOptions.IgnoreCase))
  395.                 {
  396.                     textConsole.RecentLines.Clear();
  397.                     textConsole.UpdateText();
  398.                 }
  399.                 else if (Regex.IsMatch(command, "^Get ye flask$", RegexOptions.IgnoreCase))
  400.                 {
  401.                     textConsole.Write("\\c[#06e50f]You can't get ye flask!");
  402.                 }
  403.                 else
  404.                 {
  405.                     textConsole.Write("\\c[#FFFFFF]Syntax error");
  406.                 }
  407.             }
  408.         }
  409.  
  410.         /// <summary>
  411.         /// This is called when the game should draw itself.
  412.         /// </summary>
  413.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  414.         protected override void Draw(GameTime gameTime)
  415.         {
  416.             float fps = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
  417.  
  418.             switch(CurrentScene)
  419.             {
  420.                 default:
  421.                 case Scene.MainMenu:
  422.                     break;
  423.                 case Scene.Game:
  424.                     mapRenderTarget = new RenderTarget2D(GraphicsDevice, currentMap.Width * 16, currentMap.Height * 16, false, SurfaceFormat.Color, DepthFormat.None);
  425.                     RenderCurrentMap(mapRenderTarget);
  426.                     GraphicsDevice.Clear(Color.Black);
  427.  
  428.                     spriteBatch.Begin();
  429.                     DrawMap();
  430.                     DrawUI();
  431.                     DrawText();
  432.                     spriteBatch.End();
  433.                     spriteBatch.Begin();
  434.                     myraDesktop.Render(); // Myra requires a new spriteBatch to draw on top.
  435.                     spriteBatch.End();
  436.                     base.Draw(gameTime);
  437.  
  438.                     break;
  439.             }
  440.  
  441.             void DrawMap()
  442.             {
  443.                 // Draw map centered on cameraTarget (usually the player)
  444.                 spriteBatch.Draw(mapRenderTarget, new Rectangle(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2, currentMap.Width * 16, currentMap.Height * 16),
  445.                  null, Color.White, 0f, new Vector2(cameraTarget.X * 16, cameraTarget.Y * 16), SpriteEffects.None, 0f);
  446.             }
  447.             void DrawUI()
  448.             {
  449.                 // Cell mouseover highlight
  450.                 foreach (Cell c in player.GetVisibleCells())
  451.                 {
  452.                     if (RenderedCellRectangle(currentMap.CellArray[c.X, c.Y]).Contains(new Point(currentMouseState.X, currentMouseState.Y)))
  453.                     {
  454.                         spriteBatch.Draw(Content.Load<Texture2D>("Textures/highlight/00"), RenderedCellRectangle(currentMap.CellArray[c.X, c.Y]), Color.White);
  455.                     }
  456.                 }
  457.             }
  458.             void DrawText()
  459.             {
  460.                 // Entity mouseover text
  461.                 foreach (Entity e in player.GetVisibleEntities())
  462.                 {
  463.                     if (RenderedCellRectangle(currentMap.CellArray[e.X, e.Y]).Contains(new Point(currentMouseState.X, currentMouseState.Y)))
  464.                     {
  465.                         spriteBatch.DrawString(font_bigblue_12, e.Name, new Vector2(currentMouseState.X + 12, currentMouseState.Y), Color.White);
  466.                     }
  467.                 }
  468.  
  469.                 // Debug information
  470.                 if (showDebug == true)
  471.                 {
  472.                     spriteBatch.DrawString(font_bigblue_12, "FPS = " + (int)(fps + 0.5f), new Vector2(0, font_bigblue_12.LineSpacing * 0), Color.White);
  473.                     spriteBatch.DrawString(font_bigblue_12, "Mouse X, Y = " + currentMouseState.X + ", " + currentMouseState.Y, new Vector2(0, font_bigblue_12.LineSpacing * 1), Color.White);
  474.                     foreach (Cell c in currentMap.CellArray)
  475.                     {
  476.                         if (RenderedCellRectangle(currentMap.CellArray[c.X, c.Y]).Contains(new Point(currentMouseState.X, currentMouseState.Y)))
  477.                         {
  478.                             if (c.Entity != null)
  479.                             {
  480.                                 spriteBatch.DrawString(font_bigblue_12, c.X + ", " + c.Y, new Vector2(currentMouseState.X + 12, currentMouseState.Y + font_bigblue_12.LineSpacing), Color.White);
  481.                             }
  482.                             else
  483.                             {
  484.                                 spriteBatch.DrawString(font_bigblue_12, c.X + ", " + c.Y, new Vector2(currentMouseState.X + 12, currentMouseState.Y), Color.White);
  485.                             }
  486.                         }
  487.                     }
  488.                 }
  489.             }
  490.  
  491.             void RenderCurrentMap(RenderTarget2D mapRenderTarget)
  492.             {
  493.                 // Set the render target
  494.                 GraphicsDevice.SetRenderTarget(mapRenderTarget);
  495.  
  496.                 GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
  497.  
  498.                 // Draw the scene
  499.                 GraphicsDevice.Clear(Color.Black);
  500.  
  501.                 // Add your drawing code here
  502.                 spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp);
  503.  
  504.                 DrawCells();
  505.                 DrawItems();
  506.                 DrawEntities();
  507.                 AdvanceAnimations();
  508.  
  509.                 spriteBatch.End();
  510.  
  511.                 // Drop the render target
  512.                 GraphicsDevice.SetRenderTarget(null);
  513.  
  514.                 void DrawCells()
  515.                 {
  516.                     foreach (Cell cell in currentMap.CellArray)
  517.                     {
  518.                         float opacity = 1f;
  519.  
  520.                         if (cell.IsExplored)
  521.                         {
  522.                             opacity = 0.5f;
  523.                         }
  524.                         if (cell.IsInFOV)
  525.                         {
  526.                             opacity = 1f;
  527.                         }
  528.                         if (cell is Cells.Void)
  529.                         {
  530.                             opacity = 1f;
  531.                             spriteBatch.Draw(Content.Load<Texture2D>("Textures/void"), new Rectangle(cell.X * 16, cell.Y * 16, 16, 16), Color.White * opacity);
  532.                         }
  533.                         if (cell.IsExplored == false && !(cell is Cells.Void))
  534.                         {
  535.                             spriteBatch.Draw(NoiseTextures[rng.Next(NoiseTextures.Count - 1)], new Rectangle((cell.X * 16), (cell.Y * 16), 16, 16), Color.White * opacity);
  536.                             continue;
  537.                         }
  538.                         else if (cell.CurrentAnimation != null)
  539.                         {
  540.                             spriteBatch.Draw(cell.CurrentAnimation.CurrentFrame(), new Rectangle(cell.X * 16, cell.Y * 16, 16, 16), Color.White * opacity);
  541.                         }
  542.                         else if (cell.Texture != null)
  543.                         {
  544.                             spriteBatch.Draw(cell.Texture, new Rectangle(cell.X * 16, cell.Y * 16, 16, 16), Color.White * opacity);
  545.                         }
  546.                         else
  547.                         {
  548.                             spriteBatch.Draw(Content.Load<Texture2D>("Textures/placeholder"), new Rectangle(cell.X * 16, cell.Y * 16, 16, 16), Color.White * opacity);
  549.                         }
  550.                     }
  551.                 }
  552.                 void DrawItems()
  553.                 {
  554.                     foreach (Item item in currentMap.GetAllItems())
  555.                     {
  556.                         if (item.ParentCell.IsInFOV)
  557.                         {
  558.                             if (item.CurrentAnimation != null)
  559.                             {
  560.                                 spriteBatch.Draw(item.CurrentAnimation.CurrentFrame(), new Rectangle(item.X * 16, item.Y * 16, 16, 16), Color.White);
  561.                             }
  562.                             else if (item.Texture != null)
  563.                             {
  564.                                 spriteBatch.Draw(item.Texture, new Rectangle(item.X * 16, item.Y * 16, 16, 16), Color.White);
  565.                             }
  566.                             else
  567.                             {
  568.                                 spriteBatch.Draw(Content.Load<Texture2D>("Textures/placeholder"), new Rectangle(item.X * 16, item.Y * 16, 16, 16), Color.White);
  569.                             }
  570.                         }
  571.                     }
  572.                 }
  573.                 void DrawEntities()
  574.                 {
  575.                     foreach (Entity entity in currentMap.GetAllEntities())
  576.                     {
  577.                         if (entity.ParentCell.IsInFOV)
  578.                         {
  579.                             if (entity.CurrentAnimation != null)
  580.                             {
  581.                                 spriteBatch.Draw(entity.CurrentAnimation.CurrentFrame(), new Rectangle(entity.X * 16, entity.Y * 16, 16, 16), Color.White);
  582.                             }
  583.                                 else if (entity.Texture != null)
  584.                             {
  585.                                 spriteBatch.Draw(entity.Texture, new Rectangle(entity.X * 16, entity.Y * 16, 16, 16), Color.White);
  586.                             }
  587.                             else
  588.                             {
  589.                                 spriteBatch.Draw(Content.Load<Texture2D>("Textures/placeholder"), new Rectangle(entity.X * 16, entity.Y * 16, 16, 16), Color.White);
  590.                             }
  591.                         }
  592.                     }
  593.                 }
  594.                 void AdvanceAnimations()
  595.                 {
  596.                     foreach (Cell cell in currentMap.CellArray)
  597.                     {
  598.                         if (cell.CurrentAnimation != null && (int)gameTime.TotalGameTime.TotalMilliseconds % cell.CurrentAnimation.TimePerFrame == 0)
  599.                         {
  600.                             cell.CurrentAnimation.AdvanceFrame();
  601.                         }
  602.                     }
  603.                     foreach(Entity entity in currentMap.GetAllEntities())
  604.                     {
  605.                         if (entity.CurrentAnimation != null && (int)gameTime.TotalGameTime.TotalMilliseconds % entity.CurrentAnimation.TimePerFrame == 0)
  606.                         {
  607.                             entity.CurrentAnimation.AdvanceFrame();
  608.                         }
  609.                     }
  610.                 }
  611.  
  612.             }
  613.             /// <summary>
  614.             /// Calculates the final on-screen position of a cell's texture after RenderTarget transformations.
  615.             /// </summary>
  616.             Rectangle RenderedCellRectangle(Cell cell)
  617.             {
  618.                 Point center = new Point(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
  619.                 Point mapTopLeft = new Point(center.X - player.X * 16, center.Y - player.Y * 16);
  620.                 Point cellTopLeft = new Point(mapTopLeft.X + cell.X * 16, mapTopLeft.Y + cell.Y * 16);
  621.  
  622.                 return new Rectangle(cellTopLeft, new Point(16, 15));
  623.             }
  624.         }
  625.     }
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement