/// <summary> /// draw players useful player data on screen over lighting /// </summary> public void DrawHUD() { Health.DrawOverLighting(); Health.DrawHealthBar(new Vector2(1100, 65), 1f); Canteen.DrawOverLighting(); DrawDevInfo(); }
/// <summary> /// load player content /// </summary> public void LoadContent() { Health = new Health(5, true); Canteen = new Canteen(this); playerStanding = ImageTools.LoadTexture2D("Characters/Player/standing"); playerForward = new Animation(ImageTools.LoadTexture2D("Characters/Player/character_walk_right"), 6, true); playerBackward = new Animation(ImageTools.LoadTexture2D("Characters/Player/character_walk_backward"), 4, true); playerJump = new Animation(ImageTools.LoadTexture2D("Characters/Player/jump"), 1, true); arm = ImageTools.LoadTexture2D("Characters/Player/arm"); armPosition = new Rectangle((int)position.X, (int)position.Y, arm.Width, arm.Height); lightPos = new Vector2(-300, -300); ScreenManager.LightingEngine.ClearLights(); //so light doesen't stay when new level is loaded flashLight = new SpotLight() { IsEnabled = true, Color = Color.White, Power = 1f, LightDecay = 200, Position = new Vector3(lightPos.X, lightPos.Y, 5), //position.z controls width of the focus SpotBeamWidthExponent = 36, DirectionZ = 0f //0f//-.1f }; flashLight.SpotRotation = 1f; ScreenManager.LightingEngine.AddLight(flashLight); boundingRectangle = new Rectangle(0, 0, 32, 64); setLineOfSight(); }
/// <summary> /// save player data /// </summary> public void Save() { Health.Save(); Canteen.Save(); }
/// <summary> /// update the game logic /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { Vector2 localPos = ScreenManager.GlobalToLocal(position.X, position.Y); //convert global pos to local pos LocalBounds = new Rectangle((int)localPos.X, (int)localPos.Y, 32, 64); //set the local bounds flashLight.Position = new Vector3(localPos.X + 16, localPos.Y + 32, 5); //set the postion of the flashlight using the local position calculateRotation(); //calculate the rotation of the arm getInput(); //check for keyboard input applyPhysics(gameTime); //apply all player physics setLineOfSight(); //set the raycast line of site Health.UpdateCooldownTimer(gameTime); //update the damage cooldown //adjust arm positions based on the flip of the character if (flip == SpriteEffects.None) { armPosition = new Rectangle((int)position.X + 12, (int)position.Y + 22, arm.Width, arm.Height); } else { armPosition = new Rectangle((int)position.X + 20, (int)position.Y + 22, arm.Width, arm.Height); } //healing if (ScreenManager.IsKeyPressed(Keybindings.Heal)) { Canteen.Heal(); } //developer info if (ScreenManager.IsKeyPressed(Keybindings.DevKey2)) { devMode = !devMode; Health.GodMode = !Health.GodMode; } //flashlight toggle - keep? if (ScreenManager.IsKeyPressed(Keybindings.FlashlightToggle)) { flashLight.IsEnabled = !flashLight.IsEnabled; } //set if the player is alive or not based on the health if (Health.IsDead) { IsDead = true; } else { IsDead = false; } //set the direction of the player based on the horizontal velocity if (velocity.X > 0) { Direction = -1; } else if (velocity.X < 0) { Direction = 1; } else { Direction = 0; } movement = 0.0f; //reset movment isJumping = false; //reset jump state }