Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Egyptian_Horror_Story/Resource/Textures/NAVIGATION_TEST.bmp
  • Loading branch information
LWestling committed May 30, 2017
2 parents e84650e + 7ab20a6 commit bdd37e8
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 36 deletions.
10 changes: 10 additions & 0 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/AICFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ int AICFunctions::setEntityRotation(lua_State *state) {
return 0;
}

int AICFunctions::getEntityRotation(lua_State *state) {
Entity *entity = static_cast<Entity*>
(lua_touserdata(state, lua_upvalueindex(1)));
Vector3 rotation = entity->getRotation();
lua_pushnumber(state, rotation.x);
lua_pushnumber(state, rotation.y);
lua_pushnumber(state, rotation.z);
return 3;
}

int AICFunctions::setEntityOffsetRotation(lua_State *state) {
Entity *entity = static_cast<Entity*>
(lua_touserdata(state, lua_upvalueindex(1)));
Expand Down
2 changes: 2 additions & 0 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/AICFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class AICFunctions {
static int setEntityPosition(lua_State *state);
static int getEntityPosition(lua_State *state);
static int setEntityRotation(lua_State *state);
static int getEntityRotation(lua_State *state);

static int setEntityOffsetRotation(lua_State *state);
static int slowEntity(lua_State *state);
static int stunEntity(lua_State *state);
Expand Down
1 change: 1 addition & 0 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/AIHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void AIHandler::addLuaFunctionsTrap(lua_State *state, Trap *trap) {
addLuaFunction(state, "GetPosition", AICFunctions::getEntityPosition, userData, ARRAYSIZE(userData));
addLuaFunction(state, "SetPosition", AICFunctions::setEntityPosition, userData, ARRAYSIZE(userData));
addLuaFunction(state, "RotateTrap", AICFunctions::setEntityRotation, userData, ARRAYSIZE(userData));
addLuaFunction(state, "GetRotation", AICFunctions::getEntityRotation, userData, ARRAYSIZE(userData));
addLuaFunction(state, "SetTrapRotOffset", AICFunctions::setEntityOffsetRotation, userData, ARRAYSIZE(userData));

// PLAYER FUNCTIONS
Expand Down
5 changes: 5 additions & 0 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ void Entity::setRotation(DirectX::SimpleMath::Vector3 rot) {
this->mRot = rot;
}

DirectX::SimpleMath::Vector3 Entity::getRotation() const
{
return this->mRot;
}

void Entity::setScale(DirectX::SimpleMath::Vector3 scale) {
this->mScale = scale;
}
Expand Down
1 change: 1 addition & 0 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Entity
virtual void setPosition(float x, float y, float z);
virtual void setScale(DirectX::SimpleMath::Vector3 scale);
virtual void setRotation(DirectX::SimpleMath::Vector3 rot);
DirectX::SimpleMath::Vector3 getRotation() const;
virtual void setOffsetRotation(DirectX::SimpleMath::Vector3 offRot); // Used to transform before rotation
DirectX::SimpleMath::Vector3 getPosition() const;

Expand Down
69 changes: 43 additions & 26 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/EntityHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "EntityHandler.h"
#define ENEMY_KEY 400
#define BASE_TRAP_KEY 1000
#define TREASURE_PICKUP_DIST 2.f
#define TREASURE_PICKUP_DIST 3.f
#define SCALE_X 1.f
#define SCALE_Z -1.f
#define OFFSET_X -9 * SCALE_X
Expand Down Expand Up @@ -1327,7 +1327,6 @@ void EntityHandler::loadEntityModel(std::string modelName, wchar_t* textureName,
textureName,
entity->getPosition()
);

}

void EntityHandler::updateAudio()
Expand Down Expand Up @@ -1444,40 +1443,52 @@ void EntityHandler::detectCloseTreasures()
}
}

void EntityHandler::createAhnk(ID3D11Device* device, DirectX::SimpleMath::Vector3 pos)
void EntityHandler::createAhnk(ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot)
{
Treasure* tres = new Treasure(500 + this->mTreasures.size(), 20.f);

tres->setPosition(pos.x, pos.y -0.3f, pos.z);
tres->setPosition(posRot.pos.x, posRot.pos.y -0.3f, posRot.pos.z);
tres->setRotation(DirectX::SimpleMath::Vector3(0, posRot.rot * M_PI, 0));

this->loadEntityModel("treasure1.fbx", L"ankhTexture.png", tres, device);
tres->updateTransformBuffer(context, this->mEntityRenderer->getGraphicsData());

this->mTreasures.push_back(tres);
}

