Skip to content

Commit

Permalink
Merge pull request #201 from ucsd-cse125-sp24/feat/light-cut
Browse files Browse the repository at this point in the history
DM Light Cut
  • Loading branch information
Tyler-Lentz authored Jun 5, 2024
2 parents 89bff59 + 9c62f78 commit 7049864
Show file tree
Hide file tree
Showing 23 changed files with 266 additions and 216 deletions.
Binary file added assets/imgs/lightcut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"game": {
"maze": {
"directory": "maps",
"procedural": false,
"procedural": true,
"maze_file": "test/itemRoom.maze"
}
},
Expand All @@ -15,7 +15,7 @@
"lobby_broadcast": true,
"max_players": 1,
"disable_dm": false,
"skip_intro": true
"skip_intro": false
},
"client": {
"default_name": "Conan O'Brien",
Expand Down
2 changes: 1 addition & 1 deletion include/client/animationmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class AnimationManager
{
public:
AnimationManager(Animation* animation);
explicit AnimationManager(Animation* animation);

void updateAnimation(float dt);

Expand Down
3 changes: 2 additions & 1 deletion include/client/gui/img/img.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum class ImgID {
Sungod,
Teleporter,
Lightning,
LightCut,
ArrowTrap,
SpikeTrap,
DMCD_10, DMCD_9, DMCD_8, DMCD_7, DMCD_6, DMCD_5, DMCD_4, DMCD_3, DMCD_2, DMCD_1,
Expand Down Expand Up @@ -88,7 +89,7 @@ enum class ImgID {
ImgID::Compass0, ImgID::Compass30, ImgID::Compass60, ImgID::Compass90, \
ImgID::Compass120, ImgID::Compass150, ImgID::Compass180, ImgID::Compass210, \
ImgID::Compass240, ImgID::Compass270, ImgID::Compass300, ImgID::Compass330, \
ImgID::FloorSpikeTrap, ImgID::Sungod, ImgID::Teleporter, ImgID::Lightning, \
ImgID::FloorSpikeTrap, ImgID::Sungod, ImgID::Teleporter, ImgID::Lightning, ImgID::LightCut, \
ImgID::ArrowTrap, ImgID::SpikeTrap, \
ImgID::DMTrapBG, ImgID::Needle, \
ImgID::EventBG, ImgID::DMEventBG, \
Expand Down
8 changes: 6 additions & 2 deletions include/server/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define DM_MANA_TOTAL 30
#define DM_MANA_REGEN 1
#define LIGHTNING_MANA 10
#define LIGHT_CUT_MANA 5

/* Mirror Item */
// Mirror use duration in seconds
Expand All @@ -91,8 +92,11 @@

/* DM Constants */
#define MAX_TRAPS 10
#define TRAP_INVENTORY_SIZE 6
#define TRAP_INVENTORY_SIZE 7
#define TRAP_TIME 10
#define TRAP_COOL_DOWN 5
#define ITEM_SPAWN_PROB 0.1
#define ITEM_SPAWN_BOUND 3
#define ITEM_SPAWN_BOUND 3
#define LIGHTNING_LIGHT_CUT_TICKS 100
#define LIGHT_CUT_TICKS 200
#define LIGHT_CUT_RANGE 25.0
30 changes: 26 additions & 4 deletions include/server/game/dungeonmaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ class DungeonMaster : public Creature {
public:
SharedTrapInventory sharedTrapInventory;
SharedDMInfo dmInfo;
Weapon* lightning;

DungeonMaster(glm::vec3 corner, glm::vec3 facing);
~DungeonMaster();

virtual SharedObject toShared() override;

/**
* @brief get the number of traps the DM currently has placed
*/
int getPlacedTraps();

/**
* @brief set the number of traps the DM currently has placed
* @param placedTraps the number of traps the DM has placed
*/
void setPlacedTraps(int placedTraps);

// For lightning usage
void useMana();
/**
* @brief For lightning and light-cut usage
* @param mana the amount of mana the specific DM action takes
*/
void useMana(int mana);

/**
* @brief mana regeneration function
*/
void manaRegen();

/**
Expand Down Expand Up @@ -59,7 +72,12 @@ class DungeonMaster : public Creature {
* the last time the DungeonMaster became paralyzed.
*/
std::chrono::time_point<std::chrono::system_clock> getParalysisStartTime() const;


/**
* @brief The DM's lightning weapon
*/
Weapon* lightning;

private:
/**
* @brief Duration, in seconds, of the Dungeon Master's current paralysis
Expand All @@ -73,6 +91,10 @@ class DungeonMaster : public Creature {
*/
std::chrono::time_point<std::chrono::system_clock> paralysis_start_time;

/**
* @brief the number of traps the DM has placed
*/
int placedTraps;

std::chrono::system_clock::time_point mana_used;
};
22 changes: 20 additions & 2 deletions include/server/game/servergamestate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ class ServerGameState {
*/
std::string to_string();

Trap* createTrap(CellType type, glm::vec3 corner);

private:
/**
* list of entities to delete at the end of the tick
Expand Down Expand Up @@ -357,6 +355,26 @@ class ServerGameState {
*/
Trap* currentGhostTrap;

/**
* @brief Field that stores the lightning pos for cutting lights
*/
std::optional<glm::vec3> dmLightningCutLights;

/**
* @brief Field that stores the light cut action for cutting lights
*/
std::optional<glm::vec3> dmActionCutLights;

/**
* @brief last light cut for light cut action
*/
unsigned int lastLightCut;

/**
* @brief last light cut for lightning action
*/
unsigned int lastLightningLightCut;

/**
/**
* @brief helper function to spawn a wall at a specified cell
Expand Down
6 changes: 5 additions & 1 deletion include/server/game/torchlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ class Torchlight : public Object {
* @brief runs on every server tick to update torchlight flickering
* animations
* @parm current ServerGameState
* @param the position the lightning hit (if exists)
* @param the position of the light cut action (if exists)
*/
void doTick(ServerGameState& state);
void doTick(ServerGameState& state, std::optional<glm::vec3> lightning_light_cut_pos, std::optional<glm::vec3> action_light_cut_pos);

/**
* @brief get current intensity of torch from 0-1
Expand All @@ -72,8 +74,10 @@ class Torchlight : public Object {

// curr_step from 0-1 in flickering animation
float curr_step;

// how much the intensity should change on every server tick
float flickering_speed;

// if the flickering animation is inceasing in
// intensity or decreasing
bool inc_intensity;
Expand Down
34 changes: 34 additions & 0 deletions include/server/game/trap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,51 @@ class Trap : public Object {

SharedObject toShared() override;

/**
* Set the is_dm_trap field
*
* @param boolean for if this trap is a DM trap or not
*/
void setIsDMTrap(bool is_dm_trap);

/**
* Set the SharedTrapInfo info dm_hover field
*
* @param boolean for if this trap is a a DM hover or not
*/
void setIsDMTrapHover(bool is_dm_trap_hover);

/**
* Set the expiration of this trap
*
* @param expiration time
*/
void setExpiration(std::chrono::time_point<std::chrono::system_clock> expiration);

/**
* Gets if this trap is a DM trap or not
*
* @returns True if the trap is a DM trap and false otherwise
*/
bool getIsDMTrap();

/**
* Gets the expiration time of this trap
*
* @returns the expiration time of this trap
*/
std::chrono::time_point<std::chrono::system_clock> getExpiration();

protected:
/**
* is this trap a DM trap?
*/
bool is_dm_trap;

/**
* the expiration time of this trap
*/
std::chrono::time_point<std::chrono::system_clock> expiration;

SharedTrapInfo info;
};
1 change: 1 addition & 0 deletions include/shared/game/celltype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ enum class CellType {
Exit,
Lightning,
Mirror,
LightCut,
Unknown
};
3 changes: 2 additions & 1 deletion include/shared/game/sharedmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ enum class ModelType {
FireballTrapDown,
SunGod,
ArrowTrap,
Mirror
Mirror,
LightCut
};
2 changes: 2 additions & 0 deletions src/client/animationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ AnimationManager::AnimationManager(Animation* animation) {
m_currentTime = 0.0;
m_currentAnimation = animation;

m_deltaTime = 0; // Tyler: is this still used? linter complaining about it not being initialized

m_finalBoneMatrices.reserve(100);

for (int i = 0; i < 100; i++)
Expand Down
69 changes: 27 additions & 42 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ void Client::sendTrapEvent(bool hover, bool place, ModelType trapType) {
case ModelType::Lightning:
this->session->sendEvent(Event(eid, EventType::TrapPlacement, TrapPlacementEvent(eid, this->world_pos, CellType::Lightning, hover, place)));
break;
case ModelType::LightCut:
this->session->sendEvent(Event(eid, EventType::TrapPlacement, TrapPlacementEvent(eid, this->world_pos, CellType::LightCut, hover, place)));
break;
}

}

// Handle any updates
Expand Down Expand Up @@ -1172,23 +1176,23 @@ void Client::lightingPass() {
lighting_shader->setVec3("viewPos", camPos);

if (is_dm) {
auto ambient = glm::vec3(0.1, 0.1, 0.1);
auto diffuse = glm::vec3(0.1, 0.1, 0.1);
auto specular = glm::vec3(0.1, 0.1, 0.1);
std::array<DirLight, 4> dirLights = {
DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular},
DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular},
DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular},
DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular},
};

for (int i = 0; i < dirLights.size(); i++) {
std::string i_s = std::to_string(i);
lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction);
lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient);
lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse);
lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular);
}
auto ambient = glm::vec3(0.1, 0.1, 0.1);
auto diffuse = glm::vec3(0.1, 0.1, 0.1);
auto specular = glm::vec3(0.1, 0.1, 0.1);
std::array<DirLight, 4> dirLights = {
DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular},
DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular},
DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular},
DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular},
};

