Skip to content

Commit

Permalink
initial spike and arrow traps
Browse files Browse the repository at this point in the history
  • Loading branch information
atar13 committed Jun 5, 2024
1 parent 894be87 commit 78d5253
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 72 deletions.
2 changes: 2 additions & 0 deletions include/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ class Client {
std::unique_ptr<Model> orb_model;
std::unique_ptr<Model> exit_model;
std::unique_ptr<Model> floor_model;
std::unique_ptr<Model> arrow_model;
std::unique_ptr<Model> arrow_trap_model;

GLFWwindow *window;

Expand Down
10 changes: 10 additions & 0 deletions include/client/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ class Model : public Renderable {
*/
void rotateAbsolute(const glm::vec3& dir, bool is_player = false, const glm::vec3& axis = glm::vec3(0.0f, 1.0f, 0.0f)) override;

/**
* @brief Rotates the item along the specified axis. If
* no axis is specified, then assumes a rotation on the
* y-axis. This will not stack upon previous rotations.
*
* @param angle The angle of rotation
* @param axis The axis of rotation
*/
void rotateAbsolute(const float& angle, const glm::vec3& axis = glm::vec3(0.0f, 1.0f, 0.0f)) override;

/**
* @brief Rotates the item along the specified axis. If
* no axis is specified, then assumes a rotation on the
Expand Down
13 changes: 12 additions & 1 deletion include/client/renderable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,22 @@ class Renderable {
* no axis is specified, then assumes a rotation on the
* y-axis. This will not stack upon previous rotations.
*
* @param angle The angle of rotation
* @param dir The direction the model is facing
* @param change behavior if rotating the player model
* @param axis The axis of rotation
*/
virtual void rotateAbsolute(const glm::vec3& dir, bool is_player = false, const glm::vec3& axis = glm::vec3(0.0f, 1.0f, 0.0f));

/**
* @brief Rotates the item along the specified axis. If
* no axis is specified, then assumes a rotation on the
* y-axis. This will not stack upon previous rotations.
*
* @param angle The angle of rotation
* @param axis The axis of rotation
*/
virtual void rotateAbsolute(const float& angle, const glm::vec3& axis = glm::vec3(0.0f, 1.0f, 0.0f));

/**
* @brief Rotates the item along the specified axis. If
* no axis is specified, then assumes a rotation on the
Expand Down
3 changes: 1 addition & 2 deletions include/server/game/arrowtrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class ArrowTrap: public Trap {
public:
/**
* @param corner Corner position of the spike trap
* @param dimensions TODO: remove once we use real model with size
* @param dir What direction it should shoot in
*/
ArrowTrap(glm::vec3 corner, glm::vec3 dimensions, Direction dir);
ArrowTrap(glm::vec3 corner, Direction dir);

/// how long from initial activation until it can activate again
const static inline std::chrono::seconds TIME_UNTIL_RESET = 4s;
Expand Down
4 changes: 0 additions & 4 deletions include/server/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
#define PLAYER_SPEED 1.65f
#define JUMP_SPEED 0.55f

/* Default model sizes */
#define BEAR_DIMENSIONS glm::vec3(14.163582, 17.914591, 10.655818)
#define FIRE_PLAYER_DIMENSIONS glm::vec3(8.008834, 10.069769, 2.198592)
#define SUNGOD_DIMENSIONS glm::vec3(3.281404, 9.543382, 7.974873)

/* DM Constants */
#define MAX_TRAPS 10
Expand Down
39 changes: 18 additions & 21 deletions include/server/game/projectile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "server/game/constants.hpp"
#include "server/game/arrowtrap.hpp"
#include "server/game/spell.hpp"
#include "shared/game/sharedmodel.hpp"

#include <optional>
#include <deque>
#include <iostream>
#include <variant>

/**
* Class for any possible Projectile.
Expand Down Expand Up @@ -103,37 +105,32 @@ class HomingFireball : public Projectile {
class Arrow : public Projectile {
public:
inline static const int DAMAGE = 10;
inline static const float H_MULT = 0.75f;
inline static const float H_MULT = 0.10f;
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::Cube, ServerSFX::ArrowImpact,
Options(false, DAMAGE, H_MULT, V_MULT, false, 0.0f, 0, {}))
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)
{
// temp hack to get the correct direction until we load in a model and can rotate it

const float ARROW_WIDTH = 0.2f;
const float ARROW_LENGTH = 1.0f;
const float ARROW_HEIGHT = 0.2f;

float arrow_x_dim;
float arrow_z_dim;

switch (dir) {
case Direction::UP:
case Direction::DOWN:
arrow_x_dim = ARROW_WIDTH;
arrow_z_dim = ARROW_LENGTH;
break;
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);
break;
case Direction::RIGHT:
arrow_x_dim = ARROW_LENGTH;
arrow_z_dim = ARROW_WIDTH;
std::swap(this->physics.shared.dimensions.x, this->physics.shared.dimensions.z);
this->physics.shared.facing = glm::vec3(0.0f, 0.0f, 1.0f);
break;
case Direction::UP:
this->physics.shared.facing = glm::vec3(1.0f, 0.0f, 0.0f);
break;
case Direction::DOWN:
this->physics.shared.facing = glm::vec3(-1.0f, 0.0f, 0.0f);
break;
}

this->physics.shared.dimensions = glm::vec3(arrow_x_dim, ARROW_HEIGHT, arrow_z_dim);
}

Direction dir;
};

class SpellOrb : public Projectile {
Expand Down
2 changes: 2 additions & 0 deletions include/server/game/servergamestate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,6 @@ class ServerGameState {
* @brief table of all currently playing sounds
*/
SoundTable sound_table;

GameConfig config;
};
7 changes: 7 additions & 0 deletions include/shared/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
/* Number of player deaths to update match state to MatchState::RelayRace */
#define PLAYER_DEATHS_TO_RELAY_RACE 5
//#define PLAYER_DEATHS_TO_RELAY_RACE 15

/* Default model sizes */
#define BEAR_DIMENSIONS glm::vec3(14.163582, 17.914591, 10.655818)
#define FIRE_PLAYER_DIMENSIONS glm::vec3(8.008834, 10.069769, 2.198592)
#define SUNGOD_DIMENSIONS glm::vec3(3.281404, 9.543382, 7.974873)
#define ARROW_DIMENSIONS glm::vec3(45.025101, 68.662003, 815.164001)
#define ARROW_TRAP_DIMENSIONS glm::vec3(2.815553, 3.673665, 1.588817)
4 changes: 3 additions & 1 deletion include/shared/game/sharedmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ enum class ModelType {
Dagger,
Sword,
Hammer,
Lightning
Lightning,
Arrow,
ArrowTrap
};
1 change: 1 addition & 0 deletions include/shared/utilities/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct GameConfig {
std::string maze_file;

} maze;
bool disable_enemies;
} game;
/// @brief Shared config settings for the network
struct {
Expand Down
62 changes: 44 additions & 18 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include "glm/fwd.hpp"
#include "server/game/object.hpp"
#include "server/game/solidsurface.hpp"
#include "shared/game/constants.hpp"
#include "shared/game/dir_light.hpp"
#include "shared/game/event.hpp"
#include "shared/game/sharedmodel.hpp"
#include "shared/game/sharedobject.hpp"
#include "shared/network/constants.hpp"
#include "shared/utilities/rng.hpp"
Expand Down Expand Up @@ -229,8 +231,14 @@ bool Client::init() {
auto item_model_path = item_models_dir / "item.obj";
this->item_model = std::make_unique<Model>(item_model_path.string(), true);

auto spike_trap_model_path = env_models_dir / "spike_trap.obj";
this->spike_trap_model = std::make_unique<Model>(spike_trap_model_path.string(), true);
auto spike_trap_model_path = env_models_dir / "Spike_trap" / "Trap.obj";
this->spike_trap_model = std::make_unique<Model>(spike_trap_model_path.string(), false);

auto arrow_model_path = entity_models_dir / "Arrow_red" / "Arrow.obj";
this->arrow_model = std::make_unique<Model>(arrow_model_path.string(), false);

auto arrow_trap_model_path = env_models_dir / "Arrow trap" / "levelout_21.obj";
this->arrow_trap_model = std::make_unique<Model>(arrow_trap_model_path.string(), false);

auto orb_model_path = item_models_dir / "orb.obj";
this->orb_model = std::make_unique<Model>(orb_model_path.string(), true);
Expand Down Expand Up @@ -784,6 +792,7 @@ void Client::geometryPass() {
break;
}

this->spike_trap_model->rotateAbsolute(M_PI, glm::vec3(0.0f, 0.0f, 1.0f));
this->spike_trap_model->setDimensions(sharedObject->physics.dimensions);
this->spike_trap_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->spike_trap_model->draw(this->deferred_geometry_shader.get(),
Expand All @@ -799,7 +808,6 @@ void Client::geometryPass() {

this->sungod_model->setDimensions(sharedObject->physics.dimensions);
this->sungod_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->sungod_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->sungod_model->rotateAbsolute(sharedObject->physics.facing);
this->sungod_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
Expand All @@ -812,19 +820,32 @@ void Client::geometryPass() {
break;
}

this->python_model->setDimensions(sharedObject->physics.dimensions);
this->python_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->python_model->draw(this->deferred_geometry_shader.get(),
this->arrow_trap_model->rotateAbsolute(sharedObject->physics.facing, true);
this->arrow_trap_model->setDimensions(sharedObject->physics.dimensions);
this->arrow_trap_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->arrow_trap_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
break;
}
case ObjectType::Projectile: {
this->spike_trap_model->setDimensions(sharedObject->physics.dimensions);
this->spike_trap_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->spike_trap_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
case ObjectType::Projectile: {
switch (sharedObject->modelType) {
case ModelType::Arrow: {
auto dim = ARROW_DIMENSIONS * 0.005f;
this->arrow_model->setDimensions(dim);
this->arrow_model->rotateAbsolute(sharedObject->physics.facing);
this->arrow_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->arrow_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(), true);
break;
}
default:
this->spike_trap_model->setDimensions(sharedObject->physics.dimensions);
this->spike_trap_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->spike_trap_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(), true);
break;
}
break;
}
case ObjectType::FloorSpike: {
Expand Down Expand Up @@ -895,12 +916,17 @@ void Client::geometryPass() {
if (!is_dm && sharedObject->trapInfo->dm_hover) {
break;
}

this->orb_model->setDimensions( sharedObject->physics.dimensions);
this->orb_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->orb_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
auto dim = glm::vec3(45.025101, 68.662003, 815.164001) * 0.005f;
this->arrow_model->setDimensions(dim);
this->arrow_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->arrow_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(), true);

// this->orb_model->setDimensions( sharedObject->physics.dimensions);
// this->orb_model->translateAbsolute(sharedObject->physics.getCenterPosition());
// this->orb_model->draw(this->deferred_geometry_shader.get(),
// this->cam->getPos(),
// true);
break;
}
case ObjectType::Exit: {
Expand Down
7 changes: 7 additions & 0 deletions src/client/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ void Model::rotateAbsolute(const glm::vec3& dir, bool is_player, const glm::vec3
}
}

void Model::rotateAbsolute(const float& angle, const glm::vec3& axis) {
Renderable::rotateAbsolute(angle, axis);
for(Mesh& mesh : this->meshes) {
mesh.rotateAbsolute(angle, axis);
}
}

void Model::rotateRelative(const glm::vec3& dir, const glm::vec3& axis) {
Renderable::rotateRelative(dir, axis);
for(Mesh& mesh : this->meshes) {
Expand Down
5 changes: 5 additions & 0 deletions src/client/renderable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "client/renderable.hpp"
#include "glm/fwd.hpp"

#include <cmath>
#include <glm/glm.hpp>

#define GLM_ENABLE_EXPERIMENTAL
Expand Down Expand Up @@ -44,6 +45,10 @@ void Renderable::rotateAbsolute(const glm::vec3& dir, bool is_player, const glm:
this->rotation = glm::angleAxis(r, axis);
}

void Renderable::rotateAbsolute(const float& angle, const glm::vec3& axis) {
this->rotation = glm::angleAxis(angle, axis);
}

void Renderable::rotateRelative(const glm::vec3& dir, const glm::vec3& axis) {
// float rot = glm::acos(glm::dot(dir, this->facing));
float r1 = glm::atan(dir.x, dir.z);
Expand Down
37 changes: 27 additions & 10 deletions src/server/game/arrowtrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@

using namespace std::chrono_literals;

ArrowTrap::ArrowTrap(glm::vec3 corner, glm::vec3 dimensions, Direction dir):
Trap(ObjectType::ArrowTrap, false, corner, Collider::Box, ModelType::Cube, dimensions)
ArrowTrap::ArrowTrap(glm::vec3 corner, Direction dir):
Trap(ObjectType::ArrowTrap, false, corner, Collider::None, ModelType::ArrowTrap)
{
this->dir = dir;
this->shoot_time = std::chrono::system_clock::now();
this->physics.shared.facing = directionToFacing(dir);
// switch (dir) {
// case Direction::LEFT:
// this->physics.shared.facing = glm::vec3(0.0f, 0.0f, 1.0f);
// break;
// case Direction::RIGHT:
// this->physics.shared.facing = glm::vec3(0.0f, 0.0f, -1.0f);
// break;
// case Direction::UP:
// this->physics.shared.facing = glm::vec3(1.0f, 0.0f, 0.0f);
// break;
// case Direction::DOWN:
// this->physics.shared.facing = glm::vec3(-1.0f, 0.0f, 0.0f);
// break;
// }
}

bool ArrowTrap::shouldTrigger(ServerGameState& state) {
Expand All @@ -33,6 +47,9 @@ bool ArrowTrap::shouldTrigger(ServerGameState& state) {
glm::ivec2 curr_grid_pos = state.getGrid().getGridCellFromPosition(this->physics.shared.getCenterPosition());
int dist = 0;
while (dist < ArrowTrap::SIGHTLINE_M) { // max sightline
if (!state.getGrid().getCell(curr_grid_pos.x, curr_grid_pos.y)) {
break;
}
if (state.getGrid().getCell(curr_grid_pos.x, curr_grid_pos.y)->type == CellType::Wall) {
return false; // didnt find a player before a wall
}
Expand All @@ -57,20 +74,20 @@ void ArrowTrap::trigger(ServerGameState& state) {

glm::vec3 arrow_origin(
this->physics.shared.getCenterPosition().x,
2.0f,
3.0f,
this->physics.shared.getCenterPosition().z
);

// TODO scale with grid size?
switch (this->dir) {
case Direction::UP:
arrow_origin.z -= 3.0f;
break;
case Direction::DOWN:
arrow_origin.z += 2.0f;
break;
// case Direction::UP:
// arrow_origin.z -= 3.0f;
// break;
// case Direction::DOWN:
// arrow_origin.z += 2.0f;
// break;
case Direction::LEFT:
arrow_origin.x -= 3.0f;
// arrow_origin.z -= Grid::grid_cell_width / 2.0f;
break;
case Direction::RIGHT:
arrow_origin.x += 2.0f;
Expand Down
Loading

0 comments on commit 78d5253

Please sign in to comment.