Skip to content

Commit

Permalink
fix arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
atar13 committed Jun 5, 2024
1 parent f0df856 commit 21ce1df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
8 changes: 7 additions & 1 deletion include/server/game/projectile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions include/server/game/servergamestate.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -388,6 +389,8 @@ class ServerGameState {
*/
Trap* spawnFireballTrap(GridCell *cell);

Trap* spawnArrowTrap(GridCell* cell);

std::unordered_map<EntityID, std::array<std::optional<EntityID>, MAX_POINT_LIGHTS>> lightSourcesPerPlayer;

/**
Expand Down
2 changes: 1 addition & 1 deletion include/shared/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/arrowtrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
87 changes: 40 additions & 47 deletions src/server/game/servergamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 21ce1df

Please sign in to comment.