Initial commit
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
build
|
||||
enc_temp_folder
|
||||
out
|
||||
_deps
|
||||
CMakeSettings.json
|
||||
.vs
|
||||
.cache
|
||||
|
||||
34
CMakeLists.txt
Normal file
@@ -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})
|
||||
257
Makefile
Normal file
@@ -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
|
||||
|
||||
3
TODO.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
-> Make a cardTextureLoader
|
||||
-> Make a PlaySpace (with configurable size)
|
||||
|
||||
BIN
assets/-1.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
assets/-2.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/0.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
assets/1.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
assets/10.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/11.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/12.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/2.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/3.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/4.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/5.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/6.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/7.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/8.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/9.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/back.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/skyjo-cards.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
35
includes/CardMaker.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#define CARD_BACK -3
|
||||
|
||||
#pragma once
|
||||
|
||||
class Card {
|
||||
private:
|
||||
int value_;
|
||||
bool flipped_ = false;
|
||||
bool grabbed_ = false;
|
||||
std::shared_ptr<sf::Sprite> back_;
|
||||
std::shared_ptr<sf::Sprite> face_;
|
||||
public:
|
||||
Card(int value, std::shared_ptr<sf::Sprite> face, std::shared_ptr<sf::Sprite> back);
|
||||
~Card();
|
||||
int getValue();
|
||||
std::shared_ptr<sf::Sprite> getSprite();
|
||||
void setPosition(sf::Vector2i pos);
|
||||
void flip();
|
||||
};
|
||||
|
||||
class CardMaker {
|
||||
private:
|
||||
std::map<int, std::shared_ptr<sf::Texture>> textures_;
|
||||
public:
|
||||
CardMaker();
|
||||
~CardMaker();
|
||||
std::shared_ptr<Card> generate(int value);
|
||||
};
|
||||
62
sources/CardMaker.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <CardMaker.hpp>
|
||||
|
||||
/// Card
|
||||
|
||||
Card::Card(int value, std::shared_ptr<sf::Sprite> face,
|
||||
std::shared_ptr<sf::Sprite> back)
|
||||
: value_(value), face_(face), back_(back) {}
|
||||
|
||||
Card::~Card() {}
|
||||
|
||||
int Card::getValue() { return value_; }
|
||||
std::shared_ptr<sf::Sprite> 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<sf::Texture>();
|
||||
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<sf::Texture>();
|
||||
|
||||
tex->loadFromFile(folder + "back.png");
|
||||
textures_[CARD_BACK] = tex;
|
||||
}
|
||||
|
||||
CardMaker::~CardMaker() {}
|
||||
|
||||
std::shared_ptr<Card> 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<sf::Sprite>();
|
||||
auto spr_back = std::make_shared<sf::Sprite>();
|
||||
spr_face->setTexture(*textures_[value]);
|
||||
spr_back->setTexture(*textures_[CARD_BACK]);
|
||||
auto card = std::make_shared<Card>(value, spr_face, spr_back);
|
||||
return card;
|
||||
}
|
||||
36
sources/main.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <CardMaker.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||