Made LevelInstance (DataModel V1.1_01?)

This commit is contained in:
andreja6
2018-10-25 09:45:13 -07:00
parent d7b491e073
commit 62208a14a5
8 changed files with 110 additions and 65 deletions

View File

@@ -9,17 +9,16 @@ DataModelInstance::DataModelInstance(void)
Instance::Instance();
workspace = new WorkspaceInstance();
guiRoot = new Instance();
level = new LevelInstance();
children.push_back(workspace);
children.push_back(level);
className = "dataModel";
mousex = 0;
mousey = 0;
mouseButton1Down = false;
showMessage = false;
canDelete = false;
winMessage = "You Won!";
loseMessage = "You Lost. Try Again";
timer = 60.0F;
score = 0;
}
DataModelInstance::~DataModelInstance(void)
@@ -74,58 +73,8 @@ Instance* DataModelInstance::getGuiRoot()
return guiRoot;
}
char timerTxt[12];
char scoreTxt[12];
std::vector<PROPGRIDITEM> DataModelInstance::getProperties()
LevelInstance* DataModelInstance::getLevel()
{
std::vector<PROPGRIDITEM> properties = Instance::getProperties();
properties.push_back(createPGI("Messages",
"WinMessage",
"The message that shows when the player wins.",
(LPARAM)winMessage.c_str(),
PIT_EDIT));
properties.push_back(createPGI("Messages",
"LoseMessage",
"The message that shows when the player loses.",
(LPARAM)loseMessage.c_str(),
PIT_EDIT));
sprintf(timerTxt, "%g", timer);
sprintf(scoreTxt, "%d", score);
properties.push_back(createPGI("Gameplay",
"InitialTimerValue",
"The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.",
(LPARAM)timerTxt,
PIT_EDIT));
properties.push_back(createPGI("Gameplay",
"InitialScoreValue",
"The ammount of points the player starts with.",
(LPARAM)scoreTxt,
PIT_EDIT));
return properties;
}
void DataModelInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0)
{
timer = atoi((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0)
{
score = atof((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "LoseMessage") == 0)
{
loseMessage = (LPSTR)pItem->lpCurValue;
}
if(strcmp(pItem->lpszPropName, "WinMessage") == 0)
{
winMessage = (LPSTR)pItem->lpCurValue;
}
else
Instance::PropUpdate(pItem);
return level;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "instance.h"
#include "WorkspaceInstance.h"
#include "LevelInstance.h"
class DataModelInstance :
public Instance
@@ -13,6 +14,8 @@ public:
void drawMessage(RenderDevice*);
WorkspaceInstance* getWorkspace();
WorkspaceInstance* workspace;
LevelInstance * level;
LevelInstance * getLevel();
Instance* guiRoot;
std::string message;
bool showMessage;
@@ -25,10 +28,5 @@ public:
void setMousePos(Vector2 pos);
bool mouseButton1Down;
float timer;
int score;
virtual std::vector<PROPGRIDITEM> getProperties();
std::string winMessage;
std::string loseMessage;
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

View File

@@ -325,6 +325,10 @@
RelativePath=".\Instance.cpp"
>
</File>
<File
RelativePath=".\LevelInstance.cpp"
>
</File>
<File
RelativePath=".\PartInstance.cpp"
>
@@ -430,6 +434,10 @@
RelativePath=".\Instance.h"
>
</File>
<File
RelativePath=".\LevelInstance.h"
>
</File>
<File
RelativePath=".\PartInstance.h"
>

View File

@@ -3,6 +3,7 @@
GroupInstance::GroupInstance(void)
{
PVInstance::PVInstance();
className = "GroupInstance";
}
GroupInstance::GroupInstance(const GroupInstance &oinst)

72
LevelInstance.cpp Normal file
View File

@@ -0,0 +1,72 @@
#include "LevelInstance.h"
LevelInstance::LevelInstance(void)
{
Instance::Instance();
name = "Level";
winMessage = "You Won!";
loseMessage = "You Lost. Try Again";
timer = 60.0F;
score = 0;
}
LevelInstance::~LevelInstance(void)
{
}
char timerTxt[12];
char scoreTxt[12];
std::vector<PROPGRIDITEM> LevelInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = Instance::getProperties();
properties.push_back(createPGI("Messages",
"WinMessage",
"The message that shows when the player wins.",
(LPARAM)winMessage.c_str(),
PIT_EDIT));
properties.push_back(createPGI("Messages",
"LoseMessage",
"The message that shows when the player loses.",
(LPARAM)loseMessage.c_str(),
PIT_EDIT));
sprintf(timerTxt, "%g", timer);
sprintf(scoreTxt, "%d", score);
properties.push_back(createPGI("Gameplay",
"InitialTimerValue",
"The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.",
(LPARAM)timerTxt,
PIT_EDIT));
properties.push_back(createPGI("Gameplay",
"InitialScoreValue",
"The ammount of points the player starts with.",
(LPARAM)scoreTxt,
PIT_EDIT));
return properties;
}
void LevelInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0)
{
timer = atoi((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0)
{
score = atof((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "LoseMessage") == 0)
{
loseMessage = (LPSTR)pItem->lpCurValue;
}
if(strcmp(pItem->lpszPropName, "WinMessage") == 0)
{
winMessage = (LPSTR)pItem->lpCurValue;
}
else
Instance::PropUpdate(pItem);
}

16
LevelInstance.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include "instance.h"
class LevelInstance :
public Instance
{
public:
LevelInstance(void);
~LevelInstance(void);
float timer;
int score;
virtual std::vector<PROPGRIDITEM> getProperties();
std::string winMessage;
std::string loseMessage;
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

View File

@@ -3,6 +3,7 @@
PVInstance::PVInstance(void)
{
Instance::Instance();
className = "PVInstance";
}
PVInstance::PVInstance(const PVInstance &oinst)

View File

@@ -1237,9 +1237,9 @@ void Demo::onGraphics(RenderDevice* rd) {
//TODO--Move these to their own instance
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << dataModel->timer;
stream << std::fixed << std::setprecision(1) << dataModel->getLevel()->timer;
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getLevel()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
//GUI Boxes
Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));