aboutsummaryrefslogtreecommitdiff
path: root/mwe/gameloop/src/loopManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-23 21:15:58 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-23 21:15:58 +0200
commitb5e83d076f356c6d01b7bbc1f033db4850356c0d (patch)
treec4b11f86c6ab1685e46fab9d674377a39e612fd7 /mwe/gameloop/src/loopManager.cpp
parent51c8a51b53a850265955a3e4bc45b40ad3f8c477 (diff)
parent04a040e28ade412ea5b1767bf77eed3956121973 (diff)
pull origin master
Diffstat (limited to 'mwe/gameloop/src/loopManager.cpp')
-rw-r--r--mwe/gameloop/src/loopManager.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/mwe/gameloop/src/loopManager.cpp b/mwe/gameloop/src/loopManager.cpp
index cb532cc..0392853 100644
--- a/mwe/gameloop/src/loopManager.cpp
+++ b/mwe/gameloop/src/loopManager.cpp
@@ -11,7 +11,14 @@ void LoopManager::processInput() {
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) {
gameRunning = false;
+ } else if (event.key.keysym.sym == SDLK_i) {
+ LoopTimer::getInstance().setGameScale(
+ LoopTimer::getInstance().getGameScale() + 0.1);
+ } else if (event.key.keysym.sym == SDLK_k) {
+ LoopTimer::getInstance().setGameScale(
+ LoopTimer::getInstance().getGameScale() - 0.1);
}
+
break;
}
}
@@ -41,11 +48,11 @@ void LoopManager::loop() {
void LoopManager::setup() {
gameRunning = window.initWindow();
LoopTimer::getInstance().start();
- LoopTimer::getInstance().setFPS(50);
+ LoopTimer::getInstance().setFPS(500);
- for (int i = 0; i < 2; i++) {
+ for (int i = 1; i < 3; i++) {
GameObject * square
- = new GameObject("square2", i * 40, i * 40, 20, 20, 0, 0);
+ = new GameObject("square2", i * 60, i * 60, 20, 20, 0, 0);
objectList.push_back(square);
}
}
@@ -57,13 +64,26 @@ void LoopManager::render() {
}
void LoopManager::update() {
- fprintf(stderr, "**********normal update********** \n");
+ fprintf(stderr, "********** normal update ********** \n");
LoopTimer & timer = LoopTimer::getInstance();
float delta = timer.getDeltaTime();
-
for (int i = 0; i < objectList.size(); i++) {
- objectList[i]->setX(objectList[i]->getX() + 50 * delta);
- objectList[i]->setY(objectList[i]->getY() + 50 * delta);
+ GameObject * obj = objectList[i];
+
+ // Move the object based on its direction
+ if (obj->direction == 1) {
+ obj->setX(obj->getX() + 50 * delta);
+ } else {
+ obj->setX(obj->getX() - 50 * delta);
+ }
+
+ if (obj->getX() > 500) {
+ obj->setX(500);
+ obj->direction = 0; // Switch direction to left
+ } else if (obj->getX() < 50) {
+ obj->setX(50); // Clamp the position to the boundary
+ obj->direction = 1; // Switch direction to right
+ }
}
}