#ifndef PLATFORMSTARTERKIT_PLAYER_HPP #define PLATFORMSTARTERKIT_PLAYER_HPP #include "xna.hpp" #include "animation.hpp" namespace PlatformerStarterKit { class Level; class Enemy; // Our fearless adventurer! class Player { public: Player(xna::sptr const& level, xna::Vector2 const& position); public: xna::sptr Level() const; constexpr bool IsAlive() const { return isAlive; } constexpr bool IsOnGround() const { return isOnGround; } xna::Rectangle BoundingRectangle() const; void LoadContent(); void Reset(xna::Vector2 const& position); void ApplyPhysics(xna::GameTime const& gameTime); void Update(xna::GameTime const& gameTime); void GetInput(); void OnKilled(xna::sptr& killedBy); void Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch); void OnReachedExit(); public: xna::Vector2 Position{}; xna::Vector2 Velocity{}; private: xna::sptr idleAnimation = nullptr; xna::sptr runAnimation = nullptr; xna::sptr jumpAnimation = nullptr; xna::sptr celebrateAnimation = nullptr; xna::sptr dieAnimation = nullptr; xna::SpriteEffects flip = xna::SpriteEffects::None; AnimationPlayer sprite; xna::sptr killedSound = nullptr; xna::sptr jumpSound = nullptr; xna::sptr fallSound = nullptr; xna::sptr level = nullptr; bool isAlive = false; float previousBottom = 0.0F; bool isOnGround = false; float movement = 0.0f; bool isJumping = false; bool wasJumping = false; float jumpTime = false; xna::Rectangle localBounds{}; static constexpr float MoveAcceleration = 13000.0f; static constexpr float MaxMoveSpeed = 1750.0f; static constexpr float GroundDragFactor = 0.48; static constexpr float AirDragFactor = 0.58f; static constexpr float MaxJumpTime = 0.35f; static constexpr float JumpLaunchVelocity = -3500.0f; static constexpr float GravityAcceleration = 3400.0f; static constexpr float MaxFallSpeed = 550.0f; static constexpr float JumpControlPower = 0.14f; static constexpr float MoveStickScale = 1.0f; static constexpr xna::Buttons JumpButton = xna::Buttons::A; float DoJump(float velocityY, xna::GameTime const& gameTime); void HandleCollisions(); }; } #endif