Skip to content

Inventory Setup + Initial Item Implementation #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
Expand All @@ -20,8 +9,7 @@
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}
Binary file added assets/imgs/frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/pot_health.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/pot_invisibility.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/pot_nausea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/selected_frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions include/client/gui/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ class GUI {
* TODO: this is not implemented yet
*/
void _layoutGameHUD();

/**
* @brief Displays the Game HUD for both gameHUD and EscMenu layout
*/
void _sharedGameHUD();

/**
* @brief Displays the menu which appears when the player presses Escape while playing
*
Expand Down
9 changes: 7 additions & 2 deletions include/client/gui/img/img.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ namespace gui::img {
*/
enum class ImgID {
Yoshi,
AwesomeSauce
AwesomeSauce,
ItemFrame,
SelectedFrame,
HealthPotion,
NauseaPotion,
InvisPotion
};
#define GET_ALL_IMG_IDS() \
{ImgID::Yoshi, ImgID::AwesomeSauce}
{ImgID::Yoshi, ImgID::AwesomeSauce, ImgID::ItemFrame, ImgID::SelectedFrame, ImgID::HealthPotion, ImgID::NauseaPotion, ImgID::InvisPotion}

/**
* Representation of a loaded image
Expand Down
14 changes: 13 additions & 1 deletion include/server/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define MAX_WALLS 1000
#define MAX_TRAPS 10
#define MAX_SPELLS 4
#define MAX_ITEMS 4

/* Constants */
#define FIRST_TIMESTEP 0
Expand All @@ -27,6 +26,19 @@
// Player Stat Constants
#define INITIAL_HEALTH 100

/* Inventory */
#define INVENTORY_SIZE 4

/* Potion Stats */
#define RESTORE_HEALTH 20
#define HEALTH_DURATION 0

#define NAUSEA_SCALAR -1.0f
#define NAUSEA_DURATION 10

#define INVIS_OPACITY 0.5
#define INVIS_DURATION 15

/* Game */
#define GRAVITY 0.03f
#define PLAYER_SPEED 1.5f
Expand Down
3 changes: 3 additions & 0 deletions include/server/game/gridcell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ enum class CellType {
Spawn,
Enemy,
SpikeTrap,
HealthPotion,
NauseaPotion,
InvisibilityPotion,
Unknown
};

Expand Down
22 changes: 16 additions & 6 deletions include/server/game/item.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#pragma once

#include "server/game/constants.hpp"
#include "server/game/object.hpp"
#include "shared/game/sharedobject.hpp"
#include "server/game/servergamestate.hpp"

class Item : public Object {
public:
SharedItemInfo iteminfo;

SharedItemInfo iteminfo{};
/**
* @param type Type of Object
* @param movable Movable factor for physics
* @param corner Corner position of the item
* @param model Model applied for the item
* @param dimensions Dimensions of the item
*/

Item();
~Item();
Item(ObjectType type, bool movable, glm::vec3 corner, ModelType model, glm::vec3 dimensions);

virtual void useItem(Object* other, ServerGameState& state);

void doCollision(Object* other, ServerGameState* state) override;

SharedObject toShared() override;

virtual SharedObject toShared() override;
private:

};
8 changes: 7 additions & 1 deletion include/server/game/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ struct Physics {
* set by the setModel function!
* NOTE: velocity defaults to 0
* NOTE: velocityMultitplier defaults to 1
* NOTE: Dizziness defaults to 1
*/
Physics(bool movable, Collider collider,
glm::vec3 corner, glm::vec3 facing,
glm::vec3 dimensions = glm::vec3(1.0f)):
shared{.corner=corner, .facing=facing, .dimensions=dimensions},
movable(movable), velocity(glm::vec3(0.0f)), velocityMultiplier(glm::vec3(1.0f)),
movable(movable), velocity(glm::vec3(0.0f)), velocityMultiplier(glm::vec3(1.0f)), nauseous(1.0f),
collider(collider)
{}

Expand All @@ -64,6 +65,11 @@ struct Physics {
*/
glm::vec3 velocityMultiplier;

/**
* @brief Factor for potion of nausea
*/
float nauseous;

/**
* @brief This object's collider type.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/server/game/objectmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include <memory>

#include "server/game/object.hpp"
#include "server/game/item.hpp"
#include "server/game/player.hpp"
#include "server/game/enemy.hpp"
#include "server/game/solidsurface.hpp"

class Trap; // forward declaration to use Trap*
class Item;

#include "shared/utilities/smartvector.hpp"

Expand Down
4 changes: 4 additions & 0 deletions include/server/game/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
#include "server/game/object.hpp"
#include "server/game/creature.hpp"
#include "shared/game/sharedobject.hpp"
#include <unordered_map>

class Player : public Creature {
public:
SharedPlayerInfo info;
SharedInventory sharedInventory;

std::unordered_map<int, SpecificID> inventory;

/**
* @param Corner corner position of the player
Expand Down
28 changes: 28 additions & 0 deletions include/server/game/potion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "server/game/item.hpp"
#include "server/game/object.hpp"
#include <chrono>

enum class PotionType {
Health,
Nausea,
Invisibility
};

class Potion : public Item {
public:
Potion(glm::vec3 corner, glm::vec3 dimensions, PotionType type);

int duration;
int effectScalar;
PotionType potType;

void useItem(Object* other, ServerGameState& state) override;
bool timeOut();
void revertEffect(ServerGameState& state);

private:
std::chrono::time_point<std::chrono::system_clock> used_time;
Player* usedPlayer;
};
6 changes: 2 additions & 4 deletions include/server/game/servergamestate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "shared/utilities/config.hpp"
#include "shared/utilities/smartvector.hpp"
#include "server/game/object.hpp"
#include "server/game/objectmanager.hpp"
#include "shared/game/event.hpp"
#include "server/game/grid.hpp"
#include "server/game/objectmanager.hpp"

#include <string>
#include <vector>
Expand Down Expand Up @@ -68,9 +68,7 @@ class ServerGameState {

void updateMovement();

// TODO: Add implementations of items

void useItem();
void updateItems();

void updateTraps();

Expand Down
20 changes: 20 additions & 0 deletions include/server/game/spell.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "server/game/servergamestate.hpp"
#include "server/game/object.hpp"

enum class SpellType {
Fireball,
};

class Spell : public Item {
public:
Spell(glm::vec3 corner, glm::vec3 dimensions);

SpellType spellType;

void setSpellType(SpellType type);

private:

};
52 changes: 51 additions & 1 deletion include/shared/game/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ enum class EventType {
MoveRelative,
MoveAbsolute,
SpawnEntity,
SelectItem,
UseItem,
DropItem,
};

enum class ActionType {
Expand Down Expand Up @@ -180,6 +183,50 @@ struct SpawnEntityEvent {
DEF_SERIALIZE(Archive& ar, const unsigned int version) {
// TODO:
}
};

/**
* Event for selecting which item to use
*/
struct SelectItemEvent {
SelectItemEvent() {}
explicit SelectItemEvent(EntityID playerEID, int itemNum) : playerEID(playerEID), itemNum(itemNum) {}

EntityID playerEID;
int itemNum;

DEF_SERIALIZE(Archive& ar, const unsigned int version) {
ar& playerEID& itemNum;
}

};

/**
* Event for entity to use item
*/
struct UseItemEvent {
UseItemEvent() {}
explicit UseItemEvent(EntityID playerEID) : playerEID(playerEID) {}

EntityID playerEID;

DEF_SERIALIZE(Archive& ar, const unsigned int version) {
ar& playerEID;
}
};

/**
* Event for dropping item in inventory
*/
struct DropItemEvent {
DropItemEvent() {}
explicit DropItemEvent(EntityID playerEID) : playerEID(playerEID){}

EntityID playerEID;

DEF_SERIALIZE(Archive& ar, const unsigned int version) {
ar& playerEID;
}

};

Expand All @@ -195,7 +242,10 @@ using EventData = boost::variant<
StopActionEvent,
MoveRelativeEvent,
MoveAbsoluteEvent,
SpawnEntityEvent
SpawnEntityEvent,
SelectItemEvent,
UseItemEvent,
DropItemEvent
>;

/**
Expand Down
6 changes: 5 additions & 1 deletion include/shared/game/sharedmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
enum class ModelType {
Cube,
Player,
WarrenBear
WarrenBear,
HealthPotion,
NauseaPotion,
InvisibilityPotion,
Frame
};
Loading