summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelik Houij <houijmelik08@protonmail.com>2022-09-09 08:43:27 +0200
committerMelik Houij <houijmelik08@protonmail.com>2022-09-09 08:43:27 +0200
commitcc07abb12c228d66b63399dfb758c511fbbd956c (patch)
tree068895c2d3cdd31792606c045ba9d02e3b768a20
parent2c17f2f68241a9b239fc915077c6f473584e5e10 (diff)
Got polymorphism to work with UIORIG_HEAD
-rw-r--r--gobject.h57
-rw-r--r--scene.h4
2 files changed, 58 insertions, 3 deletions
diff --git a/gobject.h b/gobject.h
index 6fb31b6..260bc41 100644
--- a/gobject.h
+++ b/gobject.h
@@ -19,6 +19,7 @@ PRESSED,
HELD
};
+// TODO maybe update returns a list of hitboxes?
struct inGameInput{
ginput bState = UNPRESSED; // button State
uint16_t timeHeld = 0; // time held
@@ -41,6 +42,7 @@ uint16_t timeHeld = 0; // time held
timeHeld++;
break;
default:
+ bState = HELD;
break;
}
@@ -67,6 +69,8 @@ class gobject
{
// NOTE game Object, this will probably be the one changed the most often
// TODO might have to give my try at polymorthy
+
+ protected:
std::vector<Animation2D> anilist;
float xPos, yPos, scale;
unsigned int currentanim = 0;
@@ -106,7 +110,7 @@ class gobject
this->xPos = xP;
this->yPos = yP;
}
- void update(GLFWwindow *window, bool paused, std::array<inGameInput,8> gameInput)
+ 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
@@ -137,6 +141,57 @@ class gobject
}
}
+
+
};
+class test:public gobject
+{
+ private:
+ std::vector<Animation2D> anilist;
+ float xPos, yPos, scale;
+ unsigned int currentanim = 0;
+ Shader *shader;
+ public:
+ test(const float scale, Shader *shader):gobject(scale, shader)
+ {
+ // NOTE game object Constructor
+ this->xPos = 0.0f;
+ this->yPos = 0.0f;
+ this->scale = scale;
+ this->shader = shader;
+ }
+ void update(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;
+ // NOTE lord forgive me
+ if (!paused)
+ {
+ if (gameInput[2].bState >= PRESSED)
+ this->move(-0.1f);
+ if (gameInput[3].bState >= PRESSED)
+ this->move(0.1f);
+ if (gameInput[4].bState == PRESSED)
+ {
+ this->currentanim = 0;
+ reset = true;
+ }
+ if (gameInput[5].bState == PRESSED)
+ {
+ this->currentanim = 1;
+ reset = true;
+ }
+ play(this->currentanim, reset);
+ reset = false;
+ }
+ else {
+ shader->use();
+ anilist.at(this->currentanim).draw();
+ }
+ }
+};
+
+
#endif
diff --git a/scene.h b/scene.h
index d63e744..b6e7558 100644
--- a/scene.h
+++ b/scene.h
@@ -103,7 +103,7 @@ class Scene
// NOTE temporary Code,used for Testing
// TODO test how the Engine handles multiple objects at the same time
- objects.push_back(gobject(0.5f, shade));
+ 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);
printf("scene created\n \n");
@@ -132,7 +132,7 @@ class Scene
for(gobject& x:objects)
{
//NOTE simple, runs an update to each game Object on the Vector
- x.update(window, paused, buttons);
+ x.update(paused, buttons);
}
if(this->paused == false)