Changeset 1822 for 2011/23/sijoseha/AdventureGame/AdventureGame
- Timestamp:
- 2011-06-09 15:14:45 (10 years ago)
- Location:
- 2011/23/sijoseha/AdventureGame/AdventureGame
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.cs
r1758 r1822 73 73 74 74 CreateViews(); 75 gameMap = new Map(this, tileImage, TILE_SIZE, 20, 20);75 gameMap = new Map(this, tileImage, TILE_SIZE, 5000, 5000); 76 76 CreateHUD(); 77 77 … … 137 137 else 138 138 button.Pressed(); 139 } 140 } 141 } 142 143 if (previousMouseState.RightButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed) 144 { 145 if (mouseState.X < gameHUD.ViewPort.X) 146 { 147 Vector2 mouseWorldPos = gameCamera.getMouseWorldPos(new Vector2(mouseState.X, mouseState.Y), mapView); 148 Rectangle mousePos = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); 149 foreach (Tile tile in gameMap.Tiles) 150 { 151 if (mousePos.Intersects(tile.Boundaries)) 152 { 153 gameMap.ChangeTileTo(tile, gameHUD.SelectedButton.RelatedTileType); 154 } 139 155 } 140 156 } … … 187 203 DrawMap(); 188 204 DrawHUD(); 189 DrawMiniMap();205 //DrawMiniMap(); 190 206 base.Draw(gameTime); 191 207 } … … 239 255 gameHUD = new HUD(); 240 256 gameHUD.ViewPort = hudView; 241 gameHUD.AddButton(new Button 257 Button LoadButton = new Button 258 (new Rectangle(10, 150, 150, 40), 259 "Load", Color.YellowGreen, Color.Red, GraphicsDevice); 260 LoadButton.Clicked += LoadMap; 261 gameHUD.AddButton(LoadButton); 262 263 Button SaveButton = new Button 242 264 (new Rectangle(10, 10, 150, 40), 243 "Save", Color.YellowGreen, Color.Red, GraphicsDevice, SaveMap)); 244 245 gameHUD.AddButton(new Button( 246 new Rectangle(10,60,32,32), gameMap.textureType[TileType.Grass], 247 Color.Red, true, GraphicsDevice)); 265 "Save", Color.YellowGreen, Color.Red, GraphicsDevice); 266 267 SaveButton.Clicked += SaveMap; 268 gameHUD.AddButton(SaveButton); 269 270 Button grassButton = new Button( 271 new Rectangle(10, 60, 32, 32), gameMap.textureType[TileType.Grass], 272 Color.Red, true, GraphicsDevice); 273 grassButton.RelatedTileType = TileType.Grass; 274 275 Button sandButton = new Button( 276 new Rectangle(10, 100, 32, 32), gameMap.textureType[TileType.Sand], 277 Color.Red, true, GraphicsDevice); 278 sandButton.RelatedTileType = TileType.Sand; 279 280 gameHUD.AddButton(grassButton); 281 gameHUD.AddButton(sandButton); 248 282 gameHUD.AddMiniMap(new MiniMap(gameMap, miniMapView, miniMapBorders)); 249 283 … … 253 287 { 254 288 return false; 289 } 290 291 private void LoadMap(object sender, EventArgs e) 292 { 293 using (FileStream mapLoad = new FileStream("savedMap", FileMode.Open, FileAccess.Read)) 294 { 295 using (BinaryReader r = new BinaryReader(mapLoad)) 296 { 297 int amount = r.ReadInt32(); 298 for (int i = 0; i < amount; i++) 299 { 300 int tile = r.ReadInt32(); 301 int x = r.ReadInt32(); 302 int y = r.ReadInt32(); 303 bool passable = r.ReadBoolean(); 304 Tile newTile = new Tile((TileType)tile, 305 new Rectangle(x,y,TILE_SIZE,TILE_SIZE)); 306 newTile.Passable = passable; 307 gameMap.Tiles.Add(newTile); 308 } 309 } 310 } 255 311 } 256 312 … … 268 324 w.Write((int)tile.Position.X); 269 325 w.Write((int)tile.Position.Y); 326 w.Write(tile.Passable); 270 327 } 271 328 } … … 284 341 int x = r.ReadInt32(); 285 342 int y = r.ReadInt32(); 286 random.WriteLine(tile.ToString() + ' ' + x.ToString() + ' ' + y.ToString()); 343 bool passable = r.ReadBoolean(); 344 random.WriteLine(tile.ToString() + ' ' + x.ToString() + ' ' + y.ToString() + ' ' + passable.ToString()); 287 345 } 288 346 } -
2011/23/sijoseha/AdventureGame/AdventureGame/Button.cs
r1758 r1822 26 26 public bool Selectable { get; set; } 27 27 public bool Selected { get; set; } 28 public TileType RelatedTileType { get; set; } 29 28 30 29 31 public Button(Rectangle boundaries, Texture2D texture, Color borderColor, bool selectable, GraphicsDevice device) … … 31 33 this.Boundaries = boundaries; 32 34 this.BorderColor = borderColor; 35 this.Selectable = selectable; 33 36 this.Image = CreateTexture(borderColor, texture, device); 34 37 this.SelectedImage = CreateTexture(Color.White, texture, device); 35 38 } 36 39 37 public Button(Rectangle boundaries, string text, Color bgColor, Color borderColor, GraphicsDevice device , ButtonClickedHandler clickAction)40 public Button(Rectangle boundaries, string text, Color bgColor, Color borderColor, GraphicsDevice device)//, ButtonClickedHandler clickAction) 38 41 { 39 42 this.Boundaries = boundaries; -
2011/23/sijoseha/AdventureGame/AdventureGame/HUD.cs
r1758 r1822 15 15 16 16 public Button SelectedButton; 17 public TileType SelectedTileButtonType; 17 18 18 19 public HUD() -
2011/23/sijoseha/AdventureGame/AdventureGame/Map.cs
r1749 r1822 31 31 for (int x = 0; x < mapWidth; x++) 32 32 for (int y = 0; y < mapHeight; y++) 33 this.Tiles.Add(new Tile(TileType.Grass, new Rectangle(x * 32, y * 32, tileSize, tileSize))); 33 { 34 int tileT = r.Next(1, 5); 35 Tile newTile = new Tile( 36 (TileType)tileT, new Rectangle(x * 32, y * 32, tileSize, tileSize)); 37 if (tileT != 2) 38 newTile.Passable = true; 39 else 40 newTile.Passable = false; 41 this.Tiles.Add(newTile); 42 } 34 43 } 35 44 … … 53 62 tile.Selected = true; 54 63 SelectedTile = tile; 64 } 65 66 public void ChangeTileTo(Tile tile, TileType tileType) 67 { 68 tile.TileType = tileType; 55 69 } 56 70 -
2011/23/sijoseha/AdventureGame/AdventureGame/Tile.cs
r1758 r1822 19 19 public Vector2 Position { get { return new Vector2(Boundaries.X, Boundaries.Y); } set{} } 20 20 public Rectangle Boundaries { get; set; } 21 public int Width { get { return Boundaries.Width; } private set {} } 22 public int Height { get { return Boundaries.Height; } private set { } } 23 public Texture2D Image { get; set; } 21 //public int Width { get { return Boundaries.Width; } private set {} } 22 //public int Height { get { return Boundaries.Height; } private set { } } 24 23 public bool Selected { get; set; } 25 24 public TileType TileType { get; set; } 25 26 public bool Passable { get; set; } 26 27 27 28 public Tile(TileType tileType, Rectangle boundaries) … … 33 34 public Tile(Texture2D image, Vector2 position, int width, int height) 34 35 { 35 this.Image = image;36 36 this.Boundaries = new Rectangle((int)position.X, (int)position.Y, width, height); 37 37 }
Note: See TracChangeset
for help on using the changeset viewer.