void EntityHandler::createTreasureChest(ID3D11Device* device, DirectX::SimpleMath::Vector3 pos)
void EntityHandler::createTreasureChest(ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot)
{
Treasure* tres = new Treasure(500 + this->mTreasures.size(), 20.f);

tres->setPosition(pos.x, pos.y, pos.z);
tres->setPosition(posRot.pos.x, posRot.pos.y, posRot.pos.z);
tres->setRotation(DirectX::SimpleMath::Vector3(0, posRot.rot * M_PI, 0));

this->loadEntityModel("treasure2.fbx", L"chestTexture.png", tres, device);
tres->updateTransformBuffer(context, this->mEntityRenderer->getGraphicsData());

this->mTreasures.push_back(tres);
}

void EntityHandler::createBoulderTrap(AIHandler* ai, ID3D11Device* device, DirectX::SimpleMath::Vector3 pos, float yOffset)
void EntityHandler::createBoulderTrap(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot, float yOffset)
{
Trap* trap = new Trap(1000 + this->mTraps.size(), pos.x, pos.y + yOffset, pos.z);
Trap* trap = new Trap(1000 + this->mTraps.size(), posRot.pos.x, posRot.pos.y + yOffset, posRot.pos.z);
trap->setRotation(DirectX::SimpleMath::Vector3(0, posRot.rot * M_PI, 0));

this->loadEntityModel("rock.fbx", L"sandstone.jpg", trap, device);
trap->updateTransformBuffer(context, this->mEntityRenderer->getGraphicsData());

ai->addTrap("scripts/TrapStone.lua", trap);
this->mTraps.push_back(trap);
}

void EntityHandler::createGuillioutineTrap(AIHandler* ai, ID3D11Device* device, DirectX::SimpleMath::Vector3 pos)
void EntityHandler::createGuillioutineTrap(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot)
{
Trap* trap = new Trap(1000 + this->mTraps.size(), pos.x, pos.y + 5.f, pos.z);
Trap* trap = new Trap(1000 + this->mTraps.size(), posRot.pos.x, posRot.pos.y + 5.f, posRot.pos.z);
trap->setRotation(DirectX::SimpleMath::Vector3(0, posRot.rot * M_PI, 0));

this->loadEntityModel("Guilliotine.fbx", L"", trap, device);
trap->updateTransformBuffer(context, this->mEntityRenderer->getGraphicsData());

ai->addTrap("scripts/TrapHanger.lua", trap);
this->mTraps.push_back(trap);
}
Expand Down Expand Up @@ -1543,24 +1554,30 @@ void EntityHandler::setupTreasureAndTraps(AIHandler* ai, ID3D11Device* device)
{
for (int i = 0; i < width; i++)
{
//TREASURE
if (
colors[count] == 0 &&
colors[count + 1] == 255 &&
colors[count + 2] == 0)
{
Vector2 temp = toPixelCoord(i, height - j, width, height);
Vector2 pos = toPixelCoord(i, height - j, width, height);
PosRot temp;
temp.pos = Vector3(pos.x, -1.4f, pos.y);
temp.rot = colors[count] / 100.f;

this->mTreasurePositions.push_back(Vector3(temp.x, -1.4f, temp.y));
this->mTreasurePositions.push_back(temp);
}

//TRAPS
else if (
colors[count] == 0 &&
colors[count + 1] == 0 &&
colors[count + 2] == 255)
{
Vector2 temp = toPixelCoord(i, height - j, width, height);
Vector2 pos = toPixelCoord(i, height - j, width, height);
PosRot temp;
temp.pos = Vector3(pos.x, -1.6f, pos.y);
temp.rot = colors[count] / 100.f;

this->mTrapPositions.push_back(Vector3(temp.x, -1.6f, temp.y));
this->mTrapPositions.push_back(temp);
}

count += 3;
Expand Down Expand Up @@ -1639,7 +1656,7 @@ void EntityHandler::setupDifficulty(settings::DifficultySettings & diff)
this->mTreasurePercentage = diff.treasurePercentage;
}

void EntityHandler::initializeTreasureAndTraps(AIHandler* ai, ID3D11Device* device)
void EntityHandler::initializeTreasureAndTraps(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context)
{
using namespace DirectX::SimpleMath;

Expand All @@ -1660,41 +1677,41 @@ void EntityHandler::initializeTreasureAndTraps(AIHandler* ai, ID3D11Device* devi
this->mTraps.clear();
this->mTreasures.clear();

std::vector<Vector3> trapPosCopy = this->mTrapPositions;
std::vector<PosRot> trapPosCopy = this->mTrapPositions;

for (int i = 0; i < floor(this->mTrapPositions.size() * this->mTrapPercentage); i++)
{
int trapPos = rand() % trapPosCopy.size();

Vector3 temp = trapPosCopy[trapPos];
PosRot temp = trapPosCopy[trapPos];
trapPosCopy.erase(trapPosCopy.begin() + trapPos);



if (rand() % 1000 < 500)
this->createBoulderTrap(ai, device, temp, 12.f);
this->createBoulderTrap(ai, device, context, temp, 12.f);

else
this->createGuillioutineTrap(ai, device, temp);
this->createGuillioutineTrap(ai, device, context, temp);
}

//***************************TREASURE*******************************
std::vector<Vector3> treasurePosCopy = this->mTreasurePositions;
std::vector<PosRot> treasurePosCopy = this->mTreasurePositions;

for (int i = 0; i < floor(this->mTreasurePositions.size() * this->mTreasurePercentage); i++)
{
int treasurePos = rand() % treasurePosCopy.size();

Vector3 temp = treasurePosCopy[treasurePos];
PosRot temp = treasurePosCopy[treasurePos];
treasurePosCopy.erase(treasurePosCopy.begin() + treasurePos);



if (rand() % 1000 < 500)
this->createAhnk(device, temp);
this->createAhnk(device, context, temp);

else
this->createTreasureChest(device, temp);
this->createTreasureChest(device, context, temp);
}

}
Expand All @@ -1721,7 +1738,7 @@ void EntityHandler::update(ID3D11DeviceContext* context, float dt)

this->detectCloseTreasures();

//this->updateCollision();
this->updateCollision();

this->updateAudio();
}
Expand Down
20 changes: 13 additions & 7 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/EntityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ class EntityHandler
float mTrapPercentage;
float mTreasurePercentage;

std::vector<DirectX::SimpleMath::Vector3> mTrapPositions;
std::vector<DirectX::SimpleMath::Vector3> mTreasurePositions;
struct PosRot
{
DirectX::SimpleMath::Vector3 pos;
float rot;
};

std::vector<PosRot> mTrapPositions;
std::vector<PosRot> mTreasurePositions;

/* From image space to world space */
DirectX::SimpleMath::Vector2 toPixelCoord(int x, int z, int w, int h) const;
Expand All @@ -47,12 +53,12 @@ class EntityHandler
void updateAudio();
void updateCollision();
void detectCloseTreasures();
void createAhnk(ID3D11Device* device, DirectX::SimpleMath::Vector3 pos);
void createTreasureChest(ID3D11Device* device, DirectX::SimpleMath::Vector3 pos);
void createBoulderTrap(AIHandler* ai, ID3D11Device* device, DirectX::SimpleMath::Vector3 pos, float yOffset);
void createAhnk(ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot);
void createTreasureChest(ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot);
void createBoulderTrap(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot, float yOffset);

//At least I tried spelling it!
void createGuillioutineTrap(AIHandler* ai, ID3D11Device* device, DirectX::SimpleMath::Vector3 pos);
void createGuillioutineTrap(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context, PosRot posRot);

void setupTreasureAndTraps(AIHandler* ai, ID3D11Device* device);
public:
Expand All @@ -66,7 +72,7 @@ class EntityHandler
void setupAudioManager(AudioManager* manager);
void setupDifficulty(settings::DifficultySettings& diff);

void initializeTreasureAndTraps(AIHandler* ai, ID3D11Device* device);
void initializeTreasureAndTraps(AIHandler* ai, ID3D11Device* device, ID3D11DeviceContext* context);
void initialize();

void update(ID3D11DeviceContext* context, float dt);
Expand Down
4 changes: 2 additions & 2 deletions Egyptian_Horror_Story/Egyptian_Horror_Story/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void Game::initialize()
this->mEntityHandler->getEntityRenderer()->setFadeout(1, this->mGraphics->getDeviceContext());
this->mVictory = false;
this->mEntityHandler->initialize();
this->mEntityHandler->initializeTreasureAndTraps(this->mAIHandler, this->mGraphics->getDevice());
this->mEntityHandler->initializeTreasureAndTraps(this->mAIHandler, this->mGraphics->getDevice(), this->mGraphics->getDeviceContext());
this->mAIHandler->setupAI();
}

