From 5c19ed004482e7f48dd25ad111f46d515b7f6454 Mon Sep 17 00:00:00 2001 From: aarav-prakash Date: Fri, 6 Feb 2026 16:42:38 +0530 Subject: [PATCH 1/2] Syntax Corrections --- include/PhysicsObject.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/PhysicsObject.h b/include/PhysicsObject.h index c34edd4..cdb54e2 100644 --- a/include/PhysicsObject.h +++ b/include/PhysicsObject.h @@ -19,8 +19,8 @@ class PhysicsObject { PhysicsAttributes attributes; public: - virtual void PhysicsObject() = 0; - virtual void ~PhysicsObject() = 0; + virtual PhysicsObject() = 0; + virtual ~PhysicsObject() = 0; // virtual get.set; // apply force @@ -30,6 +30,6 @@ class PhysicsObject { // bool checkCollision(PhysicsObject& other); // void resolveCollision(PhysicsObject& other); - virtual void update(sf::Time dt){} = 0; // do nothing :) - virtual void draw(sf::RenderWindow& window){} = 0; + virtual void update(sf::Time dt) = 0; // do nothing :) + virtual void draw(sf::RenderWindow& window) = 0; }; \ No newline at end of file From 7bb2d4bd6ad2e40a97fd3c1b2ea997bc987a095c Mon Sep 17 00:00:00 2001 From: aarav-prakash Date: Fri, 6 Feb 2026 23:43:17 +0530 Subject: [PATCH 2/2] Initial attempts at circle.h and circle.cpp. --- include/_circle.h | 22 ++++++++++++++++++++++ include/physics_object.h | 4 +++- src/circle.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 include/_circle.h create mode 100644 src/circle.cpp diff --git a/include/_circle.h b/include/_circle.h new file mode 100644 index 0000000..397ccd5 --- /dev/null +++ b/include/_circle.h @@ -0,0 +1,22 @@ +#ifndef CIRCLE_H +#define CIRCLE_H + +#include +#include "physics_object.h" + +class Circle : public PhysicsObject { +private: + float radius; + sf::CircleShape shape; + ShapeID ID = ShapeID::CIRCLE_SHAPE; + +public: + Circle(float r, sf::Vector2f position); + + void update(sf::Time deltaTime) override; + void draw(sf::RenderWindow& window) override; + + float getRadius() const; +}; + +#endif diff --git a/include/physics_object.h b/include/physics_object.h index 5e1e0b2..d0f2dc8 100644 --- a/include/physics_object.h +++ b/include/physics_object.h @@ -1,4 +1,6 @@ #include +#include +#pragma once struct PhysicalAttributes { float mass; @@ -30,7 +32,7 @@ class PhysicsObject { PhysicalAttributes attributes; public: - virtual ~PhysicsObject(); + virtual ~PhysicsObject() = default; // virtual get.set; // apply force diff --git a/src/circle.cpp b/src/circle.cpp new file mode 100644 index 0000000..a981a09 --- /dev/null +++ b/src/circle.cpp @@ -0,0 +1,29 @@ +#include "_circle.h" + +Circle::Circle(float r, sf::Vector2f pos) : PhysicsObject(pos), radius(r) { + shape.setRadius(radius); + shape.setOrigin(radius, radius); + shape.setPosition(pos); +} + +void Circle::update(sf::Time dt) { + sf::Vector2f pos = getPosition(); + sf::Vector2f vel = getVelocity(); + sf::Vector2f acc = getAcceleration(); + + float dts = dt.asSeconds(); + pos += vel * dts + acc * (0.5f * dts * dts); + vel += acc * dts; + + shape.setPosition(pos); + setVelocity(vel); + setPosition(pos); +} + +void Circle::draw(sf::RenderWindow& window) { + window.draw(shape); +} + +float Circle::getRadius() const { + return radius; +}