commit 7a91913b289d80baf642cbdfe7060e952d1b50f7 Author: lejulien Date: Fri Jan 9 13:20:01 2026 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c26deea --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +build +enc_temp_folder +out +_deps +CMakeSettings.json +.vs +.cache + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9147096 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.21) + +set(NAME skyjo) + +project(${NAME} LANGUAGES CXX) + +include(FetchContent) + +set(ASSET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assets/) + +# Disable sfml audio (This avoids pulling in OpenAL) +set(SFML_BUILD_AUDIO OFF CACHE BOOL "" FORCE) + +FetchContent_Declare( + SFML + GIT_REPOSITORY https://github.com/SFML/SFML.git + GIT_TAG 2.6.1 +) +FetchContent_MakeAvailable(SFML) + +add_executable(${NAME} + sources/main.cpp + sources/CardMaker.cpp +) +target_link_libraries(${NAME} sfml-graphics sfml-window sfml-system) +target_include_directories(${NAME} PUBLIC + ./includes +) + +target_compile_definitions(${NAME} PRIVATE + ASSET_DIR="${ASSET_DIR}" +) + +install(TARGETS ${NAME}) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1668d83 --- /dev/null +++ b/Makefile @@ -0,0 +1,257 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.22 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Disable VCS-based implicit rules. +% : %,v + +# Disable VCS-based implicit rules. +% : RCS/% + +# Disable VCS-based implicit rules. +% : RCS/%,v + +# Disable VCS-based implicit rules. +% : SCCS/s.% + +# Disable VCS-based implicit rules. +% : s.% + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Command-line flag to silence nested $(MAKE). +$(VERBOSE)MAKESILENT = -s + +#Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E rm -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/lju/Documents/game_projects/skyjo + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/lju/Documents/game_projects/skyjo + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# Special rule for the target list_install_components +list_install_components: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" +.PHONY : list_install_components + +# Special rule for the target list_install_components +list_install_components/fast: list_install_components +.PHONY : list_install_components/fast + +# Special rule for the target install +install: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install + +# Special rule for the target install +install/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install/fast + +# Special rule for the target install/local +install/local: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local + +# Special rule for the target install/local +install/local/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local/fast + +# Special rule for the target install/strip +install/strip: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip + +# Special rule for the target install/strip +install/strip/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/lju/Documents/game_projects/skyjo/CMakeFiles /home/lju/Documents/game_projects/skyjo//CMakeFiles/progress.marks + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/lju/Documents/game_projects/skyjo/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named skyjo + +# Build rule for target. +skyjo: cmake_check_build_system + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 skyjo +.PHONY : skyjo + +# fast build rule for target. +skyjo/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/build +.PHONY : skyjo/fast + +sources/CardMaker.o: sources/CardMaker.cpp.o +.PHONY : sources/CardMaker.o + +# target to build an object file +sources/CardMaker.cpp.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/CardMaker.cpp.o +.PHONY : sources/CardMaker.cpp.o + +sources/CardMaker.i: sources/CardMaker.cpp.i +.PHONY : sources/CardMaker.i + +# target to preprocess a source file +sources/CardMaker.cpp.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/CardMaker.cpp.i +.PHONY : sources/CardMaker.cpp.i + +sources/CardMaker.s: sources/CardMaker.cpp.s +.PHONY : sources/CardMaker.s + +# target to generate assembly for a file +sources/CardMaker.cpp.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/CardMaker.cpp.s +.PHONY : sources/CardMaker.cpp.s + +sources/main.o: sources/main.cpp.o +.PHONY : sources/main.o + +# target to build an object file +sources/main.cpp.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/main.cpp.o +.PHONY : sources/main.cpp.o + +sources/main.i: sources/main.cpp.i +.PHONY : sources/main.i + +# target to preprocess a source file +sources/main.cpp.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/main.cpp.i +.PHONY : sources/main.cpp.i + +sources/main.s: sources/main.cpp.s +.PHONY : sources/main.s + +# target to generate assembly for a file +sources/main.cpp.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/skyjo.dir/build.make CMakeFiles/skyjo.dir/sources/main.cpp.s +.PHONY : sources/main.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... install" + @echo "... install/local" + @echo "... install/strip" + @echo "... list_install_components" + @echo "... rebuild_cache" + @echo "... skyjo" + @echo "... sources/CardMaker.o" + @echo "... sources/CardMaker.i" + @echo "... sources/CardMaker.s" + @echo "... sources/main.o" + @echo "... sources/main.i" + @echo "... sources/main.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..8af2558 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,3 @@ + -> Make a cardTextureLoader + -> Make a PlaySpace (with configurable size) + diff --git a/assets/-1.png b/assets/-1.png new file mode 100644 index 0000000..989dc19 Binary files /dev/null and b/assets/-1.png differ diff --git a/assets/-2.png b/assets/-2.png new file mode 100644 index 0000000..765f444 Binary files /dev/null and b/assets/-2.png differ diff --git a/assets/0.png b/assets/0.png new file mode 100644 index 0000000..3c8a7b7 Binary files /dev/null and b/assets/0.png differ diff --git a/assets/1.png b/assets/1.png new file mode 100644 index 0000000..4bfd28b Binary files /dev/null and b/assets/1.png differ diff --git a/assets/10.png b/assets/10.png new file mode 100644 index 0000000..a3dd92e Binary files /dev/null and b/assets/10.png differ diff --git a/assets/11.png b/assets/11.png new file mode 100644 index 0000000..26637c2 Binary files /dev/null and b/assets/11.png differ diff --git a/assets/12.png b/assets/12.png new file mode 100644 index 0000000..dc0ed22 Binary files /dev/null and b/assets/12.png differ diff --git a/assets/2.png b/assets/2.png new file mode 100644 index 0000000..f97c77a Binary files /dev/null and b/assets/2.png differ diff --git a/assets/3.png b/assets/3.png new file mode 100644 index 0000000..167c963 Binary files /dev/null and b/assets/3.png differ diff --git a/assets/4.png b/assets/4.png new file mode 100644 index 0000000..26423d8 Binary files /dev/null and b/assets/4.png differ diff --git a/assets/5.png b/assets/5.png new file mode 100644 index 0000000..3be116a Binary files /dev/null and b/assets/5.png differ diff --git a/assets/6.png b/assets/6.png new file mode 100644 index 0000000..679bd75 Binary files /dev/null and b/assets/6.png differ diff --git a/assets/7.png b/assets/7.png new file mode 100644 index 0000000..f14ab50 Binary files /dev/null and b/assets/7.png differ diff --git a/assets/8.png b/assets/8.png new file mode 100644 index 0000000..5fe5be7 Binary files /dev/null and b/assets/8.png differ diff --git a/assets/9.png b/assets/9.png new file mode 100644 index 0000000..36eb33c Binary files /dev/null and b/assets/9.png differ diff --git a/assets/back.png b/assets/back.png new file mode 100644 index 0000000..f717577 Binary files /dev/null and b/assets/back.png differ diff --git a/assets/skyjo-cards.png b/assets/skyjo-cards.png new file mode 100644 index 0000000..2f49eee Binary files /dev/null and b/assets/skyjo-cards.png differ diff --git a/includes/CardMaker.hpp b/includes/CardMaker.hpp new file mode 100644 index 0000000..49b6d91 --- /dev/null +++ b/includes/CardMaker.hpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +#define CARD_BACK -3 + +#pragma once + +class Card { + private: + int value_; + bool flipped_ = false; + bool grabbed_ = false; + std::shared_ptr back_; + std::shared_ptr face_; + public: + Card(int value, std::shared_ptr face, std::shared_ptr back); + ~Card(); + int getValue(); + std::shared_ptr getSprite(); + void setPosition(sf::Vector2i pos); + void flip(); +}; + +class CardMaker { + private: + std::map> textures_; + public: + CardMaker(); + ~CardMaker(); + std::shared_ptr generate(int value); +}; diff --git a/sources/CardMaker.cpp b/sources/CardMaker.cpp new file mode 100644 index 0000000..50dd2cf --- /dev/null +++ b/sources/CardMaker.cpp @@ -0,0 +1,62 @@ +#include + +/// Card + +Card::Card(int value, std::shared_ptr face, + std::shared_ptr back) + : value_(value), face_(face), back_(back) {} + +Card::~Card() {} + +int Card::getValue() { return value_; } +std::shared_ptr Card::getSprite() { + if (flipped_) + return face_; + return back_; +} + +void Card::setPosition(sf::Vector2i vec) { + if (grabbed_) + face_->setPosition(vec.x - 15, vec.y - 25); +} + +void Card::flip() { + if (!flipped_) + grabbed_ == true; + flipped_ = true; +} + +/// CardMaker + +CardMaker::CardMaker() { + std::string ext(".png"); + std::string folder(ASSET_DIR); + for (int i = -2; i < 13; i++) { + auto tex = std::make_shared(); + std::string name(std::to_string(i)); + if (!tex->loadFromFile(folder + name + ext)) { + std::cerr << "Failed to load " << folder + name + ext << std::endl; + exit(1); + } + textures_[i] = tex; + } + auto tex = std::make_shared(); + + tex->loadFromFile(folder + "back.png"); + textures_[CARD_BACK] = tex; +} + +CardMaker::~CardMaker() {} + +std::shared_ptr CardMaker::generate(int value) { + if (value < -2 || value > 12) { + std::cerr << "Trying to generate oob card nbr " << value << std::endl; + exit(1); + } + auto spr_face = std::make_shared(); + auto spr_back = std::make_shared(); + spr_face->setTexture(*textures_[value]); + spr_back->setTexture(*textures_[CARD_BACK]); + auto card = std::make_shared(value, spr_face, spr_back); + return card; +} diff --git a/sources/main.cpp b/sources/main.cpp new file mode 100644 index 0000000..5ccb3ae --- /dev/null +++ b/sources/main.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include +#include + +#include + +int main() { + sf::RenderWindow win(sf::VideoMode(800, 600), "Skyjo", sf::Style::Default); + CardMaker cm; + auto card = cm.generate(5); + card->flip(); + + win.create(sf::VideoMode(800, 600), "Skyjo"); + while (win.isOpen()) { + sf::Event ev; + + while (win.pollEvent(ev)) { + if (ev.type == sf::Event::Closed) { + win.close(); + } + } + if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) + card->flip(); + // Clear frame buffer + win.clear(sf::Color::Black); + card->setPosition(sf::Mouse::getPosition(win)); + // Draw sprite + win.draw(*card->getSprite()); + + // Draw frame buffer + win.display(); + } + return 0; +}