Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/physics_engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <memory>
#include <vector>
#include "physics_object.h"

class PhysicsEngine {
private:
std::vector<std::unique_ptr<PhysicsObject>> objects;

public:
void addObject(std::unique_ptr<PhysicsObject> obj);
void update(float dt);
void draw(sf::RenderWindow& window);
};


23 changes: 23 additions & 0 deletions src/PhysicsEngine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "physics_engine.h"

void PhysicsEngine::addObject(std::unique_ptr<PhysicsObject> obj) {
object.push_back(std::move(obj));
}

void PhysicsEngine::update(float dt) {
for (auto& obj : objects)
obj->update(dt); // update() func for objects to be declared

for (int i = 0; i < objects.size(); i++) {
for (int j = i + 1; j < objects.size(); j++) {
// require a func to access x, y coordinates
}
}
}

void PhysicsEngine::draw(sf::RenderWindow& window) {
for (auto& obj : objects)
obj->draw(window); // draw() func to open window and display collision
}