Very basic implementation of OnTouch

This commit is contained in:
Modnark
2022-10-11 10:03:04 -04:00
parent adade066cc
commit d2f3e718a7
6 changed files with 149 additions and 14 deletions

BIN
content/sounds/bass.wav Normal file

Binary file not shown.

BIN
content/sounds/victory.wav Normal file

Binary file not shown.

View File

@@ -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<PROPGRIDITEM> 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;
};

View File

@@ -123,7 +123,7 @@ std::vector<PROPGRIDITEM> 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<PROPGRIDITEM> 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),

View File

@@ -4,6 +4,8 @@
#include <sstream>
#include <iomanip>
#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<PROPGRIDITEM> PartInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
@@ -581,6 +669,25 @@ std::vector<PROPGRIDITEM> 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;
}

View File

@@ -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);