summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelik Houij <houijmelik08@protonmail.com>2022-09-21 10:48:34 +0200
committerMelik Houij <houijmelik08@protonmail.com>2022-09-21 10:48:34 +0200
commit9f52a01d9c4b549afe183914527dc8e15d537ffb (patch)
treefd33bab1c2d54deb0dd78340224a43e4494de082
parent16e51967022e48da790dac4c2168324f352d5669 (diff)
fixed polymorphism
-rw-r--r--gobject.h8
-rw-r--r--scene.h18
2 files changed, 12 insertions, 14 deletions
diff --git a/gobject.h b/gobject.h
index e914498..e9489dd 100644
--- a/gobject.h
+++ b/gobject.h
@@ -134,8 +134,7 @@ class gobject
this->yPos = yP;
}
public:
- virtual void update(/*GLFWwindow *window,*/ bool paused, std::array<inGameInput,8> gameInput) = 0;
- //{
+ virtual void update (/*GLFWwindow *window,*/ bool paused, std::array<inGameInput,8> gameInput) { };
// NOTE Update function, almost all of this code is temporary and for testing
// TODO add a proper reaction to inputs
//bool reset = false;
@@ -167,7 +166,6 @@ class gobject
}
*/
- //}
};
@@ -187,7 +185,7 @@ class test:public gobject
this->scale = scale;
this->shader = shader;
}
- void update(bool paused, std::array<inGameInput,8> gameInput)
+ void update(bool paused, std::array<inGameInput,8> gameInput) override
{
// NOTE Update function, almost all of this code is temporary and for testing
// TODO add a proper reaction to inputs
@@ -236,7 +234,7 @@ class nothing:public gobject
this->shader = shader;
printf("created");
}
- void update(bool paused, std::array<inGameInput,8> gameInput)
+ void update(bool paused, std::array<inGameInput,8> gameInput) override
{
// NOTE Update function, almost all of this code is temporary and for testing
// TODO add a proper reaction to inputs
diff --git a/scene.h b/scene.h
index 151a1af..3b582ff 100644
--- a/scene.h
+++ b/scene.h
@@ -41,7 +41,7 @@ class Scene
buttons[i].pressed(glfwGetKey(window, bConfig[i]));
};
public:
- std::vector<gobject> objects;
+ std::vector<gobject *> objects;
GLFWwindow* window;
// DONE i have to Figure out how Pausing the game should work
bool paused = false;
@@ -105,12 +105,12 @@ class Scene
// NOTE temporary Code,used for Testing
// TODO test how the Engine handles multiple objects at the same time
- objects.push_back(test(0.5f, shade));
- objects.at(0).addAnim("resources/sprite1.png", 10, VAO, 4);
- objects.at(0).addAnim("resources/sprite2.png", 10, VAO, 4);
- objects.push_back(nothing(0.5f, shade));
- objects.at(1).addAnim("resources/sprite1.png", 10, VAO, 4);
- objects.at(1).addAnim("resources/sprite2.png", 10, VAO, 4);
+ objects.push_back(new test(0.5f, shade));
+ objects.at(0)->addAnim("resources/sprite1.png", 10, VAO, 4);
+ objects.at(0)->addAnim("resources/sprite2.png", 10, VAO, 4);
+ objects.push_back(new nothing(0.5f, shade));
+ objects.at(1)->addAnim("resources/sprite1.png", 10, VAO, 4);
+ objects.at(1)->addAnim("resources/sprite2.png", 10, VAO, 4);
printf("scene created\n");
}
@@ -134,10 +134,10 @@ class Scene
}
- for(gobject& x:objects)
+ for(gobject* x:objects)
{
//NOTE simple, runs an update to each game Object on the Vector
- x.update(paused, buttons);
+ x->update(paused, buttons);
}
if(this->paused == false)