diff --git a/client/Makefile b/client/Makefile index 0030b54..93e34d0 100644 --- a/client/Makefile +++ b/client/Makefile @@ -3,7 +3,7 @@ CXXFLAGS = -std=c++20 -Wall -Wextra -O2 -I. LDFLAGS = -lraylib -lboost_system -lpthread -lGL -lm -ldl -lrt -lX11 TARGET = game -SOURCES = main.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp +SOURCES = main.cpp entity/Entity.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp OBJECTS = $(SOURCES:.cpp=.o) all: $(TARGET) @@ -20,7 +20,4 @@ clean: run: $(TARGET) ./$(TARGET) -packets: - cd .. && lua generate_packets.lua - -.PHONY: all clean run packets +.PHONY: all clean run diff --git a/client/entity/Entity.cpp b/client/entity/Entity.cpp new file mode 100644 index 0000000..0abc011 --- /dev/null +++ b/client/entity/Entity.cpp @@ -0,0 +1,22 @@ +#include "Entity.hpp" + +Entity::Entity(const Vector3& pos, uint32_t entityId) + : position(pos), id(entityId) { +} + +void Entity::update(float deltaTime) { + if (!active) return; + + position = Vector3Add(position, Vector3Scale(velocity, deltaTime)); +} + +void Entity::render() { +} + +void Entity::move(const Vector3& delta) { + position = Vector3Add(position, delta); +} + +void Entity::rotate(const Vector3& delta) { + rotation = Vector3Add(rotation, delta); +} \ No newline at end of file diff --git a/client/entity/Entity.hpp b/client/entity/Entity.hpp new file mode 100644 index 0000000..33c3226 --- /dev/null +++ b/client/entity/Entity.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include + +class Entity { +protected: + Vector3 position{0, 0, 0}; + Vector3 rotation{0, 0, 0}; + Vector3 velocity{0, 0, 0}; + uint32_t id{0}; + bool active{true}; + +public: + Entity() = default; + Entity(const Vector3& pos, uint32_t entityId = 0); + virtual ~Entity() = default; + + virtual void update(float deltaTime); + virtual void render(); + + void setPosition(const Vector3& pos) { position = pos; } + void setRotation(const Vector3& rot) { rotation = rot; } + void setVelocity(const Vector3& vel) { velocity = vel; } + void setId(uint32_t entityId) { id = entityId; } + void setActive(bool isActive) { active = isActive; } + + Vector3 getPosition() const { return position; } + Vector3 getRotation() const { return rotation; } + Vector3 getVelocity() const { return velocity; } + uint32_t getId() const { return id; } + bool isActive() const { return active; } + + void move(const Vector3& delta); + void rotate(const Vector3& delta); +}; \ No newline at end of file diff --git a/client/entity/player/PlayerController.cpp b/client/entity/player/PlayerController.cpp index 5cf205d..54e13c9 100644 --- a/client/entity/player/PlayerController.cpp +++ b/client/entity/player/PlayerController.cpp @@ -14,13 +14,14 @@ PlayerController::PlayerController(float distance, float height, float speed) } void PlayerController::update(float deltaTime) { + Entity::update(deltaTime); handleCameraRotation(); handleCameraZoom(); updateCameraPosition(); } -void PlayerController::setPlayerPosition(const Vector3& position) { - playerPosition = position; +void PlayerController::setPlayerPosition(const Vector3& pos) { + position = pos; } Vector3 PlayerController::getMoveInput() const { @@ -68,7 +69,7 @@ Vector3 PlayerController::getMoveInput() const { void PlayerController::updateCameraPosition() { // Update camera target to player position - camera.target = playerPosition; + camera.target = position; // Calculate camera position based on spherical coordinates float cosYaw = cosf(cameraYaw); @@ -76,9 +77,9 @@ void PlayerController::updateCameraPosition() { float cosPitch = cosf(cameraPitch); float sinPitch = sinf(cameraPitch); - camera.position.x = playerPosition.x - sinYaw * cosPitch * cameraDistance; - camera.position.y = playerPosition.y + sinPitch * cameraDistance; - camera.position.z = playerPosition.z - cosYaw * cosPitch * cameraDistance; + camera.position.x = position.x - sinYaw * cosPitch * cameraDistance; + camera.position.y = position.y + sinPitch * cameraDistance; + camera.position.z = position.z - cosYaw * cosPitch * cameraDistance; } void PlayerController::handleCameraRotation() { diff --git a/client/entity/player/PlayerController.hpp b/client/entity/player/PlayerController.hpp index 86719df..02fdf84 100644 --- a/client/entity/player/PlayerController.hpp +++ b/client/entity/player/PlayerController.hpp @@ -2,11 +2,11 @@ #include #include +#include "../Entity.hpp" -class PlayerController { +class PlayerController : public Entity { private: Camera3D camera{}; - Vector3 playerPosition{0, 0, 0}; float cameraDistance; float cameraHeight; float moveSpeed; @@ -20,9 +20,9 @@ private: public: PlayerController(float distance = 10.0f, float height = 5.0f, float speed = 5.0f); - void update(float deltaTime); - void setPlayerPosition(const Vector3& position); - Vector3 getPlayerPosition() const { return playerPosition; } + void update(float deltaTime) override; + void setPlayerPosition(const Vector3& pos); + Vector3 getPlayerPosition() const { return position; } Vector3 getMoveInput() const; Camera3D& getCamera() { return camera; }