Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
8a17ffb
start working on module 3
eupp Jun 26, 2023
86208a5
operators overloading task
eupp Jul 10, 2023
536d25a
rename `scene.hpp` into `game.hpp`, split it into several files
eupp Jul 12, 2023
1376a51
working on framework lesson project implementation
eupp Jul 12, 2023
d86491c
working on framework lesson project implementation
eupp Jul 16, 2023
0f1845a
working on framework lesson project implementation
eupp Aug 8, 2023
3c79f86
working on framework lesson project implementation
eupp Aug 10, 2023
2c85d40
add black hole texture
eupp Aug 10, 2023
7b1a357
working on framework lesson project implementation
eupp Aug 11, 2023
621b163
fix texture file name
eupp Aug 11, 2023
455e92c
bugfixes and minor refactorings in framework lesson project implement…
eupp Aug 11, 2023
1abda88
implement enemy movement
eupp Aug 11, 2023
11153ad
fix scene borders adjustment
eupp Aug 11, 2023
36c37db
minor refactorings
eupp Aug 11, 2023
10835e2
implement consumable object approaching logic
eupp Aug 11, 2023
80c80db
change enemy movement update logic
eupp Aug 11, 2023
5a49201
working on framework lesson project implementation (dynamic scene)
eupp Aug 24, 2023
74ad0db
working prototype for the dynamic scene
eupp Aug 24, 2023
5401e4e
rename `SimpleScene` to `StaticScene`
eupp Aug 24, 2023
c784444
add copy-and-swap idiom to GameObjectList
eupp Aug 24, 2023
c0a3ed1
rename GameObjectState::DEAD intro GameObjectState::DESTROYED
eupp Sep 8, 2023
c98fe21
minor rewrite in OperatorsOverloading task description
eupp Sep 8, 2023
3ef8295
add documentation for GameObject class
eupp Sep 8, 2023
6e6df96
add text of OOP task1
eupp Sep 8, 2023
89d0dfe
add missing file
eupp Sep 8, 2023
98330a1
rename GameObjectState into GameObjectStatus to avoid collision with …
eupp Sep 8, 2023
2193907
dd text of OOP task2
eupp Sep 8, 2023
f615a41
minor changes in the task
eupp Sep 8, 2023
8644ae5
add classes documentation
eupp Sep 8, 2023
4523dd8
add text of OOP task3
eupp Sep 8, 2023
086edd5
add text of OOP task4
eupp Sep 11, 2023
f57d47b
minor updates in framework lesson code
eupp Sep 11, 2023
c6fc9a8
declare Scene class as a friend of GameObject
eupp Sep 11, 2023
291d61b
add text of OOP task4 (static modifier)
eupp Sep 11, 2023
e37e8de
add text of OOP task6 (objects vs POD)
eupp Sep 11, 2023
89f03e4
minor
eupp Oct 16, 2023
f6e6bde
add description of a task about enemy objects
eupp Oct 16, 2023
2832105
add task description for collision handling, minor renaming: `collisi…
eupp Oct 16, 2023
d685202
minor renaming
eupp Oct 16, 2023
03481c1
add OOP introductory task description
eupp Oct 16, 2023
da96719
linked lists task description
eupp Oct 16, 2023
cd604a4
add documentation to `DynamicScene` class, minor fixes
eupp Oct 16, 2023
4fccb43
minor grammar fixes
eupp Oct 16, 2023
357747e
minor
eupp Oct 16, 2023
e793119
mark the lesson as non-template-based
eupp Oct 16, 2023
a8bbd1c
make `GameObject::move` protected
eupp Oct 16, 2023
a89fff8
improve documentation for the game's classes
eupp Dec 1, 2023
49aab7f
rename CONCERNED to WARNED
eupp Dec 1, 2023
34dcb51
fix the concerned behavior of consumable objects
eupp Dec 1, 2023
c2c2ca9
fix the moving behavior of enemy objects
eupp Dec 1, 2023
c76f5cb
split game object list class into header/source files
eupp Dec 1, 2023
a1af1ed
expand the operators overloading task
eupp Dec 1, 2023
f7c6a42
add additional info about input/output operator overloads
eupp Dec 1, 2023
f2d8b0d
fix operator overload includes
eupp Dec 1, 2023
0ca4f02
refactor the game: add game engine class, add possibility to change b…
eupp Dec 1, 2023
4ddf970
minor bugfixes after refactoring
eupp Dec 2, 2023
c6fc622
initialize random number generator
eupp Dec 3, 2023
eaa6ea8
split window size and scene size
eupp Dec 3, 2023
fde866b
extract `updateVelocity()` method of enemy object
eupp Dec 3, 2023
f31f0dc
prepare placeholders for the student solution
eupp Dec 4, 2023
53ad17f
make `main.cpp` non-editable
eupp Dec 4, 2023
f21a401
add GameEngine::isActive function (for testing purposes)
eupp Dec 4, 2023
385b56d
student template solution for operators.cpp
eupp Dec 4, 2023
8edc779
WIP: operators task
eupp Dec 4, 2023
e4d2f2e
operators task --- add more tests
eupp Dec 6, 2023
10d782f
game object task (framework lesson stuff + tests)
eupp Dec 6, 2023
756a277
fixing framework lesson stuff (task-info.yaml and tests configuration)
eupp Dec 6, 2023
8d40dfc
add Inheritance task to the framework lesson
eupp Dec 6, 2023
e5f590f
fix SFML linking to test targets
eupp Dec 6, 2023
19b2f47
fix task-info.yaml
eupp Dec 6, 2023
e5a6b5f
add Polymorphism task to the framework lesson
eupp Dec 6, 2023
f89a8b5
add Encapsulation task to the framework lesson
eupp Dec 12, 2023
feaee5d
minor
eupp Dec 12, 2023
b2ddb72
add Static Members task to the framework lesson
eupp Dec 13, 2023
5e8845a
add Collisions Revisited task to the framework lesson
eupp Dec 15, 2023
5dbcbb2
add New Challenge task to the framework lesson
eupp Dec 15, 2023
f41b548
minor
eupp Dec 15, 2023
4046a9c
add New Dynamics task to the framework lesson
eupp Dec 15, 2023
8cd5256
fix description of enemy object task
eupp Dec 20, 2023
4213e0b
fix description of object list task
eupp Dec 20, 2023
94dd6a6
fix the game engine task description
eupp Dec 20, 2023
fd05a55
add documentation to the `utils.hpp` top-level functions
eupp Dec 20, 2023
012e9e9
resolving minor TODOs
eupp Dec 25, 2023
f088837
resolving minor TODOs
eupp Dec 25, 2023
511fd5a
Module3 ownership (#21)
boruno Dec 25, 2023
ae428e7
remove obsolete files
eupp Dec 25, 2023
69e0518
proofreading Ownership module, minor changes and clean-up
eupp Dec 25, 2023
5455236
remove obsolete files
eupp Dec 25, 2023
188e3b2
fix NewAndDeleteOperators task
eupp Dec 25, 2023
16a0cf3
rework PlacementNew task
eupp Dec 25, 2023
f132789
minor fix in NewAndDeleteOperators task
eupp Dec 25, 2023
5351ff4
reword Ownership task
eupp Dec 25, 2023
b64f49c
rework unique_ptr lesson
eupp Dec 26, 2023
80d17cc
reworking move semantics task
eupp Dec 27, 2023
790fd56
reworking move semantics task
eupp Dec 27, 2023
cdf3566
rework shared pointer task
eupp Dec 27, 2023
629efd4
rework weak pointer task
eupp Dec 27, 2023
7ba2a09
reworking RAII task
eupp Dec 28, 2023
31a38a2
reworking RAII task
eupp Dec 28, 2023
d6eec3f
reworking RAII task
eupp Dec 28, 2023
0b31970
add copy constructor task
eupp Dec 28, 2023
5050365
reworked move semantics task
eupp Dec 28, 2023
653f57b
fix operators implementation
eupp Dec 28, 2023
6fbf88e
minor in smart pointers summary lesson
eupp Dec 28, 2023
6936190
fill TODOs in RAII task
eupp Dec 28, 2023
d5ac580
language checked
stephen-hero Jan 3, 2024
21cdd62
language checked
stephen-hero Jan 3, 2024
8e9655c
language checked
stephen-hero Jan 4, 2024
cbf560f
language checked
stephen-hero Jan 4, 2024
7ea1828
language checked
stephen-hero Jan 4, 2024
078ff76
language checked
stephen-hero Jan 4, 2024
a537299
language checked
stephen-hero Jan 4, 2024
08c5a30
language checked
stephen-hero Jan 5, 2024
cf380e2
language checked
stephen-hero Jan 5, 2024
960a6a8
language checked
stephen-hero Jan 5, 2024
bb07631
language checked
stephen-hero Jan 5, 2024
53f8212
language checked
stephen-hero Jan 5, 2024
ace8ae2
language checked
stephen-hero Jan 5, 2024
7aa2699
language checked
stephen-hero Jan 5, 2024
b4c07e6
language checked
stephen-hero Jan 5, 2024
255b70b
language checked
stephen-hero Jan 5, 2024
185b650
language checked
stephen-hero Jan 8, 2024
24c582f
language checked
stephen-hero Jan 8, 2024
955e08e
language checked
stephen-hero Jan 8, 2024
a63c193
language checked
stephen-hero Jan 8, 2024
3af869f
language checked
stephen-hero Jan 8, 2024
8b0f289
fix OperatorsOverloading task CMakeLists file (add `prepare_sfml_fram…
eupp Jan 19, 2024
d8e782c
fix SharedPtr task test
eupp Jan 19, 2024
4d8d349
fix CMakeLists.txt project names
eupp Jan 19, 2024
cdbc70d
minor re-wording in some tasks
eupp Jan 19, 2024
9d564ca
fix UpdateVelocityChangedTest
eupp Jan 19, 2024
9e2a497
fix SFML linkage with tests
eupp Jan 29, 2024
409fe6f
minor fixes
eupp Feb 15, 2024
f2c56be
update course README: add module 3 topics
eupp Feb 15, 2024
87d72c4
fix after rebase
eupp Feb 15, 2024
53646e0
add *-remote-info.yaml files for module 3
eupp Feb 15, 2024
74aec44
fix HuntingBugs task after rebase
eupp Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ sfml/*

Makefile
CMakeCache.txt
.DS_Store
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/approaching.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

void approachingLoop(Circle player, Circle consumable[], bool concerned[], int size) {
for (int i = 0; i < size; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/borders.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

Point2D adjustToBorders(Point2D position) {
Point2D result = position;
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/collision.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cmath>

#include "scene.hpp"
#include "game.hpp"

float distance(Point2D a, Point2D b) {
float dx = a.x - b.x;
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/direction.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

Point2D getDirection(Direction direction) {
switch (direction) {
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/generate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

#include <cstdlib>

Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/loop.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

void collisionLoop(Circle player, Circle consumable[], bool consumed[], int size) {
for (int i = 0; i < size; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <SFML/Graphics.hpp>

#include "scene.hpp"
#include "game.hpp"
#include "dllist.hpp"

const int MAX_CONSUMABLES_COUNT = 8;
Expand Down
2 changes: 1 addition & 1 deletion MemoryManagement/LinkedList/LinkedList/src/point.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scene.hpp"
#include "game.hpp"

Point2D add(Point2D a, Point2D b) {
Point2D c = { 0, 0 };
Expand Down
4 changes: 2 additions & 2 deletions MemoryManagement/LinkedList/LinkedList/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void link(Node* cursor, Node* node);
It should link together the `cursor` and `node` nodes, putting `node` right after `cursor`.
Make sure to properly update the `next` and `prev` fields of all relevant nodes,
that is, the nodes pointed by the `cursor`, `cursor->next`, and `node` pointers.
You might assume that all nodes reachable from `cursor` through `next` and `prev`
You might assume that all nodes which are reachable from `cursor` through `next` and `prev`
are valid nodes and none of their `next` or `prev` pointers are null
(we will see why this is true for our intended list implementation later).

Expand Down Expand Up @@ -91,7 +91,7 @@ struct List {
For this scheme to work properly, we also have to initialize the
`next` and `prev` fields of the `sentry` node.
We can make them both point to the `sentry` node.
Therefore, in our encoding, an empty list is modelled as
Therefore, in our encoding, an empty list is modeled as
a list consisting of a single sentinel node whose `next` and `prev` pointers form a cycle.
Write code for the function `initList` implementing this idea
(set the `data` field of the `sentry` node to `nullptr`):
Expand Down
4 changes: 2 additions & 2 deletions MemoryManagement/MemoryLayout/Swap/task-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ type: edu
files:
- name: CMakeLists.txt
visible: false
- name: test/test.cpp
visible: false
- name: src/task.cpp
visible: true
placeholders:
- offset: 32
length: 36
placeholder_text: /* TODO */
- name: test/test.cpp
visible: false
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ custom_name: C Style Strings Concatenation
files:
- name: CMakeLists.txt
visible: false
- name: test/test.cpp
visible: false
- name: src/task.cpp
visible: true
placeholders:
- offset: 92
length: 201
placeholder_text: return nullptr;
- name: test/test.cpp
visible: false
2 changes: 1 addition & 1 deletion MemoryManagement/TypeCastsAndCStrings/CStyle/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ However, in general, C is not a strict subset of C++, meaning that
there are a lot of various [incompatibilities](https://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B)
between these languages.
Besides that, there are a lot of language features, idioms, and patterns that differ in C and C++.
These difference give rise to the mentioned C and C++ styles of doing things.
These differences give rise to the mentioned C and C++ styles of doing things.

It is important to learn to read C-style code, even if you plan to follow purely the C++ style in the future.
As of today, the C language has become a "cross-platform assembly language",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.25)

