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.
This commit is contained in:
2026-02-27 12:16:24 +01:00
parent f5e4caadf3
commit b58064a0d0
881 changed files with 320 additions and 2 deletions
+9
View File
@@ -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
)
+16
View File
@@ -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
+57
View File
@@ -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;
}
+49
View File
@@ -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
+28
View File
@@ -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