Changeset 1749 for 2011/23


Ignore:
Timestamp:
2011-06-08 12:44:21 (8 years ago)
Author:
tekrjant
Message:

Phew..
Changes:

  • We now have a minimap
  • Camera has been modified
  • Lot of minor stuff
Location:
2011/23/sijoseha
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.cs

    r1734 r1749  
    2828        static public SpriteFont basicFont; 
    2929        Texture2D tileImage; 
     30        Texture2D miniMapBorders; 
    3031        MouseState mouseState, previousMouseState; 
    3132        KeyboardState keyState, previousKeyState; 
     
    3536        HUD gameHUD; 
    3637 
    37         Viewport mapView, hudView; 
     38        Viewport mapView, hudView, miniMapView; 
    3839 
    3940        Button saveButton; 
     
    7273            selectionBox = Content.Load<Texture2D>("selectionbox"); 
    7374            tileImage = Content.Load<Texture2D>("tilet"); 
     75            miniMapBorders = Content.Load<Texture2D>("miniMapBorders"); 
     76 
     77            mapView = new Viewport(0, 0, 
     78                graphics.PreferredBackBufferWidth - 200, 
     79                graphics.PreferredBackBufferHeight); 
     80            hudView = new Viewport(graphics.PreferredBackBufferWidth - 200, 
     81                0, 200, graphics.PreferredBackBufferHeight); 
     82            miniMapView = new Viewport(graphics.PreferredBackBufferWidth - 200, 
     83                graphics.PreferredBackBufferHeight - 200, 200, 200); 
    7484 
    7585            gameHUD = new HUD(); 
    76             gameHUD.ViewPort = new Viewport(graphics.PreferredBackBufferWidth - 200, 0, 200, graphics.PreferredBackBufferHeight); 
     86            gameHUD.ViewPort = hudView; 
    7787            gameHUD.AddButton(new Button(new Rectangle(10, 10, 150, 40), "Save", Color.YellowGreen, Color.Red, GraphicsDevice)); 
     88             
    7889            gameHUD.Buttons[0].Clicked += new ButtonClickedHandler(SaveMap); 
    79             mapView = new Viewport(0, 0, graphics.PreferredBackBufferWidth - 200, graphics.PreferredBackBufferHeight); 
    80  
    81             gameMap = new Map(this, tileImage, TILE_SIZE, 50, 20); 
    82             gameCamera = new Camera(); 
     90 
     91            gameMap = new Map(this, tileImage, TILE_SIZE, 200, 200); 
     92            gameHUD.AddMiniMap(new MiniMap(gameMap, miniMapView, miniMapBorders)); 
     93            gameCamera = new Camera(mapView); 
    8394        } 
    8495 
     
    166177                BlendState.AlphaBlend, 
    167178                null,null,null,null,gameCamera.getTransformation(mapView)); 
    168             gameMap.Draw(spriteBatch); 
     179            gameMap.Draw(spriteBatch, gameCamera); 
    169180            spriteBatch.End(); 
    170181            GraphicsDevice.Viewport = gameHUD.ViewPort; 
     
    172183            gameHUD.Draw(spriteBatch); 
    173184            spriteBatch.End(); 
    174  
     185            GraphicsDevice.Viewport = miniMapView; 
     186            spriteBatch.Begin(SpriteSortMode.Deferred, 
     187                BlendState.AlphaBlend, 
     188                null, null, null, null, gameCamera.getTransformation(miniMapView, true, gameMap.Size)); 
     189            gameHUD.DrawMinimap(spriteBatch); 
     190            spriteBatch.End(); 
     191            spriteBatch.Begin(); 
     192            spriteBatch.Draw(gameHUD.MiniMap.Borders, new Rectangle(0,0,200,200), Color.White); 
     193            spriteBatch.End(); 
    175194            base.Draw(gameTime); 
    176195        } 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.csproj

    r1734 r1749  
    112112    <Compile Include="HUD.cs" /> 
    113113    <Compile Include="Map.cs" /> 
     114    <Compile Include="MiniMap.cs" /> 
    114115    <Compile Include="Properties\AssemblyInfo.cs" /> 
    115116    <Compile Include="Program.cs" /> 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/Camera.cs

    r1733 r1749  
    1313        public Matrix Transform { get; set; } 
    1414        public Vector2 Position { get; set; } 
     15        public Viewport View { get; set; } 
     16        public Rectangle Bounds 
     17        { 
     18            get { return new Rectangle((int)Position.X, (int)Position.Y, View.Width, View.Height); } 
     19            set { } 
     20        } 
    1521 
    16         public Camera() 
     22        public Camera(Viewport view) 
    1723        { 
     24            this.View = view; 
    1825            this.Zoom = 1.0f; 
    1926            this.Position = Vector2.Zero; 
     
    2734        public Matrix getTransformation(Viewport viewPort) 
    2835        { 
     36            Zoom = 1.0f; 
    2937            this.Transform = 
    3038                Matrix.CreateTranslation( 
     
    3543        } 
    3644 
     45        public Matrix getTransformation(Viewport viewPort, bool showAll, Vector2 mapSize) 
     46        { 
     47            Zoom = viewPort.Width / (Math.Max(mapSize.X, mapSize.Y) * 32); 
     48            this.Transform = 
     49                //Matrix.CreateTranslation( 
     50                //new Vector3(-this.Position.X, -this.Position.Y, 0)) * 
     51                Matrix.CreateScale(new Vector3(this.Zoom, this.Zoom, 0)) *  
     52            Matrix.CreateTranslation(new Vector3(1.0f, viewPort.Height* 0.5f - mapSize.Y*32*Zoom/2, 0)); 
     53            return this.Transform; 
     54        } 
     55 
    3756        public Vector2 getMouseWorldPos(Vector2 mousePos, Viewport viewPort) 
    3857        { 
     58            Zoom = 1.0f; 
    3959            float MouseWorldX = (mousePos.X - viewPort.Width * 0.5f + (viewPort.Width * 0.5f + this.Position.X) * (float)Math.Pow(this.Zoom, 3)) / 
    4060                  (float)Math.Pow(this.Zoom, 3); 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/HUD.cs

    r1734 r1749  
    1212        public Viewport ViewPort { get; set; } 
    1313        public List<Button> Buttons { get; set; } 
     14        public MiniMap MiniMap; 
    1415 
    1516        public HUD() 
    1617        { 
    1718            Buttons = new List<Button>(); 
     19        } 
     20 
     21        public void AddMiniMap(MiniMap minimap) 
     22        { 
     23            MiniMap = minimap; 
    1824        } 
    1925 
     
    3036            } 
    3137        } 
     38 
     39        public void DrawMinimap(SpriteBatch sb) 
     40        { 
     41            MiniMap.Draw(sb); 
     42        } 
    3243    } 
    3344} 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/Map.cs

    r1727 r1749  
    1313        private AdventureGame Game; 
    1414        private List<Texture2D> tileTextures; 
    15         private Dictionary<TileType, Texture2D> textureType; 
     15        public Dictionary<TileType, Texture2D> textureType; 
    1616        public List<Tile> Tiles; 
    1717        public Tile SelectedTile; 
    1818 
     19        public Rectangle Shownrectangle { get; set; } 
     20 
     21        public Vector2 Size { get; set; } 
     22 
    1923        public Map(AdventureGame game, Texture2D tileTextures, int tileSize, int mapWidth, int mapHeight) 
    2024        { 
    21              
     25            this.Size = new Vector2(mapWidth, mapHeight); 
    2226            this.Tiles = new List<Tile>(); 
    2327            this.Game = game; 
     
    5660        } 
    5761 
    58         public void Draw(SpriteBatch sb) 
     62        public void Draw(SpriteBatch sb, Camera gamecam) 
    5963        { 
    6064            foreach (Tile tile in Tiles) 
    6165            { 
    62                 sb.Draw(this.textureType[tile.TileType], tile.Boundaries, Color.White); 
    63                 if (tile.Selected) 
    64                     sb.Draw(AdventureGame.selectionBox, tile.Boundaries, Color.White); 
     66                if (tile.Boundaries.Intersects(gamecam.Bounds)) 
     67                { 
     68                    sb.Draw(this.textureType[tile.TileType], tile.Boundaries, Color.White); 
     69                    if (tile.Selected) 
     70                        sb.Draw(AdventureGame.selectionBox, tile.Boundaries, Color.White); 
     71                } 
    6572            } 
    6673        } 
  • 2011/23/sijoseha/AdventureGame/AdventureGameContent/AdventureGameContent.contentproj

    r1727 r1749  
    6363    </Compile> 
    6464  </ItemGroup> 
     65  <ItemGroup> 
     66    <Compile Include="miniMapBorders.png"> 
     67      <Name>miniMapBorders</Name> 
     68      <Importer>TextureImporter</Importer> 
     69      <Processor>TextureProcessor</Processor> 
     70    </Compile> 
     71  </ItemGroup> 
    6572  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    6673  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.