From 21ce1dfd433bb0348fe3c4dc39d57ab36149fd3a Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Wed, 5 Jun 2024 01:28:20 -0700 Subject: [PATCH] fix arrows --- include/server/game/projectile.hpp | 8 ++- include/server/game/servergamestate.hpp | 3 + include/shared/game/constants.hpp | 2 +- src/server/game/arrowtrap.cpp | 2 +- src/server/game/servergamestate.cpp | 87 ++++++++++++------------- 5 files changed, 52 insertions(+), 50 deletions(-) diff --git a/include/server/game/projectile.hpp b/include/server/game/projectile.hpp index 99c6810b..9a8ad823 100644 --- a/include/server/game/projectile.hpp +++ b/include/server/game/projectile.hpp @@ -105,27 +105,33 @@ class HomingFireball : public Projectile { class Arrow : public Projectile { public: inline static const int DAMAGE = 10; - inline static const float H_MULT = 0.10f; + inline static const float H_MULT = 0.55f; inline static const float V_MULT = 0.0f; // not affected by gravity Arrow(glm::vec3 corner, glm::vec3 facing, Direction dir): Projectile(corner, facing, glm::vec3(0.0f, 0.0f, 0.0f), ModelType::Arrow, ServerSFX::ArrowImpact, Options(false, DAMAGE, H_MULT, V_MULT, false, 0.0f, 0, {})), dir(dir) { + const float clear_model_nudge = 1.5f; switch (dir) { case Direction::LEFT: std::swap(this->physics.shared.dimensions.x, this->physics.shared.dimensions.z); this->physics.shared.facing = glm::vec3(0.0f, 0.0f, -1.0f); + this->physics.shared.corner.x -= clear_model_nudge; break; case Direction::RIGHT: std::swap(this->physics.shared.dimensions.x, this->physics.shared.dimensions.z); this->physics.shared.facing = glm::vec3(0.0f, 0.0f, 1.0f); + // right doesn't need nudge for some reason + // this->physics.shared.corner.x += clear_model_nudge; break; case Direction::UP: this->physics.shared.facing = glm::vec3(1.0f, 0.0f, 0.0f); + this->physics.shared.corner.z -= (2.0f * clear_model_nudge); break; case Direction::DOWN: this->physics.shared.facing = glm::vec3(-1.0f, 0.0f, 0.0f); + this->physics.shared.corner.z += clear_model_nudge; break; } } diff --git a/include/server/game/servergamestate.hpp b/include/server/game/servergamestate.hpp index d665425f..7e2d6dbb 100644 --- a/include/server/game/servergamestate.hpp +++ b/include/server/game/servergamestate.hpp @@ -1,5 +1,6 @@ #pragma once +#include "server/game/gridcell.hpp" #include "shared/utilities/constants.hpp" #include "shared/utilities/typedefs.hpp" #include "shared/game/sharedgamestate.hpp" @@ -388,6 +389,8 @@ class ServerGameState { */ Trap* spawnFireballTrap(GridCell *cell); + Trap* spawnArrowTrap(GridCell* cell); + std::unordered_map, MAX_POINT_LIGHTS>> lightSourcesPerPlayer; /** diff --git a/include/shared/game/constants.hpp b/include/shared/game/constants.hpp index 0a24cfa8..44fc042d 100644 --- a/include/shared/game/constants.hpp +++ b/include/shared/game/constants.hpp @@ -15,7 +15,7 @@ #define LIGHTNING_PLAYER_DIMENSIONS glm::vec3(4.0f, 10.069769, 4.0f) #define WATER_PLAYER_DIMENSIONS glm::vec3(4.0f, 10.069769, 4.0f) #define SUNGOD_DIMENSIONS glm::vec3(3.281404, 9.543382, 7.974873) -#define ARROW_DIMENSIONS glm::vec3(45.025101, 68.662003, 815.164001) +#define ARROW_DIMENSIONS glm::vec3(25.025101, 68.662003, 333.333333) #define ARROW_TRAP_DIMENSIONS glm::vec3(2.815553, 3.673665, 1.588817) #define PLAYER_BBOX_SCALE 0.35f diff --git a/src/server/game/arrowtrap.cpp b/src/server/game/arrowtrap.cpp index 484f7325..c84406a2 100644 --- a/src/server/game/arrowtrap.cpp +++ b/src/server/game/arrowtrap.cpp @@ -11,7 +11,7 @@ using namespace std::chrono_literals; ArrowTrap::ArrowTrap(glm::vec3 corner, Direction dir): - Trap(ObjectType::ArrowTrap, false, corner, Collider::None, ModelType::ArrowTrap) + Trap(ObjectType::ArrowTrap, false, corner, Collider::Box, ModelType::ArrowTrap) { this->dir = dir; this->shoot_time = std::chrono::system_clock::now(); diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index 50a20c1e..807b4efd 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -1778,35 +1778,10 @@ Trap* ServerGameState::placeTrapInCell(GridCell* cell, CellType type) { case CellType::ArrowTrapLeft: case CellType::ArrowTrapRight: case CellType::ArrowTrapUp: { - if (cell->type != CellType::Empty) { - return nullptr; - } - - Direction dir; - if (cell->type == CellType::ArrowTrapDown) { - dir = Direction::DOWN; - } - else if (cell->type == CellType::ArrowTrapUp) { - dir = Direction::UP; - } - else if (cell->type == CellType::ArrowTrapLeft) { - dir = Direction::LEFT; - } - else { - dir = Direction::RIGHT; - } - - glm::vec3 corner( - (cell->x* Grid::grid_cell_width), - 0.0f, - (cell->y* Grid::grid_cell_width) - ); - - ArrowTrap* arrowTrap = new ArrowTrap(corner, dir); - - this->objects.createObject(arrowTrap); - - return arrowTrap; + if (cell->type != CellType::Empty) { + return nullptr; + } + return spawnArrowTrap(cell); } case CellType::TeleporterTrap: { if (cell->type != CellType::Empty) @@ -2146,24 +2121,7 @@ void ServerGameState::loadMaze(const Grid& grid) { case CellType::ArrowTrapLeft: case CellType::ArrowTrapRight: case CellType::ArrowTrapUp: { - Direction dir; - if (cell->type == CellType::ArrowTrapDown) { - dir = Direction::DOWN; - } else if (cell->type == CellType::ArrowTrapUp) { - dir = Direction::UP; - } else if (cell->type == CellType::ArrowTrapLeft) { - dir = Direction::LEFT; - } else { - dir = Direction::RIGHT; - } - - glm::vec3 corner( - cell->x * Grid::grid_cell_width, - -3.0f, - cell->y * Grid::grid_cell_width - ); - - this->objects.createObject(new ArrowTrap(corner, dir)); + spawnArrowTrap(cell); break; } @@ -2331,6 +2289,41 @@ Trap* ServerGameState::spawnFireballTrap(GridCell *cell) { return fireBallTrap; } +Trap* ServerGameState::spawnArrowTrap(GridCell* cell) { + glm::vec3 corner( + (cell->x* Grid::grid_cell_width), + -3.0f, + (cell->y* Grid::grid_cell_width) + ); + + const float z_nudge = 0.55f; + const float x_nudge = 0.15f; + Direction dir; + if (cell->type == CellType::ArrowTrapDown) { + dir = Direction::DOWN; + corner.x -= x_nudge; + } + else if (cell->type == CellType::ArrowTrapUp) { + dir = Direction::UP; + corner.x -= x_nudge; + } + else if (cell->type == CellType::ArrowTrapLeft) { + dir = Direction::LEFT; + corner.z += z_nudge; + } + else { + dir = Direction::RIGHT; + corner.z += z_nudge; + } + + + ArrowTrap* arrowTrap = new ArrowTrap(corner, dir); + + this->objects.createObject(arrowTrap); + + return arrowTrap; +} + Grid& ServerGameState::getGrid() { return this->grid; }