Expand Down Expand Up @@ -166,7 +166,7 @@ bool Game::handleKeyboardRelease(SDL_KeyboardEvent const& key)
this->mOptionHandler->handleButtonRelease(key, this->mGraphics->getDeviceContext());

if (key.keysym.scancode == SDL_SCANCODE_2)
this->mEntityHandler->initializeTreasureAndTraps(this->mAIHandler, this->mGraphics->getDevice());
this->mEntityHandler->initializeTreasureAndTraps(this->mAIHandler, this->mGraphics->getDevice(), this->mGraphics->getDeviceContext());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function update(deltaTime)
temp = temp + deltaTime

local rot = math.sin(temp) * 1.4
RotateTrap(0, 0, rot)
rotX, rotY, rotZ = GetRotation()
RotateTrap(rotX, rotY, rot)

collision = math.abs(rot) < 0.35
end
Expand Down
Binary file modified Egyptian_Horror_Story/Resource/Models/Guilliotine.fbx
Binary file not shown.
Binary file modified Egyptian_Horror_Story/Resource/Textures/TreasureMesh.bmp
Binary file not shown.
Binary file modified Egyptian_Horror_Story/Resource/Textures/navMesh.bmp
Binary file not shown.
Binary file modified Egyptian_Horror_Story/Resource/Textures/sand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bdd37e8

Please sign in to comment.