diff --git a/content/sounds/bass.wav b/content/sounds/bass.wav new file mode 100644 index 0000000..5f4b791 Binary files /dev/null and b/content/sounds/bass.wav differ diff --git a/content/sounds/victory.wav b/content/sounds/victory.wav new file mode 100644 index 0000000..0c021f3 Binary files /dev/null and b/content/sounds/victory.wav differ diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 93b0548..ffdf211 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -30,18 +30,13 @@ public: //OnTocuh Enum::ActionType::Value OnTouchAction; - Enum::Sound::Value OnTouchSound; + Enum::Sound::Value OnTouchSound; //Variables Color3 color; bool canCollide; dBodyID physBody; dGeomID physGeom[3]; - bool singleShot; - int touchesToTrigger; - int uniqueObjectsToTrigger; - int changeScore; - int changeTimer; //Getters Vector3 getPosition(); @@ -53,6 +48,13 @@ public: Box getScaledBox(); CoordinateFrame getCFrame(); + //OnTouch Getters + bool isSingleShot(); + int getTouchesToTrigger(); + int getUniqueObjectsToTrigger(); + int getChangeScore(); + float getChangeTimer(); + //Setters void setParent(Instance* parent); void setPosition(Vector3); @@ -74,6 +76,9 @@ public: bool collides(PartInstance * part); bool collides(Box); + // onTouch + void onTouch(); + //Properties virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); @@ -87,4 +92,12 @@ private: bool dragging; Box itemBox; GLuint glList; + + // OnTouch + bool singleShot; + int touchesToTrigger; + int uniqueObjectsToTrigger; + int changeScore; + float changeTimer; + bool _touchedOnce; }; \ No newline at end of file diff --git a/src/source/DataModelV2/LevelInstance.cpp b/src/source/DataModelV2/LevelInstance.cpp index cd51b6d..9aea060 100644 --- a/src/source/DataModelV2/LevelInstance.cpp +++ b/src/source/DataModelV2/LevelInstance.cpp @@ -123,7 +123,7 @@ std::vector LevelInstance::getProperties() (LPARAM)scoreTxt, PIT_EDIT)); - properties.push_back(createPGI("Gameplay", + properties.push_back(createPGI("Gameplay", "TimerUpAction", "Some temporary string here", (LPARAM)strActionType(TimerUpAction), @@ -131,7 +131,7 @@ std::vector LevelInstance::getProperties() TEXT("Nothing\0Pause\0Lose\0Draw\0Win\0") )); - properties.push_back(createPGI("Gameplay", + properties.push_back(createPGI("Gameplay", "TimerAffectsScore", "Some temporary string here", (LPARAM)strAffectType(TimerAffectsScore), diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 290fa0c..defcd56 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -4,6 +4,8 @@ #include #include #include "Faces.h" +#include "AudioPlayer.h" +#include "StringFunctions.h" PartInstance::PartInstance(void) { @@ -27,6 +29,7 @@ PartInstance::PartInstance(void) left = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth; shape = Enum::Shape::Block; + _touchedOnce = false; // OnTouch singleShot = true; @@ -34,6 +37,7 @@ PartInstance::PartInstance(void) uniqueObjectsToTrigger = 1; changeScore = 0; changeTimer = 0; + singleShot = true; } bool PartInstance::isDragging() @@ -67,6 +71,32 @@ Vector3 PartInstance::getRotVelocity() return rotVelocity; } +// OnTouch +bool PartInstance::isSingleShot() +{ + return singleShot; +} + +int PartInstance::getTouchesToTrigger() +{ + return touchesToTrigger; +} + +int PartInstance::getUniqueObjectsToTrigger() +{ + return uniqueObjectsToTrigger; +} + +int PartInstance::getChangeScore() +{ + return changeScore; +} + +float PartInstance::getChangeTimer() +{ + return changeTimer; +} + void PartInstance::setVelocity(Vector3 v) { velocity = v; @@ -197,6 +227,8 @@ PartInstance::PartInstance(const PartInstance &oinst) changeTimer = oinst.changeTimer; OnTouchAction = oinst.OnTouchAction; OnTouchSound = oinst.OnTouchSound; + singleShot = oinst.singleShot; + _touchedOnce = false; } void PartInstance::setSize(Vector3 newSize) @@ -459,6 +491,46 @@ static Enum::Sound::Value EnumOnTouchSoundType(TCHAR* option) return Enum::Sound::NoSound; } +void PartInstance::onTouch() +{ + if(singleShot && _touchedOnce) + return; + + if(singleShot && !_touchedOnce) + _touchedOnce = true; + + g_dataModel->getLevel()->score += changeScore; + g_dataModel->getLevel()->timer += changeTimer; + + switch(OnTouchAction) + { + case Enum::ActionType::Nothing: + break; + case Enum::ActionType::Pause: + break; + case Enum::ActionType::Lose: + g_dataModel->getLevel()->loseCondition(); + break; + case Enum::ActionType::Draw: + break; + case Enum::ActionType::Win: + g_dataModel->getLevel()->winCondition(); + break; + } + + switch(OnTouchSound) + { + case Enum::Sound::NoSound: + break; + case Enum::Sound::Victory: + AudioPlayer::playSound(GetFileInPath("/content/sounds/victory.wav")); + break; + case Enum::Sound::Boing: + AudioPlayer::playSound(GetFileInPath("/content/sounds/boing.wav")); + break; + } +} + void PartInstance::PropUpdate(LPPROPGRIDITEM &item) { setChanged(); @@ -526,9 +598,25 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) { OnTouchSound = EnumOnTouchSoundType((TCHAR*)item->lpCurValue); } + else if (strcmp(item->lpszPropName, "ChangeScore") == 0) + { + changeScore = atoi((LPSTR)item->lpCurValue); + } + else if (strcmp(item->lpszPropName, "ChangeTimer") == 0) + { + changeTimer = atof((LPSTR)item->lpCurValue); + } + else if (strcmp(item->lpszPropName, "SingleShot") == 0) + { + singleShot = item->lpCurValue == TRUE; + } else PVInstance::PropUpdate(item); } +// This needs to be changed, buffer size of 12 is way too small +// Crash occurs if you put a huge number in +char changeTimerTxt[12]; +char changeScoreTxt[12]; std::vector PartInstance::getProperties() { std::vector properties = PVInstance::getProperties(); @@ -581,6 +669,25 @@ std::vector PartInstance::getProperties() PIT_COMBO, TEXT("NoSound\0Victory\0Boing\0") )); + + sprintf_s(changeScoreTxt, "%d", changeScore); + sprintf_s(changeTimerTxt, "%g", changeTimer); + properties.push_back(createPGI("OnTouch", + "ChangeScore", + "How the score is affected when touched", + (LPARAM)changeScoreTxt, + PIT_EDIT)); + properties.push_back(createPGI("OnTouch", + "ChangeTimer", + "How the timer is affected when touched", + (LPARAM)changeTimerTxt, + PIT_EDIT)); + properties.push_back(createPGI("OnTouch", + "SingleShot", + "Whether or not Action happens only once", + (LPARAM)singleShot, + PIT_CHECK + )); return properties; } diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 7421fb7..8373c8f 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -25,10 +25,10 @@ XplicitNgine::~XplicitNgine() dCloseODE(); } -void XplicitNgine::resetBody(PartInstance* partInstance) -{ - deleteBody(partInstance); - createBody(partInstance); +void XplicitNgine::resetBody(PartInstance* partInstance) +{ + deleteBody(partInstance); + createBody(partInstance); } void collisionCallback(void *data, dGeomID o1, dGeomID o2) @@ -37,10 +37,12 @@ void collisionCallback(void *data, dGeomID o1, dGeomID o2) dBodyID b1 = dGeomGetBody(o1); dBodyID b2 = dGeomGetBody(o2); - + if (b1 && b2 && dAreConnected(b1, b2)) return; + + const int N = 4; dContact contact[N]; n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); @@ -62,8 +64,17 @@ void collisionCallback(void *data, dGeomID o1, dGeomID o2) g_xplicitNgine->contactgroup, contact+i ); - + dJointAttach (c,b1,b2); + + if(b1 != NULL) + { + PartInstance* touched = (PartInstance*)dGeomGetData(o2); + if(touched != NULL) + { + touched->onTouch(); + } + } } } } @@ -123,6 +134,7 @@ void XplicitNgine::createBody(PartInstance* partInstance) partInstance->physBody = dBodyCreate(physWorld); dBodySetData(partInstance->physBody, partInstance); + // Create geom if(partInstance->shape == Enum::Shape::Block) { @@ -140,6 +152,9 @@ void XplicitNgine::createBody(PartInstance* partInstance) partInstance->physGeom[0] = dCreateSphere(physSpace, partSize[0]/2); } + if(partInstance->physGeom[0]) + dGeomSetData(partInstance->physGeom[0], partInstance); + dMass mass; mass.setBox(sqrt(partSize.x*2), sqrt(partSize.y*2), sqrt(partSize.z*2), 0.7F); dBodySetMass(partInstance->physBody, &mass);