Add SFML project with Paddle class and miscellaneous utilities
- Introduced `Paddle` class for player controls in the SFML project. - Added `main.cpp` to demonstrate basic paddle movement and rendering. - Created reusable templates (`templates.h`) and inline class (`inlines.h`) in the `misc` module. - Defined `structs`, `enums`, `unions` in `misc/structs_enums_unions.h`. - Updated CMake configuration for the `sfml` and `misc` modules. - Included new assets for backgrounds, characters, enemies, and tiles.
@@ -1 +1 @@
|
|||||||
containers
|
CMakeSFMLProject
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<component name="CMakePythonSetting">
|
<component name="CMakePythonSetting">
|
||||||
<option name="pythonIntegrationState" value="YES" />
|
<option name="pythonIntegrationState" value="YES" />
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/containers">
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/sfml">
|
||||||
<contentRoot DIR="$PROJECT_DIR$" />
|
<contentRoot DIR="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -2,5 +2,17 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/flac-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/freetype-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/ogg-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/sfml-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-debug/_deps/vorbis-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/flac-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/freetype-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/ogg-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/sfml-src" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/sfml/cmake-build-release/_deps/vorbis-src" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,3 +4,6 @@ project(cpp)
|
|||||||
add_subdirectory(intro)
|
add_subdirectory(intro)
|
||||||
add_subdirectory(pointer)
|
add_subdirectory(pointer)
|
||||||
add_subdirectory(classes)
|
add_subdirectory(classes)
|
||||||
|
add_subdirectory(containers)
|
||||||
|
add_subdirectory(misc)
|
||||||
|
add_subdirectory(sfml)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "ClassA.h"
|
#include "ClassA.h"
|
||||||
|
#include <list>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ClassA a;
|
ClassA a;
|
||||||
@@ -25,6 +26,14 @@ int main() {
|
|||||||
|
|
||||||
ClassA a2 = a;
|
ClassA a2 = a;
|
||||||
|
|
||||||
|
std::list<ClassA> l;
|
||||||
|
l.push_back(a);
|
||||||
|
l.push_back(a2);
|
||||||
|
l.push_back(*pA);
|
||||||
|
for (std::list<ClassA>::iterator it = l.begin(); it != l.end(); ++it) {
|
||||||
|
// (*it).Print();
|
||||||
|
it->Print(); // same as line above, but simpler
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
|
||||||
|
typedef std::list<long long> LongLongList;
|
||||||
|
typedef LongLongList::iterator LongLongListIterator;
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
// C array
|
// C array
|
||||||
int numbers[5] = {1, 2, 3, 4, 5}; // stack array
|
int numbers[5] = {1, 2, 3, 4, 5}; // stack array
|
||||||
@@ -35,5 +39,31 @@ int main(int argc, const char* argv[]) {
|
|||||||
|
|
||||||
std::cout << "size of v: " << v.size() << "/" << v.capacity() << std::endl;
|
std::cout << "size of v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||||
|
|
||||||
|
// list
|
||||||
|
std::list<int> l = {1, 2, 3, 4, 5};
|
||||||
|
l.push_front(0);
|
||||||
|
// int n = l[0]; // no random access for list
|
||||||
|
|
||||||
|
std::list<int>::iterator it;
|
||||||
|
for (it = l.begin(); it != l.end(); ++it) {
|
||||||
|
std::cout << *it << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
--it; --it;
|
||||||
|
std::cout << *it << std::endl;
|
||||||
|
l.insert(it, 100);
|
||||||
|
for (it = l.begin(); it != l.end(); ++it) {
|
||||||
|
std::cout << *it << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
--it; --it;
|
||||||
|
l.erase(it);
|
||||||
|
for (it = l.begin(); it != l.end(); ++it) {
|
||||||
|
std::cout << *it << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
LongLongList ll = {1, 2, 3, 4, 5};
|
||||||
|
LongLongListIterator it2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 4.1)
|
||||||
|
project(misc)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_FLAGS -pedantic-errors)
|
||||||
|
|
||||||
|
add_executable(misc
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by David Hackbarth on 27.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MISC_INLINES_H
|
||||||
|
#define MISC_INLINES_H
|
||||||
|
|
||||||
|
class Value {
|
||||||
|
public:
|
||||||
|
Value(int val) : value(val) {} // implicit inline
|
||||||
|
int getValue() const { return value; } // implicit inline
|
||||||
|
private:
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //MISC_INLINES_H
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#include <random>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "templates.h"
|
||||||
|
#include "structs_enums_unions.h"
|
||||||
|
#include "inlines.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int *pI = new int(0);
|
||||||
|
long *pL = new long(0);
|
||||||
|
|
||||||
|
safeDelete<int>(pI);
|
||||||
|
safeDelete(pL);
|
||||||
|
|
||||||
|
Node<int> n1(1);
|
||||||
|
Node<int> n2(2);
|
||||||
|
Node<int> n3(3);
|
||||||
|
|
||||||
|
n1.next = &n2;
|
||||||
|
n2.next = &n3;
|
||||||
|
|
||||||
|
// random
|
||||||
|
std::default_random_engine generator;
|
||||||
|
std::uniform_int_distribution<int> distribution(1, 100);
|
||||||
|
|
||||||
|
std::cout << distribution(generator) << std::endl;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
std::cout << distribution(generator) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enums
|
||||||
|
Weekdays weekday = Weekdays::Monday;
|
||||||
|
std::cout << "Today is " << weekday << std::endl;
|
||||||
|
|
||||||
|
// unions
|
||||||
|
ScreenSize screen_size;
|
||||||
|
screen_size.u.width = 1920;
|
||||||
|
screen_size.u.height = 1080;
|
||||||
|
|
||||||
|
int size = sizeof(screen_size);
|
||||||
|
|
||||||
|
// structs
|
||||||
|
Vector3 v1 = {1.0f, 2.0f, 3.0f};
|
||||||
|
Vector3 v2 = {4.0f, 5.0f, 6.0f};
|
||||||
|
Vector3 v3 = {7.0f, 8.0f, 9.0f};
|
||||||
|
|
||||||
|
bool isEqual = v1 == v2;
|
||||||
|
std::cout << "v1 == v2: " << isEqual << std::endl;
|
||||||
|
std::cout << "v1: " << v1 << std::endl;
|
||||||
|
|
||||||
|
// inline
|
||||||
|
Value v(42);
|
||||||
|
std::cout << "Value: " << v.getValue() << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// Created by David Hackbarth on 27.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MISC_STRUCTS_ENUMS_UNIONS_H
|
||||||
|
#define MISC_STRUCTS_ENUMS_UNIONS_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
struct Vector3 {
|
||||||
|
// public
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
bool operator==(const Vector3 &other) const { return x == other.x && y == other.y && z == other.z; }
|
||||||
|
bool operator!=(const Vector3 &other) const { return !(*this == other); }
|
||||||
|
bool operator<(const Vector3 &other) const { return x < other.x && y < other.y && z < other.z; }
|
||||||
|
bool operator<=(const Vector3 &other) const { return *this < other || *this == other; }
|
||||||
|
bool operator>(const Vector3 &other) const { return !(*this <= other); }
|
||||||
|
bool operator>=(const Vector3 &other) const { return !(*this < other); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// private
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Vector3& v) {
|
||||||
|
os << "(" << v.x << "/" << v.y << "/" << v.z << ")";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Weekdays {
|
||||||
|
Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7,
|
||||||
|
|
||||||
|
FORCE_DWORD = 0x7fffffff // DWORD -> double word -> unsigned 32bit, word -> unsigned 16bit
|
||||||
|
};
|
||||||
|
|
||||||
|
union ScreenSize {
|
||||||
|
unsigned int value; // 32bit
|
||||||
|
struct {
|
||||||
|
unsigned short width; // first 16bit
|
||||||
|
unsigned short height; // second 16bit
|
||||||
|
} u;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
unsigned short width; // first 16bit
|
||||||
|
unsigned short height; // second 16bit
|
||||||
|
} _;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //MISC_STRUCTS_ENUMS_UNIONS_H
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by David Hackbarth on 27.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MISC_TEMPLATES_H
|
||||||
|
#define MISC_TEMPLATES_H
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void safeDelete(T*& pObj)
|
||||||
|
{
|
||||||
|
if (pObj != nullptr)
|
||||||
|
{
|
||||||
|
delete pObj;
|
||||||
|
pObj = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
T data;
|
||||||
|
Node* next;
|
||||||
|
|
||||||
|
Node(T value) : data(value), next(nullptr) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //MISC_TEMPLATES_H
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(CMakeSFMLProject LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(SFML
|
||||||
|
GIT_REPOSITORY https://github.com/SFML/SFML.git
|
||||||
|
GIT_TAG 3.0.2
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
SYSTEM)
|
||||||
|
FetchContent_MakeAvailable(SFML)
|
||||||
|
|
||||||
|
add_executable(main
|
||||||
|
src/main.cpp
|
||||||
|
src/Paddle.cpp
|
||||||
|
)
|
||||||
|
target_compile_features(main PRIVATE cxx_std_17)
|
||||||
|
target_link_libraries(main PRIVATE SFML::Graphics)
|
||||||
|
|
||||||
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT main)
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 6.0 KiB |