SpelunkyRemake / Player.h
Player.h
Raw
#pragma once
#include "Level.h"
#include "Item.h"
#include "SoundEffect.h"
class Tile;

class Player
{
public:
	enum class Buttons { LEFT, RIGHT, UP, DOWN, A, B, X, Y, RIGHT_TRIGGER, LENGTH };
	enum class ActionState { IDLE, WALKING, JUMPING, FALLING, CROUCHING, STANDING_UP, STARING_UP, STARING_BACK_DOWN, CRAWLING, HURT, LEDGE_GRAB, LOST_BALANCE, LADDER_IDLE, LADDER_CLIMBING };
	enum class Direction { LEFT, RIGHT };

	struct Info
	{
		int lives;
		int bombs;
		int ropes;
	};

	Player(const Point2f startPos = Point2f{});
	Player(SDL_GameController* gameController, const Point2f startPos = Point2f{});
	~Player();

	Player(const Player& other) = delete;
	Player(Player&& other) = delete;

	void SetPosition(const Point2f& pos);

	void Draw() const;
	void Update(float elapsedSec, const Level& level, std::vector<Item*>& pItems, Point2f& cameraOffset, float& cameraSmoothing);
	void PowerUpHit();
	void Hit(int damage, int direction);
	Rectf& GetHitbox();
	Vector2f GetVelocity() const;

	bool DidJumpOnEnemy(const std::vector<Point2f>& topVertices);

	void SetAction(ActionState action);
	void SetController(SDL_GameController* controller);

	bool GetInput(Buttons button, bool pressedOnce = false);
	void UpdateHeldInputs();

	Info GetInfo() const;

	ActionState GetState() const;

	const bool PRESSED_ONCE{ true };

	static int m_Score;

	std::vector<Point2f> GetTopVertices() const;

private:
	Rectf m_SpriteRect;
	Rectf m_Hitbox;
	const float m_ClimbSpeed;
	const float m_CrawlSpeed;
	const float m_WalkSpeed;
	const float m_RunSpeed;
	const float m_BrakeSpeedHurt;
	float m_BrakeSpeed;
	float m_SpeedLimit;
	const float m_JumpSpeed;
	float m_JumpTimer;
	float m_MinJumpDuration;
	const float m_NormalJumpDuration;
	const float m_JumpOnEnemyDuration;
	float m_StandUpTimer;
	const float m_StandUpDelay;
	float m_LookTimer;
	const float m_LookDelay;
	Vector2f m_Velocity;
	const Vector2f m_GravityAcceleration;
	const float m_MoveAcceleration;
	ActionState m_ActionState;
	ActionState m_LastActionState;
	float m_HurtTimer;
	float m_HurtDuration;
	int m_Power;
	const float m_HitBoxHeight;

	Tile* m_GrabbedTile;
	Tile* m_LastGrabbedTile;

	Texture m_SpritesTexture;
	const float m_ClipHeight;
	const float m_ClipWidth;
	int m_AnimFirstFrameId;
	int m_AnimLength;
	bool m_AnimLoop;
	int m_NrFramesPerSec;
	float m_AnimTime;
	int m_AnimFrame;

	SDL_GameController* m_Controller;
	bool m_HeldInputs[int(Buttons::LENGTH)];

	Direction m_Direction;

	SoundEffect m_HitSFX;

	SoundEffect m_JumpSFX;
	SoundEffect m_LandSFX;
	SoundEffect m_GrabLedgeSFX;

	SoundEffect m_GoldSmallSFX;
	SoundEffect m_GoldBigSFX;

	SoundEffect m_GreenGem;
	SoundEffect m_BlueGem;
	SoundEffect m_RedGem;

	int m_Lives;
	int m_Bombs;
	int m_Ropes;

	bool HandlePickups(std::vector<Item*>& pItems);
};