for (int i = 0; i < dirLights.size(); i++) {
std::string i_s = std::to_string(i);
lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction);
lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient);
lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse);
lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular);
}
}

for (int i = 0; i < closest_lights->size(); i++) {
Expand All @@ -1201,6 +1205,7 @@ void Client::lightingPass() {
glm::vec3 pos = curr_source->physics.getCenterPosition();

lighting_shader->setFloat("pointLights[" + std::to_string(i) + "].intensity", properties.intensity);

lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].position", pos);

lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].ambient_color", properties.ambient_color);
Expand Down Expand Up @@ -1426,16 +1431,13 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action,
break;
/* Send an event to start 'shift' movement (i.e. sprint) */
case GLFW_KEY_LEFT_SHIFT:
if (eid.has_value() && !this->session->getInfo().is_dungeon_master.value()) {
if (eid.has_value()) {
this->session->sendEvent(Event(eid.value(), EventType::StartAction, StartActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint)));
}
is_held_i = true;

break;
case GLFW_KEY_LEFT_CONTROL:
if (this->session->getInfo().is_dungeon_master.has_value() && this->session->getInfo().is_dungeon_master.value()) {
this->session->sendEvent(Event(eid.value(), EventType::StartAction, StartActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint)));
}

is_held_i = true;
break;

