Changeset 1734 for 2011/23/sijoseha


Ignore:
Timestamp:
2011-06-07 15:08:33 (8 years ago)
Author:
tekrjant
Message:
  • Map and HUD are no separeted
  • Button works with events
  • Lots of minor stuff
Location:
2011/23/sijoseha/AdventureGame/AdventureGame
Files:
1 added
3 edited

Legend:

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

    r1733 r1734  
    2222        GraphicsDeviceManager graphics; 
    2323         
    24          
    25  
    2624        SpriteBatch spriteBatch; 
    2725 
    28          
    2926        static public int TILE_SIZE = 32; 
    3027        static public Texture2D selectionBox; 
     
    3633        Map gameMap; 
    3734        Camera gameCamera; 
     35        HUD gameHUD; 
    3836 
    3937        Viewport mapView, hudView; 
     
    7573            tileImage = Content.Load<Texture2D>("tilet"); 
    7674 
     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); 
    7779            mapView = new Viewport(0, 0, graphics.PreferredBackBufferWidth - 200, graphics.PreferredBackBufferHeight); 
    78             hudView = new Viewport(graphics.PreferredBackBufferWidth - 200, 0, 200, graphics.PreferredBackBufferHeight); 
    7980 
    8081            gameMap = new Map(this, tileImage, TILE_SIZE, 50, 20); 
    8182            gameCamera = new Camera(); 
    82             saveButton = new Button(new Rectangle(10, 10, 150, 40), "Save", Color.YellowGreen, Color.Red, GraphicsDevice); 
    8383        } 
    8484 
     
    108108            if (previousMouseState.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed) 
    109109            { 
    110                 if (mouseState.X < graphics.PreferredBackBufferWidth - 200) 
     110                if (mouseState.X < gameHUD.ViewPort.X) 
    111111                { 
    112112                    Vector2 mouseWorldPos = gameCamera.getMouseWorldPos(new Vector2(mouseState.X, mouseState.Y), mapView); 
     
    123123                else 
    124124                { 
    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); 
    126126                    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                    } 
    129132                } 
    130133            } 
     
    165168            gameMap.Draw(spriteBatch); 
    166169            spriteBatch.End(); 
    167             GraphicsDevice.Viewport = hudView; 
     170            GraphicsDevice.Viewport = gameHUD.ViewPort; 
    168171            spriteBatch.Begin(); 
    169             saveButton.Draw(spriteBatch); 
     172            gameHUD.Draw(spriteBatch); 
    170173            spriteBatch.End(); 
    171174 
     
    173176        } 
    174177 
    175         private void SaveMap() 
     178        private void SaveMap(object sender, EventArgs e) 
    176179        { 
    177180            //FileStream mapFile = File.Create("savedMap,xml"); 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/AdventureGame.csproj

    r1733 r1734  
    110110    <Compile Include="Button.cs" /> 
    111111    <Compile Include="Camera.cs" /> 
     112    <Compile Include="HUD.cs" /> 
    112113    <Compile Include="Map.cs" /> 
    113114    <Compile Include="Properties\AssemblyInfo.cs" /> 
  • 2011/23/sijoseha/AdventureGame/AdventureGame/Button.cs

    r1727 r1734  
    99namespace AdventureGame 
    1010{ 
     11 
     12    public delegate void ButtonClickedHandler(object sender, EventArgs e); 
     13 
    1114    public class Button 
    1215    { 
     16        public event ButtonClickedHandler Clicked; 
     17 
    1318        public Vector2 Position { get { return new Vector2(Boundaries.X, Boundaries.Y); } set { } } 
    1419        public Rectangle Boundaries { get; set; } 
     
    4449        } 
    4550 
     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 
    4662        public void Draw(SpriteBatch sb) 
    4763        { 
Note: See TracChangeset for help on using the changeset viewer.