Inventory (WIP part I)

This commit is contained in:
MihailRis
2024-01-21 15:23:46 +03:00
parent fe5cab0db0
commit 5142f3b4e7
13 changed files with 864 additions and 175 deletions
+15 -6
View File
@@ -5,6 +5,7 @@
#include "../world/Level.h"
#include "../window/Events.h"
#include "../window/Camera.h"
#include "../items/Inventory.h"
#include <glm/glm.hpp>
@@ -18,12 +19,16 @@ const float JUMP_FORCE = 8.0f;
Player::Player(glm::vec3 position, float speed) :
speed(speed),
chosenItem(0),
chosenSlot(0),
camera(new Camera(position, glm::radians(90.0f))),
spCamera(new Camera(position, glm::radians(90.0f))),
tpCamera(new Camera(position, glm::radians(90.0f))),
currentCamera(camera),
hitbox(new Hitbox(position, glm::vec3(0.3f,0.9f,0.3f))) {
hitbox(new Hitbox(position, glm::vec3(0.3f,0.9f,0.3f))),
inventory(new Inventory(40)) {
}
Player::~Player() {
}
void Player::update(
@@ -118,14 +123,18 @@ void Player::teleport(glm::vec3 position) {
hitbox->position = position;
}
void Player::setChosenItem(itemid_t id) {
chosenItem = id;
void Player::setChosenSlot(int index) {
chosenSlot = index;
}
itemid_t Player::getChosenItem() const {
return chosenItem;
int Player::getChosenSlot() const {
return chosenSlot;
}
float Player::getSpeed() const {
return speed;
}
std::shared_ptr<Inventory> Player::getInventory() const {
return inventory;
}
+8 -4
View File
@@ -9,6 +9,7 @@
class Camera;
class Hitbox;
class Inventory;
class PhysicsSolver;
class Chunks;
class Level;
@@ -30,11 +31,12 @@ struct PlayerInput {
class Player {
float speed;
itemid_t chosenItem;
int chosenSlot;
public:
std::shared_ptr<Camera> camera, spCamera, tpCamera;
std::shared_ptr<Camera> currentCamera;
std::unique_ptr<Hitbox> hitbox;
std::shared_ptr<Inventory> inventory;
bool flight = false;
bool noclip = false;
bool debug = false;
@@ -43,15 +45,17 @@ public:
glm::vec2 cam = {};
Player(glm::vec3 position, float speed);
~Player() = default;
~Player();
void teleport(glm::vec3 position);
void update(Level* level, PlayerInput& input, float delta);
void setChosenItem(itemid_t id);
void setChosenSlot(int index);
itemid_t getChosenItem() const;
int getChosenSlot() const;
float getSpeed() const;
std::shared_ptr<Inventory> getInventory() const;
};
#endif /* SRC_OBJECTS_PLAYER_H_ */