project(ObjectOrientedProgramming-ClassesAndObjects-CollisionsRevisited)

set(SRC
src/main.cpp
src/engine.cpp src/scenes.cpp src/textures.cpp
src/scene.cpp src/statscene.cpp src/dynscene.cpp
src/gobject.cpp src/gobjectlist.cpp src/cgobject.cpp
src/player.cpp src/consumable.cpp src/enemy.cpp
src/collision.cpp src/direction.cpp
src/rectangle.cpp src/point.cpp
src/operators.cpp src/utils.cpp
)

set(TEST
test/test.cpp)

add_executable(${PROJECT_NAME}-run ${SRC})

configure_test_target(${PROJECT_NAME}-test "${SRC}" ${TEST})

prepare_sfml_framework_lesson_task(
"${CMAKE_CURRENT_SOURCE_DIR}/.."
${PROJECT_NAME}-run
${PROJECT_NAME}-test
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "cgobject.hpp"

#include "operators.hpp"

CircleGameObject::CircleGameObject(Circle circle)
: circle(circle)
, status(GameObjectStatus::NORMAL)
{}

Point2D CircleGameObject::getPosition() const {
return circle.center;
}

void CircleGameObject::setPosition(Point2D position) {
circle.center = position;
}

GameObjectStatus CircleGameObject::getStatus() const {
return status;
}

void CircleGameObject::setStatus(GameObjectStatus newStatus) {
status = newStatus;
}

Circle CircleGameObject::getCircle() const {
return circle;
}

Rectangle CircleGameObject::getBoundingBox() const {
Point2D offset = { circle.radius, circle.radius };
Point2D p1 = circle.center - offset;
Point2D p2 = circle.center + offset;
return createRectangle(p1, p2);
}

void CircleGameObject::draw(sf::RenderWindow &window, TextureManager& textureManager) const {
const sf::Texture* texture = getTexture(textureManager);
if (texture == nullptr)
return;
sf::CircleShape shape;
shape.setPosition(circle.center.x, circle.center.y);
shape.setOrigin(circle.radius, circle.radius);
shape.setRadius(circle.radius);
shape.setTexture(texture);
window.draw(shape);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cassert>

#include "collision.hpp"
#include "cgobject.hpp"
#include "utils.hpp"

CollisionInfo collisionInfo(const Circle& circle1, const Circle& circle2) {
CollisionInfo info;
info.distance = distance(circle1.center, circle2.center);
info.collide = (info.distance < circle1.radius + circle2.radius);
return info;
}

CollisionInfo collisionInfo(const GameObject& object1, const GameObject& object2) {
const CircleGameObject* circleObject1 = dynamic_cast<const CircleGameObject*>(&object1);
const CircleGameObject* circleObject2 = dynamic_cast<const CircleGameObject*>(&object2);
if (circleObject1 && circleObject2) {
return collisionInfo(circleObject1->getCircle(), circleObject2->getCircle());
}
assert(false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "consumable.hpp"

#include "constants.hpp"

ConsumableObject::ConsumableObject()
: CircleGameObject({ { CONSUMABLE_START_X, CONSUMABLE_START_Y }, CONSUMABLE_RADIUS })
{}

GameObjectKind ConsumableObject::getKind() const {
return GameObjectKind::CONSUMABLE;
}

Point2D ConsumableObject::getVelocity() const {
return { 0.0f, 0.0f };
}

void ConsumableObject::update(sf::Time delta) {
if (getStatus() != GameObjectStatus::DESTROYED) {
setStatus(GameObjectStatus::NORMAL);
}
}

void ConsumableObject::onCollision(const GameObject &object, const CollisionInfo &info) {
if (getStatus() == GameObjectStatus::DESTROYED || object.getKind() == GameObjectKind::CONSUMABLE) {
return;
}
if (info.collide) {
setStatus(GameObjectStatus::DESTROYED);
return;
}
if (info.distance < CONSUMABLE_WARNED_MULTIPLIER * getCircle().radius) {
setStatus(GameObjectStatus::WARNED);
return;
}
}

const sf::Texture* ConsumableObject::getTexture(TextureManager& textureManager) const {
switch (getStatus()) {
case GameObjectStatus::NORMAL:
return textureManager.getTexture(GameTextureID::STAR);
case GameObjectStatus::WARNED:
return textureManager.getTexture(GameTextureID::STAR_CONCERNED);
case GameObjectStatus::DESTROYED:
return nullptr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "direction.hpp"

Point2D getDirection(Direction direction) {
switch (direction) {
case North:
return { 0.0f, -1.0f };
case East:
return { 1.0f, 0.0f };
case South:
return { 0.0f, 1.0f };
case West:
return { -1.0f, 0.0f };
default:
return { 0.0f, 0.0f };
}
}
Loading