aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-17 15:34:32 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-17 15:34:32 +0100
commit876a2e2ba115f6f8afa45155c8c6ed90d10576de (patch)
tree71dd70d555831eba188210d522993f1f249e772d /src/crepe
parentb019b401c3a1de0ffea7e6776242ae73599651ef (diff)
added functionality to example and added pictures
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/LoopManager.cpp13
-rw-r--r--src/crepe/facade/SDLContext.cpp4
-rw-r--r--src/crepe/system/CollisionSystem.cpp22
3 files changed, 23 insertions, 16 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 2e9823f..f9c5362 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -2,6 +2,8 @@
#include "../facade/SDLContext.h"
#include "../system/RenderSystem.h"
#include "../system/ScriptSystem.h"
+#include "..//system/PhysicsSystem.h"
+#include "..//system/CollisionSystem.h"
#include "LoopManager.h"
#include "LoopTimer.h"
@@ -18,7 +20,12 @@ void LoopManager::start() {
}
void LoopManager::set_running(bool running) { this->game_running = running; }
-void LoopManager::fixed_update() {}
+void LoopManager::fixed_update() {
+ PhysicsSystem phys;
+ phys.update();
+ CollisionSystem col;
+ col.update();
+}
void LoopManager::loop() {
LoopTimer & timer = LoopTimer::get_instance();
@@ -27,11 +34,11 @@ void LoopManager::loop() {
while (game_running) {
timer.update();
- while (timer.get_lag() >= timer.get_fixed_delta_time()) {
+ //while (timer.get_lag() >= timer.get_fixed_delta_time()) {
this->process_input();
this->fixed_update();
timer.advance_fixed_update();
- }
+ //}
this->update();
this->render();
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 236bf8c..274cd7a 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -130,8 +130,8 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform,
};
SDL_Rect dstrect = {
- .x = static_cast<int>(adjusted_x),
- .y = static_cast<int>(adjusted_y),
+ .x = static_cast<int>(adjusted_x/2),
+ .y = static_cast<int>(adjusted_y/2),
.w = static_cast<int>(adjusted_w),
.h = static_cast<int>(adjusted_h),
};
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index b9366df..d59539e 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -27,7 +27,7 @@ void CollisionSystem::update() {
std::vector<std::reference_wrapper<BoxCollider>> boxcolliders = mgr.get_components_by_type<BoxCollider>();
std::vector<std::reference_wrapper<CircleCollider>> circlecolliders = mgr.get_components_by_type<CircleCollider>();
std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> collided = check_collisions(boxcolliders,circlecolliders);
- std::cout << "DEBUG INFO" << std::endl;
+ // std::cout << "DEBUG INFO" << std::endl;
for (const auto& collision_pair : collided) {
call_collision_handler(collision_pair.first,collision_pair.second); // First collider
call_collision_handler(collision_pair.second,collision_pair.first); // First collider
@@ -202,12 +202,12 @@ bool CollisionSystem::check_box_box_collision(const BoxCollider& box1, const Box
Vector2 final_position2 = current_position(box2,transform2,rigidbody2);
// Log final positions for debugging purposes
- std::cout << "Final Position of Box 1: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
- std::cout << "Final Position of Box 2: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
+ // std::cout << "Final Position of Box 1: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
+ // std::cout << "Final Position of Box 2: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
// Log rotation values for debugging
- std::cout << "Rotation of Box 1: " << transform1.rotation << " degrees" << std::endl;
- std::cout << "Rotation of Box 2: " << transform2.rotation << " degrees" << std::endl;
+ // std::cout << "Rotation of Box 1: " << transform1.rotation << " degrees" << std::endl;
+ // std::cout << "Rotation of Box 2: " << transform2.rotation << " degrees" << std::endl;
// Calculate half-extents (half width and half height)
@@ -229,8 +229,8 @@ bool CollisionSystem::check_box_circle_collision(const BoxCollider& box1, const
Vector2 final_position2 = current_position(circle2, transform2, rigidbody2);
// Log final positions for debugging purposes
- std::cout << "Final Position of Box: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
- std::cout << "Final Position of Circle: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
+ // std::cout << "Final Position of Box: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
+ // std::cout << "Final Position of Circle: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
// Calculate box half-extents
double half_width = box1.width / 2.0;
@@ -256,12 +256,12 @@ bool CollisionSystem::check_circle_circle_collision(const CircleCollider& circle
Vector2 final_position2 = current_position(circle2,transform2,rigidbody2);
// Log final positions for debugging purposes
- std::cout << "Final Position of Circle 1: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
- std::cout << "Final Position of Circle 2: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
+ // std::cout << "Final Position of Circle 1: (" << final_position1.x << ", " << final_position1.y << ")" << std::endl;
+ // std::cout << "Final Position of Circle 2: (" << final_position2.x << ", " << final_position2.y << ")" << std::endl;
// Log rotation values for debugging (circles do not rotate, so this might not be needed for circles)
- std::cout << "Rotation of Circle 1: " << transform1.rotation << " degrees" << std::endl;
- std::cout << "Rotation of Circle 2: " << transform2.rotation << " degrees" << std::endl;
+ // std::cout << "Rotation of Circle 1: " << transform1.rotation << " degrees" << std::endl;
+ // std::cout << "Rotation of Circle 2: " << transform2.rotation << " degrees" << std::endl;
double distance_x = final_position1.x - final_position2.x;
double distance_y = final_position1.y - final_position2.y;