SpelunkyRemake / Level.h
Level.h
Raw
#pragma once
#include "Texture.h"
#include "Tile.h"
#include "Ladder.h"

class Level
{
public:
	struct Info
	{
		int world;
		int stage;
		float timer;
	};

	Level(int world, int stage);
	~Level();

	Level(const Level& other) = delete;
	Level(Level&& other) = delete;
	Level& operator=(const Level& other) = delete;
	Level& operator=(Level&& other) = delete;

	void DrawVertices() const;
	void DrawBackground() const;
	void DrawForeground() const;
	void HandleCollision(Rectf& hitbox, Vector2f& velocity) const;
	void BounceCollision(Rectf& hitbox, Vector2f& velocity) const;
	bool IsOnSingleTile(const Rectf& hitbox) const;
	bool IsOnGround(const Rectf& hitbox) const;
	bool IsNearlyFalling(const Rectf& hitbox, int playerDir) const;
	bool IsOverlappingLadder(const Rectf& hitbox, float& ladderX) const;
	bool IsOverlappingLadder(const Rectf& hitbox, float& maxY, bool& isTopPiece) const;
	Tile* IsGrabbingLedge(Rectf& hitbox, Vector2f& velocity, int playerDir) const;
	
	void LoadLevel(int world, int stage);
	void CreateTile(int x, int y, Tile::Type tileType, int itemType = -1);

	void InitTiles();
	void UpdateTilesBorders();

	void Update(float elapsedSec);

	Rectf GetBoundaries() const;
	Info GetInfo() const;
	Point2f GetStartPos(float playerWidth) const;

	unsigned int GetTileIdx(int x, int y) const;

	static const int m_NrTilesX{ 40 };
	static const int m_NrTilesY{ 32 };

	static const int m_BorderSize{ 3 };

	static const bool WITH_PLATFORM{ true };

	void CreateLadder(int x, int y, bool isPlatform = false);

private:
	std::vector<Point2f> m_LevelVertices;
	Texture m_BorderBgTexture;
	Texture m_BorderEdgesTexture;
	Texture m_BackgroundTexture;
	Rectf m_Boundaries;

	Texture m_DoorTextures;
	Point2f m_EntryDoorPos;
	Point2f m_ExitDoorPos;

	const Rectf m_EntryDoorSrc;
	const Rectf m_ExitDoorSrc;

	Tile* m_pTiles[m_NrTilesX * m_NrTilesY];
	std::vector<Tile*> m_pTilesList;

	std::vector<Ladder*> m_pLadders;

	int m_World;
	int m_Stage;

	float m_Timer;
};