Changeset 1749 for 2011/23/sijoseha/AdventureGame/AdventureGame
- Timestamp:
- 2011-06-08 12:44:21 (10 years ago)
- Location:
- 2011/23/sijoseha/AdventureGame/AdventureGame
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.cs
r1734 r1749 28 28 static public SpriteFont basicFont; 29 29 Texture2D tileImage; 30 Texture2D miniMapBorders; 30 31 MouseState mouseState, previousMouseState; 31 32 KeyboardState keyState, previousKeyState; … … 35 36 HUD gameHUD; 36 37 37 Viewport mapView, hudView ;38 Viewport mapView, hudView, miniMapView; 38 39 39 40 Button saveButton; … … 72 73 selectionBox = Content.Load<Texture2D>("selectionbox"); 73 74 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); 74 84 75 85 gameHUD = new HUD(); 76 gameHUD.ViewPort = new Viewport(graphics.PreferredBackBufferWidth - 200, 0, 200, graphics.PreferredBackBufferHeight);86 gameHUD.ViewPort = hudView; 77 87 gameHUD.AddButton(new Button(new Rectangle(10, 10, 150, 40), "Save", Color.YellowGreen, Color.Red, GraphicsDevice)); 88 78 89 gameHUD.Buttons[0].Clicked += new ButtonClickedHandler(SaveMap); 79 mapView = new Viewport(0, 0, graphics.PreferredBackBufferWidth - 200, graphics.PreferredBackBufferHeight); 80 81 game Map = 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); 83 94 } 84 95 … … 166 177 BlendState.AlphaBlend, 167 178 null,null,null,null,gameCamera.getTransformation(mapView)); 168 gameMap.Draw(spriteBatch );179 gameMap.Draw(spriteBatch, gameCamera); 169 180 spriteBatch.End(); 170 181 GraphicsDevice.Viewport = gameHUD.ViewPort; … … 172 183 gameHUD.Draw(spriteBatch); 173 184 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(); 175 194 base.Draw(gameTime); 176 195 } -
2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.csproj
r1734 r1749 112 112 <Compile Include="HUD.cs" /> 113 113 <Compile Include="Map.cs" /> 114 <Compile Include="MiniMap.cs" /> 114 115 <Compile Include="Properties\AssemblyInfo.cs" /> 115 116 <Compile Include="Program.cs" /> -
2011/23/sijoseha/AdventureGame/AdventureGame/Camera.cs
r1733 r1749 13 13 public Matrix Transform { get; set; } 14 14 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 } 15 21 16 public Camera( )22 public Camera(Viewport view) 17 23 { 24 this.View = view; 18 25 this.Zoom = 1.0f; 19 26 this.Position = Vector2.Zero; … … 27 34 public Matrix getTransformation(Viewport viewPort) 28 35 { 36 Zoom = 1.0f; 29 37 this.Transform = 30 38 Matrix.CreateTranslation( … … 35 43 } 36 44 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 37 56 public Vector2 getMouseWorldPos(Vector2 mousePos, Viewport viewPort) 38 57 { 58 Zoom = 1.0f; 39 59 float MouseWorldX = (mousePos.X - viewPort.Width * 0.5f + (viewPort.Width * 0.5f + this.Position.X) * (float)Math.Pow(this.Zoom, 3)) / 40 60 (float)Math.Pow(this.Zoom, 3); -
2011/23/sijoseha/AdventureGame/AdventureGame/HUD.cs
r1734 r1749 12 12 public Viewport ViewPort { get; set; } 13 13 public List<Button> Buttons { get; set; } 14 public MiniMap MiniMap; 14 15 15 16 public HUD() 16 17 { 17 18 Buttons = new List<Button>(); 19 } 20 21 public void AddMiniMap(MiniMap minimap) 22 { 23 MiniMap = minimap; 18 24 } 19 25 … … 30 36 } 31 37 } 38 39 public void DrawMinimap(SpriteBatch sb) 40 { 41 MiniMap.Draw(sb); 42 } 32 43 } 33 44 } -
2011/23/sijoseha/AdventureGame/AdventureGame/Map.cs
r1727 r1749 13 13 private AdventureGame Game; 14 14 private List<Texture2D> tileTextures; 15 p rivateDictionary<TileType, Texture2D> textureType;15 public Dictionary<TileType, Texture2D> textureType; 16 16 public List<Tile> Tiles; 17 17 public Tile SelectedTile; 18 18 19 public Rectangle Shownrectangle { get; set; } 20 21 public Vector2 Size { get; set; } 22 19 23 public Map(AdventureGame game, Texture2D tileTextures, int tileSize, int mapWidth, int mapHeight) 20 24 { 21 25 this.Size = new Vector2(mapWidth, mapHeight); 22 26 this.Tiles = new List<Tile>(); 23 27 this.Game = game; … … 56 60 } 57 61 58 public void Draw(SpriteBatch sb )62 public void Draw(SpriteBatch sb, Camera gamecam) 59 63 { 60 64 foreach (Tile tile in Tiles) 61 65 { 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 } 65 72 } 66 73 }
Note: See TracChangeset
for help on using the changeset viewer.