mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add block placement and destruction
This commit is contained in:
@@ -20,4 +20,9 @@ struct BlockRenderData {
|
||||
glm::vec3 pos;
|
||||
std::vector<bool> draw_face;
|
||||
unsigned block_id;
|
||||
};
|
||||
|
||||
struct LookBlock {
|
||||
glm::ivec3 pos;
|
||||
glm::ivec3 normal;
|
||||
};
|
||||
@@ -14,7 +14,7 @@ private:
|
||||
World& m_world;
|
||||
// the index is a array of block id
|
||||
std::vector<uint8_t> m_blocks;
|
||||
GLuint m_vbo;
|
||||
GLuint m_vbo = 0;
|
||||
std::vector<Vertex> m_vertexs_data;
|
||||
|
||||
public:
|
||||
@@ -28,5 +28,7 @@ public:
|
||||
GLuint get_vbo() const;
|
||||
const std::vector<Vertex>& get_vertex_data() const;
|
||||
void init_chunk();
|
||||
|
||||
void set_chunk_block(int index, unsigned id);
|
||||
|
||||
};
|
||||
@@ -2,17 +2,11 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
#include <Cubed/input.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
struct MoveState {
|
||||
bool forward = false;
|
||||
bool back = false;
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool down = false;
|
||||
bool up = false;
|
||||
};
|
||||
|
||||
class World;
|
||||
|
||||
@@ -31,17 +25,17 @@ private:
|
||||
glm::vec3 m_right;
|
||||
MoveState m_move_state;
|
||||
|
||||
std::optional<glm::ivec3> m_look_block_pos = std::nullopt;
|
||||
std::optional<LookBlock> m_look_block = std::nullopt;
|
||||
std::string m_name;
|
||||
World& m_world;
|
||||
|
||||
bool ray_cast(const glm::vec3& start, const glm::vec3& dir, glm::ivec3& block_pos, float distance = 4.0f);
|
||||
bool ray_cast(const glm::vec3& start, const glm::vec3& dir, glm::ivec3& block_pos, glm::vec3& normal, float distance = 4.0f);
|
||||
|
||||
public:
|
||||
Player(World& world, const std::string& name);
|
||||
~Player();
|
||||
const glm::vec3& get_front() const;
|
||||
const std::optional<glm::ivec3>& get_look_block_pos() const;
|
||||
const std::optional<LookBlock>& get_look_block_pos() const;
|
||||
const glm::vec3& get_player_pos() const;
|
||||
const MoveState& get_move_state() const;
|
||||
|
||||
|
||||
@@ -17,11 +17,12 @@ public:
|
||||
~World();
|
||||
|
||||
const BlockRenderData& get_block_render_data(int x, int y ,int z);
|
||||
const std::optional<glm::ivec3>& get_look_block_pos(const std::string& name) const;
|
||||
const std::optional<LookBlock>& get_look_block_pos(const std::string& name) const;
|
||||
Player& get_player(const std::string& name);
|
||||
void init_world();
|
||||
bool is_block(const glm::ivec3& block_pos) const;
|
||||
void render();
|
||||
void set_block(const glm::ivec3& pos, unsigned id);
|
||||
void update(float delta_time);
|
||||
|
||||
|
||||
|
||||
24
include/Cubed/input.hpp
Normal file
24
include/Cubed/input.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
struct MoveState {
|
||||
bool forward = false;
|
||||
bool back = false;
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool down = false;
|
||||
bool up = false;
|
||||
};
|
||||
|
||||
struct MouseState {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
};
|
||||
|
||||
struct InputState {
|
||||
MoveState move_state;
|
||||
MouseState mouse_state;
|
||||
};
|
||||
|
||||
namespace Input {
|
||||
InputState& get_input_state();
|
||||
}
|
||||
Reference in New Issue
Block a user