mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: add Spectator Mode
This commit is contained in:
@@ -17,6 +17,7 @@ public:
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
||||
static void window_focus_callback(GLFWwindow* window, int focused);
|
||||
static void window_reshape_callback(GLFWwindow* window, int new_width, int new_height);
|
||||
static void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
|
||||
static int start_cubed_application(int argc, char** argv);
|
||||
static unsigned int seed();
|
||||
|
||||
19
include/Cubed/gameplay/game_mode.hpp
Normal file
19
include/Cubed/gameplay/game_mode.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
enum class GameMode {
|
||||
CREATIVE,
|
||||
SPECTATOR
|
||||
};
|
||||
|
||||
inline std::string to_str(GameMode mode) {
|
||||
using enum GameMode;
|
||||
switch (mode) {
|
||||
case CREATIVE:
|
||||
return {"Creative"};
|
||||
case SPECTATOR:
|
||||
return {"Spective"};
|
||||
}
|
||||
throw std::invalid_argument{"GameMode is invaild"};
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
#include <Cubed/gameplay/chunk_pos.hpp>
|
||||
#include <Cubed/gameplay/game_mode.hpp>
|
||||
#include <Cubed/input.hpp>
|
||||
|
||||
#include <optional>
|
||||
@@ -19,6 +20,7 @@ class World;
|
||||
|
||||
class Player {
|
||||
private:
|
||||
using enum GameMode;
|
||||
constexpr static float WALK_SPEED = 4.5f;
|
||||
constexpr static float RUN_SPEED = 7.0f;
|
||||
constexpr static float ACCELERATION = 10.0f;
|
||||
@@ -54,7 +56,7 @@ private:
|
||||
|
||||
Gait m_gait = Gait::WALK;
|
||||
MoveState m_move_state {};
|
||||
|
||||
GameMode m_game_mode = CREATIVE;
|
||||
std::optional<LookBlock> m_look_block = std::nullopt;
|
||||
std::string m_name {};
|
||||
World& m_world;
|
||||
@@ -79,10 +81,11 @@ public:
|
||||
const glm::vec3& get_player_pos() const;
|
||||
const MoveState& get_move_state() const;
|
||||
|
||||
void change_mode(GameMode mode);
|
||||
void set_player_pos(const glm::vec3& pos);
|
||||
void update(float delta_time);
|
||||
void update_front_vec(float offset_x, float offset_y);
|
||||
void update_player_move_state(int key, int action);
|
||||
|
||||
void update_scroll(double yoffset);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user