default:
Expand Down Expand Up @@ -1479,10 +1481,9 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action,
break;

case GLFW_KEY_LEFT_SHIFT:
if (eid.has_value() && !this->session->getInfo().is_dungeon_master.value()) {
if (eid.has_value()) {
this->session->sendEvent(Event(eid.value(), EventType::StopAction, StopActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint)));
}
is_held_i = false;
break;

case GLFW_KEY_O: // zoom out
Expand All @@ -1492,16 +1493,10 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action,
}
break;
case GLFW_KEY_I: // zoom out
if (eid.has_value() && this->session->getInfo().is_dungeon_master.value()) {
//sendTrapEvent(true, false, (this->gameState.objects.at(eid.value()))->trapInventoryInfo->inventory[(this->gameState.objects.at(eid.value()))->trapInventoryInfo->selected-1]);
}
is_held_i = false;
break;
case GLFW_KEY_LEFT_CONTROL:
if (this->session->getInfo().is_dungeon_master.has_value() && this->session->getInfo().is_dungeon_master.value()) {
this->session->sendEvent(Event(eid.value(), EventType::StopAction, StopActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint)));
}

is_held_i = false;
break;
default:
break;
Expand Down Expand Up @@ -1577,16 +1572,6 @@ void Client::mouseCallback(GLFWwindow* window, double xposIn, double yposIn) { /

mouse_xpos = new_mouse_xpos;
mouse_ypos = new_mouse_ypos;

if (this->gameState.phase == GamePhase::GAME && this->gui_state == GUIState::GAME_HUD) {
if (this->session->getInfo().is_dungeon_master.has_value() &&
this->session->getInfo().is_dungeon_master.value()) {
auto eid = this->session->getInfo().client_eid;
auto obj = this->gameState.objects.at(eid.value());

//sendTrapEvent(true, false, obj->trapInventoryInfo->inventory[obj->trapInventoryInfo->selected - 1]);
}
}
}

void Client::setWorldPos() {
Expand Down
Loading

0 comments on commit 7049864

Please sign in to comment.