public void Update(Camera camera) { prevMouseState = currentMouseState; currentMouseState = Mouse.GetState(); if (currentMouseState.LeftButton == ButtonState.Pressed && prevMouseState.LeftButton == ButtonState.Released) { // Transfrom to World coords Vector2 worldPosition = Vector2.Transform(new Vector2(currentMouseState.X, currentMouseState.Y), Matrix.Invert(camera.Transform)); SpawnCrate(worldPosition.X); hud.DecreaseMana(20); } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { SpawnBrick(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { graphics.ApplyChanges(); this.IsMouseVisible = true; this.Window.Title = "Crate Game"; currentState = GameState.Playing; world = new World(new Vector2(0, 9.81f)); map = new Map(); camera = new Camera(GraphicsDevice.Viewport); hud = new HeadUpDisplay(); splashScreen = new SplashScreen(); menuManager = new MenuManager(graphics.GraphicsDevice); base.Initialize(); }