Very basic implementation of OnTouch
This commit is contained in:
BIN
content/sounds/bass.wav
Normal file
BIN
content/sounds/bass.wav
Normal file
Binary file not shown.
BIN
content/sounds/victory.wav
Normal file
BIN
content/sounds/victory.wav
Normal file
Binary file not shown.
@@ -30,18 +30,13 @@ public:
|
|||||||
|
|
||||||
//OnTocuh
|
//OnTocuh
|
||||||
Enum::ActionType::Value OnTouchAction;
|
Enum::ActionType::Value OnTouchAction;
|
||||||
Enum::Sound::Value OnTouchSound;
|
Enum::Sound::Value OnTouchSound;
|
||||||
|
|
||||||
//Variables
|
//Variables
|
||||||
Color3 color;
|
Color3 color;
|
||||||
bool canCollide;
|
bool canCollide;
|
||||||
dBodyID physBody;
|
dBodyID physBody;
|
||||||
dGeomID physGeom[3];
|
dGeomID physGeom[3];
|
||||||
bool singleShot;
|
|
||||||
int touchesToTrigger;
|
|
||||||
int uniqueObjectsToTrigger;
|
|
||||||
int changeScore;
|
|
||||||
int changeTimer;
|
|
||||||
|
|
||||||
//Getters
|
//Getters
|
||||||
Vector3 getPosition();
|
Vector3 getPosition();
|
||||||
@@ -53,6 +48,13 @@ public:
|
|||||||
Box getScaledBox();
|
Box getScaledBox();
|
||||||
CoordinateFrame getCFrame();
|
CoordinateFrame getCFrame();
|
||||||
|
|
||||||
|
//OnTouch Getters
|
||||||
|
bool isSingleShot();
|
||||||
|
int getTouchesToTrigger();
|
||||||
|
int getUniqueObjectsToTrigger();
|
||||||
|
int getChangeScore();
|
||||||
|
float getChangeTimer();
|
||||||
|
|
||||||
//Setters
|
//Setters
|
||||||
void setParent(Instance* parent);
|
void setParent(Instance* parent);
|
||||||
void setPosition(Vector3);
|
void setPosition(Vector3);
|
||||||
@@ -74,6 +76,9 @@ public:
|
|||||||
bool collides(PartInstance * part);
|
bool collides(PartInstance * part);
|
||||||
bool collides(Box);
|
bool collides(Box);
|
||||||
|
|
||||||
|
// onTouch
|
||||||
|
void onTouch();
|
||||||
|
|
||||||
//Properties
|
//Properties
|
||||||
virtual std::vector<PROPGRIDITEM> getProperties();
|
virtual std::vector<PROPGRIDITEM> getProperties();
|
||||||
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
|
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
|
||||||
@@ -87,4 +92,12 @@ private:
|
|||||||
bool dragging;
|
bool dragging;
|
||||||
Box itemBox;
|
Box itemBox;
|
||||||
GLuint glList;
|
GLuint glList;
|
||||||
|
|
||||||
|
// OnTouch
|
||||||
|
bool singleShot;
|
||||||
|
int touchesToTrigger;
|
||||||
|
int uniqueObjectsToTrigger;
|
||||||
|
int changeScore;
|
||||||
|
float changeTimer;
|
||||||
|
bool _touchedOnce;
|
||||||
};
|
};
|
||||||
@@ -123,7 +123,7 @@ std::vector<PROPGRIDITEM> LevelInstance::getProperties()
|
|||||||
(LPARAM)scoreTxt,
|
(LPARAM)scoreTxt,
|
||||||
PIT_EDIT));
|
PIT_EDIT));
|
||||||
|
|
||||||
properties.push_back(createPGI("Gameplay",
|
properties.push_back(createPGI("Gameplay",
|
||||||
"TimerUpAction",
|
"TimerUpAction",
|
||||||
"Some temporary string here",
|
"Some temporary string here",
|
||||||
(LPARAM)strActionType(TimerUpAction),
|
(LPARAM)strActionType(TimerUpAction),
|
||||||
@@ -131,7 +131,7 @@ std::vector<PROPGRIDITEM> LevelInstance::getProperties()
|
|||||||
TEXT("Nothing\0Pause\0Lose\0Draw\0Win\0")
|
TEXT("Nothing\0Pause\0Lose\0Draw\0Win\0")
|
||||||
));
|
));
|
||||||
|
|
||||||
properties.push_back(createPGI("Gameplay",
|
properties.push_back(createPGI("Gameplay",
|
||||||
"TimerAffectsScore",
|
"TimerAffectsScore",
|
||||||
"Some temporary string here",
|
"Some temporary string here",
|
||||||
(LPARAM)strAffectType(TimerAffectsScore),
|
(LPARAM)strAffectType(TimerAffectsScore),
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include "Faces.h"
|
#include "Faces.h"
|
||||||
|
#include "AudioPlayer.h"
|
||||||
|
#include "StringFunctions.h"
|
||||||
|
|
||||||
PartInstance::PartInstance(void)
|
PartInstance::PartInstance(void)
|
||||||
{
|
{
|
||||||
@@ -27,6 +29,7 @@ PartInstance::PartInstance(void)
|
|||||||
left = Enum::SurfaceType::Smooth;
|
left = Enum::SurfaceType::Smooth;
|
||||||
bottom = Enum::SurfaceType::Smooth;
|
bottom = Enum::SurfaceType::Smooth;
|
||||||
shape = Enum::Shape::Block;
|
shape = Enum::Shape::Block;
|
||||||
|
_touchedOnce = false;
|
||||||
|
|
||||||
// OnTouch
|
// OnTouch
|
||||||
singleShot = true;
|
singleShot = true;
|
||||||
@@ -34,6 +37,7 @@ PartInstance::PartInstance(void)
|
|||||||
uniqueObjectsToTrigger = 1;
|
uniqueObjectsToTrigger = 1;
|
||||||
changeScore = 0;
|
changeScore = 0;
|
||||||
changeTimer = 0;
|
changeTimer = 0;
|
||||||
|
singleShot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartInstance::isDragging()
|
bool PartInstance::isDragging()
|
||||||
@@ -67,6 +71,32 @@ Vector3 PartInstance::getRotVelocity()
|
|||||||
return rotVelocity;
|
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)
|
void PartInstance::setVelocity(Vector3 v)
|
||||||
{
|
{
|
||||||
velocity = v;
|
velocity = v;
|
||||||
@@ -197,6 +227,8 @@ PartInstance::PartInstance(const PartInstance &oinst)
|
|||||||
changeTimer = oinst.changeTimer;
|
changeTimer = oinst.changeTimer;
|
||||||
OnTouchAction = oinst.OnTouchAction;
|
OnTouchAction = oinst.OnTouchAction;
|
||||||
OnTouchSound = oinst.OnTouchSound;
|
OnTouchSound = oinst.OnTouchSound;
|
||||||
|
singleShot = oinst.singleShot;
|
||||||
|
_touchedOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartInstance::setSize(Vector3 newSize)
|
void PartInstance::setSize(Vector3 newSize)
|
||||||
@@ -459,6 +491,46 @@ static Enum::Sound::Value EnumOnTouchSoundType(TCHAR* option)
|
|||||||
return Enum::Sound::NoSound;
|
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)
|
void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
|
||||||
{
|
{
|
||||||
setChanged();
|
setChanged();
|
||||||
@@ -526,9 +598,25 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
|
|||||||
{
|
{
|
||||||
OnTouchSound = EnumOnTouchSoundType((TCHAR*)item->lpCurValue);
|
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);
|
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> PartInstance::getProperties()
|
||||||
{
|
{
|
||||||
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
|
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
|
||||||
@@ -581,6 +669,25 @@ std::vector<PROPGRIDITEM> PartInstance::getProperties()
|
|||||||
PIT_COMBO,
|
PIT_COMBO,
|
||||||
TEXT("NoSound\0Victory\0Boing\0")
|
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;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ XplicitNgine::~XplicitNgine()
|
|||||||
dCloseODE();
|
dCloseODE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XplicitNgine::resetBody(PartInstance* partInstance)
|
void XplicitNgine::resetBody(PartInstance* partInstance)
|
||||||
{
|
{
|
||||||
deleteBody(partInstance);
|
deleteBody(partInstance);
|
||||||
createBody(partInstance);
|
createBody(partInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void collisionCallback(void *data, dGeomID o1, dGeomID o2)
|
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 b1 = dGeomGetBody(o1);
|
||||||
dBodyID b2 = dGeomGetBody(o2);
|
dBodyID b2 = dGeomGetBody(o2);
|
||||||
|
|
||||||
if (b1 && b2 && dAreConnected(b1, b2))
|
if (b1 && b2 && dAreConnected(b1, b2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const int N = 4;
|
const int N = 4;
|
||||||
dContact contact[N];
|
dContact contact[N];
|
||||||
n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
|
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,
|
g_xplicitNgine->contactgroup,
|
||||||
contact+i
|
contact+i
|
||||||
);
|
);
|
||||||
|
|
||||||
dJointAttach (c,b1,b2);
|
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);
|
partInstance->physBody = dBodyCreate(physWorld);
|
||||||
dBodySetData(partInstance->physBody, partInstance);
|
dBodySetData(partInstance->physBody, partInstance);
|
||||||
|
|
||||||
|
|
||||||
// Create geom
|
// Create geom
|
||||||
if(partInstance->shape == Enum::Shape::Block)
|
if(partInstance->shape == Enum::Shape::Block)
|
||||||
{
|
{
|
||||||
@@ -140,6 +152,9 @@ void XplicitNgine::createBody(PartInstance* partInstance)
|
|||||||
partInstance->physGeom[0] = dCreateSphere(physSpace, partSize[0]/2);
|
partInstance->physGeom[0] = dCreateSphere(physSpace, partSize[0]/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(partInstance->physGeom[0])
|
||||||
|
dGeomSetData(partInstance->physGeom[0], partInstance);
|
||||||
|
|
||||||
dMass mass;
|
dMass mass;
|
||||||
mass.setBox(sqrt(partSize.x*2), sqrt(partSize.y*2), sqrt(partSize.z*2), 0.7F);
|
mass.setBox(sqrt(partSize.x*2), sqrt(partSize.y*2), sqrt(partSize.z*2), 0.7F);
|
||||||
dBodySetMass(partInstance->physBody, &mass);
|
dBodySetMass(partInstance->physBody, &mass);
|
||||||
|
|||||||
Reference in New Issue
Block a user