Changeset 1734
- Timestamp:
- 2011-06-07 15:08:33 (12 years ago)
- Location:
- 2011/23/sijoseha/AdventureGame/AdventureGame
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.cs
r1733 r1734 22 22 GraphicsDeviceManager graphics; 23 23 24 25 26 24 SpriteBatch spriteBatch; 27 25 28 29 26 static public int TILE_SIZE = 32; 30 27 static public Texture2D selectionBox; … … 36 33 Map gameMap; 37 34 Camera gameCamera; 35 HUD gameHUD; 38 36 39 37 Viewport mapView, hudView; … … 75 73 tileImage = Content.Load<Texture2D>("tilet"); 76 74 75 gameHUD = new HUD(); 76 gameHUD.ViewPort = new Viewport(graphics.PreferredBackBufferWidth - 200, 0, 200, graphics.PreferredBackBufferHeight); 77 gameHUD.AddButton(new Button(new Rectangle(10, 10, 150, 40), "Save", Color.YellowGreen, Color.Red, GraphicsDevice)); 78 gameHUD.Buttons[0].Clicked += new ButtonClickedHandler(SaveMap); 77 79 mapView = new Viewport(0, 0, graphics.PreferredBackBufferWidth - 200, graphics.PreferredBackBufferHeight); 78 hudView = new Viewport(graphics.PreferredBackBufferWidth - 200, 0, 200, graphics.PreferredBackBufferHeight);79 80 80 81 gameMap = new Map(this, tileImage, TILE_SIZE, 50, 20); 81 82 gameCamera = new Camera(); 82 saveButton = new Button(new Rectangle(10, 10, 150, 40), "Save", Color.YellowGreen, Color.Red, GraphicsDevice);83 83 } 84 84 … … 108 108 if (previousMouseState.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed) 109 109 { 110 if (mouseState.X < g raphics.PreferredBackBufferWidth - 200)110 if (mouseState.X < gameHUD.ViewPort.X) 111 111 { 112 112 Vector2 mouseWorldPos = gameCamera.getMouseWorldPos(new Vector2(mouseState.X, mouseState.Y), mapView); … … 123 123 else 124 124 { 125 Vector2 mouseWorldPos = gameCamera.getMouseWorldPos(new Vector2(mouseState.X - hudView.X, mouseState.Y), hudView);125 Vector2 mouseWorldPos = gameCamera.getMouseWorldPos(new Vector2(mouseState.X - gameHUD.ViewPort.X, mouseState.Y), gameHUD.ViewPort); 126 126 Rectangle mousePos = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); 127 if (mousePos.Intersects(saveButton.Boundaries)) 128 SaveMap(); 127 foreach (Button button in gameHUD.Buttons) 128 { 129 if (mousePos.Intersects(button.Boundaries)) 130 button.Pressed(); 131 } 129 132 } 130 133 } … … 165 168 gameMap.Draw(spriteBatch); 166 169 spriteBatch.End(); 167 GraphicsDevice.Viewport = hudView;170 GraphicsDevice.Viewport = gameHUD.ViewPort; 168 171 spriteBatch.Begin(); 169 saveButton.Draw(spriteBatch);172 gameHUD.Draw(spriteBatch); 170 173 spriteBatch.End(); 171 174 … … 173 176 } 174 177 175 private void SaveMap( )178 private void SaveMap(object sender, EventArgs e) 176 179 { 177 180 //FileStream mapFile = File.Create("savedMap,xml"); -
2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.csproj
r1733 r1734 110 110 <Compile Include="Button.cs" /> 111 111 <Compile Include="Camera.cs" /> 112 <Compile Include="HUD.cs" /> 112 113 <Compile Include="Map.cs" /> 113 114 <Compile Include="Properties\AssemblyInfo.cs" /> -
2011/23/sijoseha/AdventureGame/AdventureGame/Button.cs
r1727 r1734 9 9 namespace AdventureGame 10 10 { 11 12 public delegate void ButtonClickedHandler(object sender, EventArgs e); 13 11 14 public class Button 12 15 { 16 public event ButtonClickedHandler Clicked; 17 13 18 public Vector2 Position { get { return new Vector2(Boundaries.X, Boundaries.Y); } set { } } 14 19 public Rectangle Boundaries { get; set; } … … 44 49 } 45 50 51 protected void OnClicked(EventArgs e) 52 { 53 if (Clicked != null) 54 Clicked(this, e); 55 } 56 57 public void Pressed() 58 { 59 OnClicked(EventArgs.Empty); 60 } 61 46 62 public void Draw(SpriteBatch sb) 47 63 {
Note: See TracChangeset
for help on using the changeset viewer.