public HUD(Level l) { level = l; selectionArrowPosition = new Vector2(40, 500); textColor = Color.Black; }
public Player(Game game, Level l) : base(game) { position = new Vector2(240, 700); level = l; speed = 5f; health = 3; stateTimer = 0; movementSpeed = 8; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); menuSelect = Content.Load<SoundEffect>("Audio/UI/menuSelect"); hud = new HUD(level); level = new Level(this, hud); hud.SetLevel(level); level.LoadContent(spriteBatch, Content); hud.LoadContent(spriteBatch, Content); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); GraphicsDevice.SamplerStates[0] = ClampSampleState; if (isMenuShown) { menu.Update(gameTime); int c = -1; if (keyboardTimer / 1000 >= DELAY) { if (ks.IsKeyDown(Keys.Space) && !oldstate.IsKeyDown(Keys.Space)) { sfx_press.Play(); keyboardTimer = 0; c = menu.currentItem; } } switch (c) { case 0: isMenuShown = false; isGameScreenShown = true; break; case 1: isMenuShown = false; isOptionsShown = true; break; case 2: Exit(); break; default: break; } } else if (isOptionsShown) { if (keyboardTimer/1000 >= DELAY) { if (ks.IsKeyDown(Keys.Space) && !oldstate.IsKeyDown(Keys.Down)) { sfx_press.Play(); keyboardTimer = 0; isMenuShown = true; isOptionsShown = false; } } } else if (GameLost) { if (keyboardTimer / 1000 >= DELAY) { if (ks.IsKeyDown(Keys.Space) && !oldstate.IsKeyDown(Keys.Down)) { sfx_press.Play(); keyboardTimer = 0; isMenuShown = true; GameLost = false; level = new Level(this); ResetTimer(); } } } else if (GameWon) { if (keyboardTimer / 1000 >= DELAY) { if (ks.IsKeyDown(Keys.Space) && !oldstate.IsKeyDown(Keys.Down)) { sfx_press.Play(); keyboardTimer = 0; isMenuShown = true; GameWon = false; level = new Level(this); ResetTimer(); } } } else if (isGameScreenShown) { timeMs += gameTime.ElapsedGameTime.Milliseconds; if (timeMs / 1000 >= 1) { timeSecs--; timeMs = 0; } if (timeSecs <= 0) { timeMinutes--; if (timeMinutes < 0) timeSecs = 0; else timeSecs = 60; } if (timeMinutes < 1) { timeCol = Color.Red; } if (timeMinutes <= 0 && timeSecs <= 0) { GameLost = true; isGameScreenShown = false; } else if (level.getSurvivorCount() <= 0) { GameWon = true; isGameScreenShown = false; } camera2D.camera2DPos = level.currentActor.getPos(); level.Update(gameTime, camera2D.transform_get(graphics)); } oldstate = ks; if (keyboardTimer/1000 < DELAY) { keyboardTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; } base.Update(gameTime); }
/// <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() { camera2D = new Camera(new Vector2(0,0)); normalrender = new RenderTarget2D(graphics.GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); level = new Level(this); menu = new Menu(this); this.isMenuShown = true; this.isOptionsShown = false; this.isGameScreenShown = false; base.Initialize(); }
//Because when I create level, I need to give it HUD and vice versa. Need to manually insert. public void SetLevel(Level l) { level = l; }