Zad3 - start
This commit is contained in:
parent
65e2f937a4
commit
86de1db6cb
@ -1,6 +1,6 @@
|
|||||||
IDE: Microsoft Visual Studio 2019
|
IDE: Microsoft Visual Studio 2022
|
||||||
Kompilator: Microsoft Visual C++
|
Kompilator: Microsoft Visual C++
|
||||||
Biblioteki: SDL2
|
Biblioteki: SDL2, SDL2_ttf, nlohmann-json
|
||||||
|
|
||||||
Przetestowane pady: DualSense, DualShock 3 (ze sterownikiem/wrapperem XInputowym ScpToolkit), telefon Android (ze sterownikiem/wrapperem XInputowym HandyGamePad).
|
Przetestowane pady: DualSense, DualShock 3 (ze sterownikiem/wrapperem XInputowym ScpToolkit), telefon Android (ze sterownikiem/wrapperem XInputowym HandyGamePad).
|
||||||
|
|
||||||
|
31
2dgk_zad3/2dgk_zad3.sln
Normal file
31
2dgk_zad3/2dgk_zad3.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.31729.503
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{423520C9-0301-4445-99D4-078B2842C600}") = "2dgk_zad3", "2dgk_zad3\2dgk_zad3.vcxproj", "{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Release|x64.Build.0 = Release|x64
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{710B7A8E-21B0-4956-9B5B-F92A42AF86EA}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {F6AE8D48-1DC7-43D1-9855-F4AD626525B1}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
101
2dgk_zad3/2dgk_zad3/2dgk_zad3.rc
Normal file
101
2dgk_zad3/2dgk_zad3/2dgk_zad3.rc
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// Microsoft Visual C++ generated resource script.
|
||||||
|
//
|
||||||
|
#pragma code_page(65001)
|
||||||
|
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
|
//
|
||||||
|
#include "winres.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Polish (Poland) resources
|
||||||
|
|
||||||
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK)
|
||||||
|
LANGUAGE LANG_POLISH, SUBLANG_DEFAULT
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// TEXTINCLUDE
|
||||||
|
//
|
||||||
|
|
||||||
|
1 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"resource.h\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
2 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"#include ""winres.h""\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
3 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Version
|
||||||
|
//
|
||||||
|
|
||||||
|
VS_VERSION_INFO VERSIONINFO
|
||||||
|
FILEVERSION 1,0,0,1
|
||||||
|
PRODUCTVERSION 1,0,0,1
|
||||||
|
FILEFLAGSMASK 0x3fL
|
||||||
|
#ifdef _DEBUG
|
||||||
|
FILEFLAGS 0x1L
|
||||||
|
#else
|
||||||
|
FILEFLAGS 0x0L
|
||||||
|
#endif
|
||||||
|
FILEOS 0x40004L
|
||||||
|
FILETYPE 0x1L
|
||||||
|
FILESUBTYPE 0x0L
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "041504b0"
|
||||||
|
BEGIN
|
||||||
|
VALUE "CompanyName", "Michał Leśniak"
|
||||||
|
VALUE "FileDescription", "A simple game"
|
||||||
|
VALUE "FileVersion", "1.0.0.1"
|
||||||
|
VALUE "InternalName", "2dgk_zad3.exe"
|
||||||
|
VALUE "LegalCopyright", "Copyright (C) 2021 Michał Leśniak"
|
||||||
|
VALUE "OriginalFilename", "2dgk_zad3.exe"
|
||||||
|
VALUE "ProductName", "2DKG_ZAD3"
|
||||||
|
VALUE "ProductVersion", "1.0.0.1"
|
||||||
|
END
|
||||||
|
END
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Translation", 0x415, 1200
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // Polish (Poland) resources
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif // not APSTUDIO_INVOKED
|
||||||
|
|
250
2dgk_zad3/2dgk_zad3/2dgk_zad3.vcxproj
Normal file
250
2dgk_zad3/2dgk_zad3/2dgk_zad3.vcxproj
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{710b7a8e-21b0-4956-9b5b-f92a42af86ea}</ProjectGuid>
|
||||||
|
<RootNamespace>My2dgk_zad3</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Label="Vcpkg">
|
||||||
|
<VcpkgEnableManifest>true</VcpkgEnableManifest>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>vcpkg_installed\x86-windows\x86-windows\include\SDL2</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>vcpkg_installed\x86-windows\x86-windows\debug\lib\manual-link;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>SDL2maind.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>vcpkg_installed\x86-windows\x86-windows\include\SDL2</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>vcpkg_installed\x86-windows\x86-windows\lib\manual-link;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>vcpkg_installed\x64-windows\x64-windows\include\SDL2</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>vcpkg_installed\x64-windows\x64-windows\debug\lib\manual-link;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>SDL2maind.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>vcpkg_installed\x64-windows\x64-windows\include\SDL2</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>vcpkg_installed\x64-windows\x64-windows\lib\manual-link;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="KCamera.cpp" />
|
||||||
|
<ClCompile Include="KCircle.cpp" />
|
||||||
|
<ClCompile Include="KCirclePawn.cpp" />
|
||||||
|
<ClCompile Include="KExit.cpp" />
|
||||||
|
<ClCompile Include="KFont.cpp" />
|
||||||
|
<ClCompile Include="KGame.cpp" />
|
||||||
|
<ClCompile Include="KInput.cpp" />
|
||||||
|
<ClCompile Include="KObject.cpp" />
|
||||||
|
<ClCompile Include="KPawn.cpp" />
|
||||||
|
<ClCompile Include="KPlayerController.cpp" />
|
||||||
|
<ClCompile Include="KRect.cpp" />
|
||||||
|
<ClCompile Include="KCollider.cpp" />
|
||||||
|
<ClCompile Include="KRectPawn.cpp" />
|
||||||
|
<ClCompile Include="KTexture.cpp" />
|
||||||
|
<ClCompile Include="KWall.cpp" />
|
||||||
|
<ClCompile Include="Main.cpp" />
|
||||||
|
<ClCompile Include="Utils.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="config.json">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</None>
|
||||||
|
<None Include="vcpkg.json" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Constants.h" />
|
||||||
|
<ClInclude Include="Controllers.h" />
|
||||||
|
<ClInclude Include="GamePad.h" />
|
||||||
|
<ClInclude Include="KActionBind.h" />
|
||||||
|
<ClInclude Include="KCamera.h" />
|
||||||
|
<ClInclude Include="KCircle.h" />
|
||||||
|
<ClInclude Include="KCirclePawn.h" />
|
||||||
|
<ClInclude Include="KExit.h" />
|
||||||
|
<ClInclude Include="KFont.h" />
|
||||||
|
<ClInclude Include="KGame.h" />
|
||||||
|
<ClInclude Include="KInput.h" />
|
||||||
|
<ClInclude Include="KObject.h" />
|
||||||
|
<ClInclude Include="KPawn.h" />
|
||||||
|
<ClInclude Include="KPlayer.h" />
|
||||||
|
<ClInclude Include="KPlayerController.h" />
|
||||||
|
<ClInclude Include="KRect.h" />
|
||||||
|
<ClInclude Include="KCollider.h" />
|
||||||
|
<ClInclude Include="KRectPawn.h" />
|
||||||
|
<ClInclude Include="KTexture.h" />
|
||||||
|
<ClInclude Include="KWall.h" />
|
||||||
|
<ClInclude Include="resource.h" />
|
||||||
|
<ClInclude Include="Utils.h" />
|
||||||
|
<ClInclude Include="KVector2d.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="2dgk_zad3.rc" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="assets\fonts\LICENSE.txt">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Text>
|
||||||
|
<Text Include="assets\levels\level1.txt">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Text>
|
||||||
|
<Text Include="assets\levels\level2.txt">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Text>
|
||||||
|
<Text Include="assets\levels\level3.txt">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Text>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Font Include="assets\fonts\Roboto-Thin.ttf">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Font>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Image Include="assets\textures\arrow.bmp">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Image>
|
||||||
|
<Image Include="assets\textures\exit.bmp">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Image>
|
||||||
|
<Image Include="assets\textures\P1.bmp">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Image>
|
||||||
|
<Image Include="assets\textures\P2.bmp">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Image>
|
||||||
|
<Image Include="assets\textures\wall.bmp">
|
||||||
|
<DeploymentContent>true</DeploymentContent>
|
||||||
|
</Image>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
149
2dgk_zad3/2dgk_zad3/2dgk_zad3.vcxproj.filters
Normal file
149
2dgk_zad3/2dgk_zad3/2dgk_zad3.vcxproj.filters
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Main.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KTexture.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KGame.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KInput.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KCircle.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Utils.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KPlayerController.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KCollider.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KRect.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KObject.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KPawn.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KWall.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KRectPawn.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KCirclePawn.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KExit.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KCamera.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="KFont.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="vcpkg.json" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Utils.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Constants.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KVector2d.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KTexture.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KGame.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="GamePad.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KInput.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KCircle.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KPlayerController.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KCollider.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KRect.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KActionBind.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Controllers.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KPlayer.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KObject.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KPawn.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KWall.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KRectPawn.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KCirclePawn.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KExit.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KCamera.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="KFont.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="resource.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="2dgk_zad3.rc">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</ResourceCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
20
2dgk_zad3/2dgk_zad3/Constants.h
Normal file
20
2dgk_zad3/2dgk_zad3/Constants.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
namespace KapitanGame {
|
||||||
|
namespace Constants {
|
||||||
|
constexpr const char* WINDOW_TITLE = "2DGK - Zadanie 2 (Lab 7-8)";
|
||||||
|
//Analog joystick dead zone
|
||||||
|
constexpr int JOYSTICK_DEAD_ZONE = 8000;
|
||||||
|
//Screen dimension constants
|
||||||
|
constexpr int WINDOW_DEAD_ZONE = 100;
|
||||||
|
constexpr int SCREEN_WIDTH = 640;
|
||||||
|
constexpr int SCREEN_HEIGHT = 480;
|
||||||
|
constexpr float SCREEN_RATIO = static_cast<float>(SCREEN_WIDTH) / SCREEN_HEIGHT;
|
||||||
|
constexpr int TILE_WIDTH = 32;
|
||||||
|
constexpr int TILE_HEIGHT = 32;
|
||||||
|
constexpr float SPEED = 200.f;
|
||||||
|
constexpr float SMOOTH = 0.4f;
|
||||||
|
constexpr float JUMP_SPEED = 200.f;
|
||||||
|
constexpr float JUMP_SHORT_SPEED = 100.f;
|
||||||
|
constexpr float GRAVITY = 200.f;
|
||||||
|
}
|
||||||
|
}
|
9
2dgk_zad3/2dgk_zad3/Controllers.h
Normal file
9
2dgk_zad3/2dgk_zad3/Controllers.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
namespace KapitanGame {
|
||||||
|
enum class Controllers : int {
|
||||||
|
Controller1,
|
||||||
|
Controller2,
|
||||||
|
Controller3,
|
||||||
|
Controller4
|
||||||
|
};
|
||||||
|
}
|
8
2dgk_zad3/2dgk_zad3/GamePad.h
Normal file
8
2dgk_zad3/2dgk_zad3/GamePad.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_gamecontroller.h>
|
||||||
|
namespace KapitanGame {
|
||||||
|
struct GamePad {
|
||||||
|
bool Buttons[SDL_CONTROLLER_BUTTON_MAX];
|
||||||
|
int Axis[SDL_CONTROLLER_AXIS_MAX];
|
||||||
|
};
|
||||||
|
}
|
31
2dgk_zad3/2dgk_zad3/KActionBind.h
Normal file
31
2dgk_zad3/2dgk_zad3/KActionBind.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KPlayer.h"
|
||||||
|
#include "KPlayerController.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
;
|
||||||
|
enum class InputState : int {
|
||||||
|
Pressed,
|
||||||
|
Released,
|
||||||
|
Hold
|
||||||
|
};
|
||||||
|
struct KActionBind {
|
||||||
|
KActionBind(std::string name, const InputState expectedInputState, const std::shared_ptr<KPlayerController>& controllerObject, const KPlayerCommand command, const KPlayer player) :
|
||||||
|
Name(std::move(name)), ExpectedInputState(expectedInputState), ControllerObject(controllerObject), Command(command), Player(player) {}
|
||||||
|
std::string Name;
|
||||||
|
InputState ExpectedInputState;
|
||||||
|
std::weak_ptr<KPlayerController> ControllerObject;
|
||||||
|
KPlayerCommand Command;
|
||||||
|
KPlayer Player;
|
||||||
|
};
|
||||||
|
struct KAxisBind
|
||||||
|
{
|
||||||
|
KAxisBind(std::string name, const std::shared_ptr<KPlayerController>& controllerObject, const KPlayerAxisCommand command, const KPlayer player) :
|
||||||
|
Name(std::move(name)), ControllerObject(controllerObject), AxisCommand(command), Player(player) {}
|
||||||
|
std::string Name;
|
||||||
|
std::weak_ptr<KPlayerController> ControllerObject;
|
||||||
|
KPlayerAxisCommand AxisCommand;
|
||||||
|
KPlayer Player;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
46
2dgk_zad3/2dgk_zad3/KCamera.cpp
Normal file
46
2dgk_zad3/2dgk_zad3/KCamera.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "KCamera.h"
|
||||||
|
|
||||||
|
#include "KPawn.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
const SDL_FRect& KCamera::GetViewport() const
|
||||||
|
{
|
||||||
|
return Viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KCamera::GetScale() const
|
||||||
|
{
|
||||||
|
return Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
const KVector2D& KCamera::GetFocusPoint() const
|
||||||
|
{
|
||||||
|
return FocusPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KCamera::Update(const std::vector<std::shared_ptr<KPawn>>& pawns, const SDL_FRect& map)
|
||||||
|
{
|
||||||
|
FocusPoint = { 0.f,0.f };
|
||||||
|
for(const auto& pawn : pawns) {
|
||||||
|
FocusPoint += pawn->GetPosition();
|
||||||
|
}
|
||||||
|
FocusPoint *= 1.f / static_cast<float>(pawns.size());
|
||||||
|
Viewport.x = Utils::Clamp(FocusPoint.X - Viewport.w / 2.f, 0.f, map.w - Viewport.w);
|
||||||
|
Viewport.y = Utils::Clamp(FocusPoint.Y - Viewport.h / 2.f, 0.f, map.h - Viewport.h);
|
||||||
|
PlayArea.x = Utils::Clamp(FocusPoint.X - PlayArea.w / 2.f, static_cast<float>(-Constants::WINDOW_DEAD_ZONE), map.w + static_cast<float>(Constants::WINDOW_DEAD_ZONE));
|
||||||
|
PlayArea.y = Utils::Clamp(FocusPoint.Y - PlayArea.h / 2.f, static_cast<float>(-Constants::WINDOW_DEAD_ZONE), map.h + static_cast<float>(Constants::WINDOW_DEAD_ZONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KCamera::SetDebug(const SDL_FRect& map)
|
||||||
|
{
|
||||||
|
Viewport = { 0,0,Constants::SCREEN_WIDTH, Constants::SCREEN_HEIGHT };
|
||||||
|
Scale = Constants::SCREEN_RATIO > 1.f ? Constants::SCREEN_HEIGHT * 1.f / map.h : Constants::SCREEN_WIDTH * 1.f / map.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_FRect& KCamera::GetPlayArea() const
|
||||||
|
{
|
||||||
|
return PlayArea;
|
||||||
|
}
|
||||||
|
}
|
43
2dgk_zad3/2dgk_zad3/KCamera.h
Normal file
43
2dgk_zad3/2dgk_zad3/KCamera.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KPawn;
|
||||||
|
|
||||||
|
class KCamera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit KCamera(const SDL_FRect& map)
|
||||||
|
: Viewport({
|
||||||
|
(map.w - Constants::SCREEN_WIDTH) / 2.f, (map.h - Constants::SCREEN_HEIGHT) / 2.f,
|
||||||
|
Constants::SCREEN_WIDTH * 1.f,
|
||||||
|
Constants::SCREEN_HEIGHT * 1.f
|
||||||
|
}), PlayArea({
|
||||||
|
0, 0,
|
||||||
|
Constants::SCREEN_WIDTH - Constants::WINDOW_DEAD_ZONE,
|
||||||
|
Constants::SCREEN_HEIGHT - Constants::WINDOW_DEAD_ZONE
|
||||||
|
}), FocusPoint(Viewport.x + Viewport.w / 2, Viewport.y + Viewport.h / 2),
|
||||||
|
Scale(1.f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_FRect& GetViewport() const;
|
||||||
|
float GetScale() const;
|
||||||
|
const KVector2D& GetFocusPoint() const;
|
||||||
|
void Update(const std::vector<std::shared_ptr<KPawn>>& pawns, const SDL_FRect& map);
|
||||||
|
void SetDebug(const SDL_FRect& map);
|
||||||
|
const SDL_FRect& GetPlayArea() const;
|
||||||
|
private:
|
||||||
|
SDL_FRect Viewport;
|
||||||
|
SDL_FRect PlayArea;
|
||||||
|
KVector2D FocusPoint;
|
||||||
|
float Scale;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
111
2dgk_zad3/2dgk_zad3/KCircle.cpp
Normal file
111
2dgk_zad3/2dgk_zad3/KCircle.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#include "KCircle.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "KRect.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
|
||||||
|
bool KCircle::IsCollision(const KCircle* other) const {
|
||||||
|
return (GetParent()->GetPosition() - other->GetParent()->GetPosition()).Length() < Radius + other->Radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KCircle::IsCollision(const KCollider* other) const
|
||||||
|
{
|
||||||
|
const auto circle = dynamic_cast<const KCircle*>(other);
|
||||||
|
if (circle != nullptr)
|
||||||
|
return IsCollision(circle);
|
||||||
|
|
||||||
|
|
||||||
|
const auto rect = dynamic_cast<const KRect*>(other);
|
||||||
|
if (rect != nullptr)
|
||||||
|
return IsCollision(rect);
|
||||||
|
|
||||||
|
throw std::runtime_error("unsupported shape");
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KCircle::GetSeparationVector(const KCollider* other) const
|
||||||
|
{
|
||||||
|
const auto circle = dynamic_cast<const KCircle*>(other);
|
||||||
|
if (circle != nullptr)
|
||||||
|
return GetSeparationVector(circle);
|
||||||
|
|
||||||
|
const auto rect = dynamic_cast<const KRect*>(other);
|
||||||
|
if (rect != nullptr)
|
||||||
|
return GetSeparationVector(rect);
|
||||||
|
|
||||||
|
throw std::runtime_error("unsupported shape");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KCircle::IsCollision(const KRect* other) const {
|
||||||
|
const auto f = KVector2D(Utils::Clamp(GetParent()->GetPosition().X, other->GetParent()->GetPosition().X - other->GetWidth() / 2, other->GetParent()->GetPosition().X + other->GetWidth() / 2),
|
||||||
|
Utils::Clamp(GetParent()->GetPosition().Y, other->GetParent()->GetPosition().Y - other->GetHeight() / 2, other->GetParent()->GetPosition().Y + other->GetHeight() / 2));
|
||||||
|
|
||||||
|
return (GetParent()->GetPosition() - f).Length() < Radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KCircle::GetSeparationVector(const KCircle* other) const {
|
||||||
|
const KVector2D centerDiff = GetParent()->GetPosition() - other->GetParent()->GetPosition();
|
||||||
|
const float centerDiffLength = centerDiff.Length();
|
||||||
|
return centerDiff / centerDiffLength * (Radius + other->Radius - centerDiffLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KCircle::GetSeparationVector(const KRect* other) const {
|
||||||
|
const float l = other->GetParent()->GetPosition().X - other->GetWidth() / 2;
|
||||||
|
const float r = other->GetParent()->GetPosition().X + other->GetWidth() / 2;
|
||||||
|
const float t = other->GetParent()->GetPosition().Y - other->GetHeight() / 2;
|
||||||
|
const float b = other->GetParent()->GetPosition().Y + other->GetHeight() / 2;
|
||||||
|
const auto f = KVector2D(Utils::Clamp(GetParent()->GetPosition().X, l, r),
|
||||||
|
Utils::Clamp(GetParent()->GetPosition().Y, t, b));
|
||||||
|
|
||||||
|
if (GetParent()->GetPosition() == f) {
|
||||||
|
const auto left = GetParent()->GetPosition().X - l + Radius;
|
||||||
|
const auto right = r - GetParent()->GetPosition().X + Radius;
|
||||||
|
const auto top = GetParent()->GetPosition().Y - t + Radius;
|
||||||
|
const auto bottom = b - GetParent()->GetPosition().Y + Radius;
|
||||||
|
return KRect::GetSeparationVector(left, right, top, bottom);
|
||||||
|
}
|
||||||
|
return (GetParent()->GetPosition() - f) / (GetParent()->GetPosition() - f).Length() * (Radius - (GetParent()->GetPosition() - f).Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KCircle::GetSeparationVector(const SDL_FRect& map) const {
|
||||||
|
KVector2D separationVector{ 0.f,0.f };
|
||||||
|
if (GetParent()->GetPosition().X - map.x - Radius < 0)
|
||||||
|
{
|
||||||
|
separationVector.X += -(GetParent()->GetPosition().X - map.x - Radius);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().X + Radius - (map.x + map.w) > 0)
|
||||||
|
{
|
||||||
|
separationVector.X += -(GetParent()->GetPosition().X - (map.x+map.w) + Radius);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().Y - Radius - map.y < 0) {
|
||||||
|
separationVector.Y += -(GetParent()->GetPosition().Y - map.y - Radius);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().Y + Radius - (map.y + map.h) > 0) {
|
||||||
|
separationVector.Y += -(GetParent()->GetPosition().Y - (map.y + map.h) + Radius);
|
||||||
|
}
|
||||||
|
return separationVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KCircle::GetWidth() const
|
||||||
|
{
|
||||||
|
return Radius * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KCircle::GetHeight() const
|
||||||
|
{
|
||||||
|
return Radius * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
KCircle::KCircle(KObject* parent, const float radius): KCollider(parent),
|
||||||
|
Radius(radius)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float KCircle::GetRadius() const {
|
||||||
|
return Radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
32
2dgk_zad3/2dgk_zad3/KCircle.h
Normal file
32
2dgk_zad3/2dgk_zad3/KCircle.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
|
||||||
|
#include "KCollider.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
class KRect;
|
||||||
|
|
||||||
|
class KCircle final : public KCollider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KCircle(KObject* parent, const float radius);
|
||||||
|
float GetRadius() const;
|
||||||
|
private:
|
||||||
|
KVector2D GetSeparationVector(const KCircle* other) const;
|
||||||
|
KVector2D GetSeparationVector(const KRect* other) const;
|
||||||
|
bool IsCollision(const KCircle* other) const;
|
||||||
|
bool IsCollision(const KRect* other) const;
|
||||||
|
public:
|
||||||
|
bool IsCollision(const KCollider* other) const override;
|
||||||
|
KVector2D GetSeparationVector(const KCollider* other) const override;
|
||||||
|
KVector2D GetSeparationVector(const SDL_FRect& map) const override;
|
||||||
|
float GetWidth() const override;
|
||||||
|
float GetHeight() const override;
|
||||||
|
private:
|
||||||
|
float Radius{ 1.f };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
2dgk_zad3/2dgk_zad3/KCirclePawn.cpp
Normal file
15
2dgk_zad3/2dgk_zad3/KCirclePawn.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "KCirclePawn.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
KCirclePawn::KCirclePawn(const KVector2D& position, const KTexture& texture,
|
||||||
|
const std::shared_ptr<KPlayerController>& playerController) : KPawn(position, texture, playerController),
|
||||||
|
Collider(this, static_cast<float>(texture.GetWidth())/2.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const KCollider* KCirclePawn::GetCollider() const
|
||||||
|
{
|
||||||
|
return &Collider;
|
||||||
|
}
|
||||||
|
}
|
18
2dgk_zad3/2dgk_zad3/KCirclePawn.h
Normal file
18
2dgk_zad3/2dgk_zad3/KCirclePawn.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KCircle.h"
|
||||||
|
#include "KPawn.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KCirclePawn final :public KPawn
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KCirclePawn(const KVector2D& position, const KTexture& texture,
|
||||||
|
const std::shared_ptr<KPlayerController>& playerController);
|
||||||
|
|
||||||
|
const KCollider* GetCollider() const override;
|
||||||
|
private:
|
||||||
|
KCircle Collider;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
34
2dgk_zad3/2dgk_zad3/KCollider.cpp
Normal file
34
2dgk_zad3/2dgk_zad3/KCollider.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "KCollider.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
KCollider::KCollider(const KCollider& other) = default;
|
||||||
|
|
||||||
|
KCollider::KCollider(KCollider&& other) noexcept: Parent(other.Parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KCollider& KCollider::operator=(const KCollider& other)
|
||||||
|
{
|
||||||
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
Parent = other.Parent;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
KCollider& KCollider::operator=(KCollider&& other) noexcept
|
||||||
|
{
|
||||||
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
Parent = other.Parent;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
KCollider::KCollider(KObject* parent): Parent(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KObject* KCollider::GetParent() const
|
||||||
|
{
|
||||||
|
return Parent;
|
||||||
|
}
|
||||||
|
}
|
35
2dgk_zad3/2dgk_zad3/KCollider.h
Normal file
35
2dgk_zad3/2dgk_zad3/KCollider.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
|
||||||
|
#include "KObject.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
|
||||||
|
class KCollider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KCollider(const KCollider& other);
|
||||||
|
|
||||||
|
KCollider(KCollider&& other) noexcept;
|
||||||
|
|
||||||
|
KCollider& operator=(const KCollider& other);
|
||||||
|
|
||||||
|
KCollider& operator=(KCollider&& other) noexcept;
|
||||||
|
|
||||||
|
explicit KCollider(KObject* parent);
|
||||||
|
|
||||||
|
virtual ~KCollider() = default;
|
||||||
|
virtual bool IsCollision(const KCollider* other) const = 0;
|
||||||
|
virtual KVector2D GetSeparationVector(const KCollider* other) const = 0;
|
||||||
|
virtual KVector2D GetSeparationVector(const SDL_FRect& map) const = 0;
|
||||||
|
virtual float GetWidth() const = 0;
|
||||||
|
virtual float GetHeight() const = 0;
|
||||||
|
KObject* GetParent() const;
|
||||||
|
private:
|
||||||
|
KObject* Parent;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
9
2dgk_zad3/2dgk_zad3/KExit.cpp
Normal file
9
2dgk_zad3/2dgk_zad3/KExit.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "KExit.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
const KCollider* KExit::GetCollider() const
|
||||||
|
{
|
||||||
|
return &Collider;
|
||||||
|
}
|
||||||
|
}
|
22
2dgk_zad3/2dgk_zad3/KExit.h
Normal file
22
2dgk_zad3/2dgk_zad3/KExit.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KObject.h"
|
||||||
|
#include "KRect.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KExit final :
|
||||||
|
public KObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KExit(const KVector2D& position, const KTexture& texture)
|
||||||
|
: KObject(position, texture),
|
||||||
|
Collider(this, texture.GetWidth() * 1.f, texture.GetHeight() * 1.f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const KCollider* GetCollider() const override;
|
||||||
|
private:
|
||||||
|
KRect Collider;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
97
2dgk_zad3/2dgk_zad3/KFont.cpp
Normal file
97
2dgk_zad3/2dgk_zad3/KFont.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#include "KFont.h"
|
||||||
|
|
||||||
|
#include "KTexture.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
KFont::KFont()
|
||||||
|
= default;
|
||||||
|
|
||||||
|
KFont::~KFont()
|
||||||
|
{
|
||||||
|
Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
KFont::KFont(KFont&& other) noexcept : Font(other.Font)
|
||||||
|
{
|
||||||
|
other.Font = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
KFont& KFont::operator=(KFont&& other) noexcept
|
||||||
|
{
|
||||||
|
Font = other.Font;
|
||||||
|
other.Font = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KFont::LoadFromFile(const std::string& path, const int ptSize)
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
Font = TTF_OpenFont(path.c_str(), ptSize);
|
||||||
|
if (Font == nullptr)
|
||||||
|
{
|
||||||
|
printf("Failed to load %s font! SDL_ttf Error: %s\n", path.c_str(), TTF_GetError());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KFont::Free()
|
||||||
|
{
|
||||||
|
if (Font != nullptr)
|
||||||
|
{
|
||||||
|
TTF_CloseFont(Font);
|
||||||
|
Font = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KTexture KFont::GetTextTexture(const std::string& text, const SDL_Color textColor, SDL_Renderer* renderer) const
|
||||||
|
{
|
||||||
|
KTexture texture;
|
||||||
|
SDL_Surface* textSurface = TTF_RenderText_Blended(Font, text.c_str(), textColor);
|
||||||
|
if (textSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
texture.LoadFromSurface(textSurface, renderer);
|
||||||
|
SDL_FreeSurface(textSurface);
|
||||||
|
}
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
KTexture KFont::GetTextWithOutlineTexture(const std::string& text, const SDL_Color fgColor, const SDL_Color bgColor,
|
||||||
|
const int outlineSize, SDL_Renderer* renderer) const
|
||||||
|
{
|
||||||
|
KTexture texture;
|
||||||
|
const int originalOutlineSize = TTF_GetFontOutline(Font);
|
||||||
|
|
||||||
|
if (SDL_Surface* fgSurface = TTF_RenderText_Blended(Font, text.c_str(), fgColor); fgSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TTF_SetFontOutline(Font, outlineSize);
|
||||||
|
SDL_Surface* bgSurface = TTF_RenderText_Blended(Font, text.c_str(), bgColor);
|
||||||
|
TTF_SetFontOutline(Font, originalOutlineSize);
|
||||||
|
if (bgSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_Rect rect = { outlineSize, outlineSize, fgSurface->w, fgSurface->h };
|
||||||
|
|
||||||
|
/* blit text onto its outline */
|
||||||
|
SDL_SetSurfaceBlendMode(fgSurface, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_BlitSurface(fgSurface, nullptr, bgSurface, &rect);
|
||||||
|
texture.LoadFromSurface(bgSurface, renderer);
|
||||||
|
SDL_FreeSurface(bgSurface);
|
||||||
|
}
|
||||||
|
SDL_FreeSurface(fgSurface);
|
||||||
|
}
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
}
|
37
2dgk_zad3/2dgk_zad3/KFont.h
Normal file
37
2dgk_zad3/2dgk_zad3/KFont.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
//Font wrapper class
|
||||||
|
class KTexture;
|
||||||
|
class KFont {
|
||||||
|
public:
|
||||||
|
KFont();
|
||||||
|
|
||||||
|
~KFont();
|
||||||
|
|
||||||
|
KFont(const KFont& other) = delete;
|
||||||
|
|
||||||
|
KFont(KFont&& other) noexcept;
|
||||||
|
|
||||||
|
KFont& operator=(const KFont& other) = delete;
|
||||||
|
|
||||||
|
KFont& operator=(KFont&& other) noexcept;
|
||||||
|
|
||||||
|
//Loads image at specified path
|
||||||
|
bool LoadFromFile(const std::string& path, int ptSize);
|
||||||
|
|
||||||
|
//Deallocates Font
|
||||||
|
void Free();
|
||||||
|
|
||||||
|
KTexture GetTextTexture(const std::string& text, SDL_Color textColor, SDL_Renderer* renderer) const;
|
||||||
|
KTexture GetTextWithOutlineTexture(const std::string& text, SDL_Color fgColor, SDL_Color bgColor, int outlineSize, SDL_Renderer* renderer) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//The actual hardware font
|
||||||
|
TTF_Font* Font{};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
362
2dgk_zad3/2dgk_zad3/KGame.cpp
Normal file
362
2dgk_zad3/2dgk_zad3/KGame.cpp
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
#include "KGame.h"
|
||||||
|
#include "SDL.h"
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "KCamera.h"
|
||||||
|
#include "KCirclePawn.h"
|
||||||
|
#include "KExit.h"
|
||||||
|
#include "KRectPawn.h"
|
||||||
|
#include "KTexture.h"
|
||||||
|
#include "KTile.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
#include "KWall.h"
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
KGame::KGame() : Time(0), PreviousTime(0), Map()
|
||||||
|
{
|
||||||
|
//Initialize SDL
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(Utils::StringFormat("SDL could not initialize! SDL_Error: %s", SDL_GetError()));
|
||||||
|
}
|
||||||
|
//Set texture filtering to linear
|
||||||
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
|
||||||
|
{
|
||||||
|
printf("Warning: Linear texture filtering not enabled!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Input.Init();
|
||||||
|
|
||||||
|
if (TTF_Init() < 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(Utils::StringFormat("SDL_TTF could not initialize! TTF_Error: %s", TTF_GetError()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create window
|
||||||
|
Window = SDL_CreateWindow(Constants::WINDOW_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
Constants::SCREEN_WIDTH, Constants::SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||||
|
if (Window == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(Utils::StringFormat("Window could not be created! SDL_Error: %s", SDL_GetError()));
|
||||||
|
}
|
||||||
|
//Create renderer for window
|
||||||
|
Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
if (Renderer == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
Utils::StringFormat("Renderer could not be created! SDL Error: %s", SDL_GetError()));
|
||||||
|
}
|
||||||
|
//Initialize renderer color
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 0, 0xFF, 0, 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
KGame::~KGame() {
|
||||||
|
//Free loaded images
|
||||||
|
Textures.clear();
|
||||||
|
Objects.clear();
|
||||||
|
Pawns.clear();
|
||||||
|
PlayerControllers.clear();
|
||||||
|
Fonts.clear();
|
||||||
|
TTF_Quit();
|
||||||
|
Input.Free();
|
||||||
|
|
||||||
|
//Destroy window
|
||||||
|
SDL_DestroyRenderer(Renderer);
|
||||||
|
SDL_DestroyWindow(Window);
|
||||||
|
Window = nullptr;
|
||||||
|
Renderer = nullptr;
|
||||||
|
|
||||||
|
//Quit SDL subsystems
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KGame::LoadLevel()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
Objects.clear();
|
||||||
|
FreePositions.clear();
|
||||||
|
/*std::ifstream levelFile;
|
||||||
|
levelFile.open("assets/levels/level" + std::to_string(LvlCounter) + ".txt");
|
||||||
|
if (levelFile.fail())
|
||||||
|
{
|
||||||
|
printf("Failed to load assets/levels/level%d.txt!\n", LvlCounter);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int y = 0;
|
||||||
|
float mapWidth = 0;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(levelFile, line)) {
|
||||||
|
if (mapWidth < static_cast<float>(line.length() * Constants::TILE_WIDTH))
|
||||||
|
mapWidth = static_cast<float>(line.length()) * Constants::TILE_WIDTH;
|
||||||
|
for (auto i = 0ull; i < line.length(); ++i) {
|
||||||
|
KVector2D position{ static_cast<float>(i * Constants::TILE_WIDTH + Constants::TILE_WIDTH / 2) , static_cast<float>(y * Constants::TILE_HEIGHT + Constants::TILE_HEIGHT / 2) };
|
||||||
|
switch (line[i])
|
||||||
|
{
|
||||||
|
case '#':
|
||||||
|
Objects.emplace(std::make_pair(static_cast<int>(i), y), std::make_shared<KWall>(position, Textures["wall.bmp"]));
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
FreePositions.emplace_back(position);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++y;
|
||||||
|
}
|
||||||
|
const auto mapHeight = static_cast<float>(y * Constants::TILE_HEIGHT);
|
||||||
|
levelFile.close();
|
||||||
|
Map = { 0,0,mapWidth,mapHeight };
|
||||||
|
}*/
|
||||||
|
Map = { 0,0,Constants::SCREEN_WIDTH,Constants::SCREEN_HEIGHT };
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KGame::LoadPlayerPawn()
|
||||||
|
{
|
||||||
|
Pawns.clear();
|
||||||
|
KVector2D StartPosition{ 0.f, 0.f };
|
||||||
|
Pawns.emplace_back(std::make_shared<KCirclePawn>(StartPosition, Textures["P1.bmp"], PlayerControllers[static_cast<int>(KPlayer::Player1)]));
|
||||||
|
PlayerControllers[static_cast<int>(KPlayer::Player1)]->Possess(Pawns.back().get());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KGame::LoadMedia()
|
||||||
|
{
|
||||||
|
//Loading success flag
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
for (auto player : Utils::KPlayerIterator())
|
||||||
|
{
|
||||||
|
std::string filename = "P" + std::to_string(static_cast<int>(player) + 1) + ".bmp";
|
||||||
|
Textures.emplace(filename, KTexture());
|
||||||
|
if (!Textures[filename].LoadFromFile("assets/textures/" + filename, Renderer))
|
||||||
|
{
|
||||||
|
Textures.erase(filename);
|
||||||
|
printf("Failed to load player texture image!\n");
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerControllers.emplace_back(std::make_shared<KPlayerController>(player, this));
|
||||||
|
PlayerControllers.back()->SetupInputBindings(Input);
|
||||||
|
}
|
||||||
|
Textures.emplace("wall.bmp", KTexture());
|
||||||
|
if (!Textures["wall.bmp"].LoadFromFile("assets/textures/wall.bmp", Renderer))
|
||||||
|
{
|
||||||
|
printf("Failed to load wall texture image!\n");
|
||||||
|
Textures.erase("wall.bmp");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Fonts.emplace("PressStart2P-Regular", KFont());
|
||||||
|
if (!Fonts["PressStart2P-Regular"].LoadFromFile("assets/fonts/PressStart2P-Regular.ttf", 72))
|
||||||
|
{
|
||||||
|
printf("Failed to load PressStart2P-Regular font!\n");
|
||||||
|
Fonts.erase("PressStart2P-Regular");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
//Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextWithOutlineTexture("0:0", { 0xFF,0xFF,0xFF,0xFF }, { 0,0,0,0xFF }, 1, Renderer));
|
||||||
|
//Textures.emplace("Text_Winner", KTexture());
|
||||||
|
|
||||||
|
std::ifstream configFile("config.json");
|
||||||
|
if (configFile.fail()) {
|
||||||
|
printf("Failed to load config.json!\n");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nlohmann::json configJson;
|
||||||
|
configFile >> configJson;
|
||||||
|
configFile.close();
|
||||||
|
for (auto& player : configJson["Input"].items()) {
|
||||||
|
const auto playerEnum = Utils::GetPlayerFromString(player.key());
|
||||||
|
for (auto& axisMapping : player.value()["AxisMappings"]) {
|
||||||
|
Input.AddAxisMapping(axisMapping["AxisName"].get<std::string>(), axisMapping["Scale"].get<float>(), axisMapping["Key"].get<std::string>(), playerEnum);
|
||||||
|
}
|
||||||
|
for (auto& actionMapping : player.value()["ActionMappings"]) {
|
||||||
|
Input.AddActionMapping(actionMapping["ActionName"].get<std::string>(), actionMapping["Key"].get<std::string>(), playerEnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!LoadLevel())
|
||||||
|
success = false;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KGame::Run(int argc, char* args[])
|
||||||
|
{
|
||||||
|
//Load media
|
||||||
|
if (!LoadMedia())
|
||||||
|
{
|
||||||
|
printf("Failed to load media!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Main loop flag
|
||||||
|
bool quit = false;
|
||||||
|
|
||||||
|
//Event handler
|
||||||
|
SDL_Event e;
|
||||||
|
|
||||||
|
KCamera camera(Map);
|
||||||
|
KCamera debugCamera(Map);
|
||||||
|
debugCamera.SetDebug(Map);
|
||||||
|
|
||||||
|
bool debug = false;
|
||||||
|
|
||||||
|
LoadPlayerPawn();
|
||||||
|
camera.Update(Pawns, Map);
|
||||||
|
|
||||||
|
Time = PreviousTime = SDL_GetTicks();
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
//While application is running
|
||||||
|
while (!quit)
|
||||||
|
{
|
||||||
|
PreviousTime = Time;
|
||||||
|
Time = SDL_GetTicks();
|
||||||
|
float deltaTime = (Time - PreviousTime) * 0.001f;
|
||||||
|
|
||||||
|
Input.HandleInputPreEvents();
|
||||||
|
|
||||||
|
//Handle events on queue
|
||||||
|
while (SDL_PollEvent(&e))
|
||||||
|
{
|
||||||
|
//User requests quit
|
||||||
|
if (e.type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
quit = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Input.HandleEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Input.HandleInputPostEvents(Playing);
|
||||||
|
|
||||||
|
if (Input.IsKeyboardButtonPressed(SDL_SCANCODE_F1))
|
||||||
|
{
|
||||||
|
debug = !debug;
|
||||||
|
}
|
||||||
|
if (Input.IsKeyboardButtonPressed(SDL_SCANCODE_F2))
|
||||||
|
{
|
||||||
|
CollisionEnabled = !CollisionEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Playing) {
|
||||||
|
for (const auto& pc : PlayerControllers) {
|
||||||
|
pc->Update(deltaTime);
|
||||||
|
}
|
||||||
|
for (const auto& pawn : Pawns) {
|
||||||
|
if (!Playing) break;
|
||||||
|
pawn->MovementStep(deltaTime);
|
||||||
|
}
|
||||||
|
if (CollisionEnabled) {
|
||||||
|
for (const auto& pawn : Pawns) {
|
||||||
|
if (!Playing) break;
|
||||||
|
pawn->CollisionDetectionStep(Objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto& pawn : Pawns) {
|
||||||
|
if (!Playing) break;
|
||||||
|
pawn->CollisionDetectionWithMapStep(Map);
|
||||||
|
}
|
||||||
|
for (const auto& pawn : Pawns) {
|
||||||
|
if (!Playing) break;
|
||||||
|
pawn->CollisionDetectionWithMapStep(camera.GetPlayArea());
|
||||||
|
}
|
||||||
|
|
||||||
|
camera.Update(Pawns, Map);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Playing)
|
||||||
|
{
|
||||||
|
if (Time > RestartTick)
|
||||||
|
{
|
||||||
|
LoadLevel();
|
||||||
|
LoadPlayerPawn();
|
||||||
|
debugCamera.SetDebug(Map);
|
||||||
|
camera.Update(Pawns, Map);
|
||||||
|
if (ShowWinner)
|
||||||
|
{
|
||||||
|
for (auto i : Utils::KPlayerIterator())
|
||||||
|
{
|
||||||
|
Scores[static_cast<int>(i)] = 0;
|
||||||
|
}
|
||||||
|
//Textures.erase("Text_Score");
|
||||||
|
//Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextWithOutlineTexture(Utils::StringFormat("%d:%d", Scores[0], Scores[1]), { 0xFF,0xFF,0xFF,0xFF }, { 0,0,0,0xFF }, 1, Renderer));
|
||||||
|
ShowWinner = false;
|
||||||
|
}
|
||||||
|
Playing = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Clear screen
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 66, 135, 245, 0xFF);
|
||||||
|
SDL_RenderClear(Renderer);
|
||||||
|
|
||||||
|
const auto& cameraInUse = debug ? debugCamera : camera;
|
||||||
|
|
||||||
|
|
||||||
|
if (Playing) {
|
||||||
|
for (const auto& object : Objects)
|
||||||
|
object.second->Render(Renderer, cameraInUse);
|
||||||
|
for (const auto& pawn : Pawns) {
|
||||||
|
pawn->Render(Renderer, cameraInUse);
|
||||||
|
}
|
||||||
|
if (const auto exit = Exit.lock()) {
|
||||||
|
const float exitX = camera.GetViewport().x + Constants::SCREEN_WIDTH / 2.f - Textures["arrow.bmp"].GetWidth() / 2.f - exit->GetPosition().X + exit->GetCollider()->GetWidth() / 2.f;
|
||||||
|
const float exitY = camera.GetViewport().y + 25.f - exit->GetPosition().Y + exit->GetCollider()->GetHeight() / 2.f;
|
||||||
|
const double degrees = atan2(-exitX, exitY) * (180.f / M_PI);
|
||||||
|
Textures["arrow.bmp"].RenderEx(Renderer, Constants::SCREEN_WIDTH / 2.f - Textures["arrow.bmp"].GetWidth() / 2.f, 25.f, degrees);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ShowWinner)
|
||||||
|
{
|
||||||
|
Textures["Text_Winner"].Render(Renderer, Constants::SCREEN_WIDTH / 2.f - Textures["Text_Winner"].GetWidth() / 2.f, 25.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Textures["Text_Score"].Render(Renderer, Constants::SCREEN_WIDTH / 2.f - Textures["Text_Score"].GetWidth() / 2.f, Constants::SCREEN_HEIGHT - 10.f - Textures["Text_Score"].GetHeight());
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
SDL_RenderDrawLineF(Renderer, 0, Constants::SCREEN_HEIGHT / 2.f, Constants::SCREEN_WIDTH, Constants::SCREEN_HEIGHT / 2.f);
|
||||||
|
SDL_RenderDrawLineF(Renderer, Constants::SCREEN_WIDTH / 2.f, 0, Constants::SCREEN_WIDTH / 2.f, Constants::SCREEN_HEIGHT);
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||||
|
|
||||||
|
SDL_RenderDrawPointF(Renderer, camera.GetFocusPoint().X * debugCamera.GetScale(), camera.GetFocusPoint().Y * debugCamera.GetScale());
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 0xFF, 0x00, 0x00, 0xFF);
|
||||||
|
SDL_FRect debugViewport = { camera.GetViewport().x * debugCamera.GetScale(),
|
||||||
|
camera.GetViewport().y * debugCamera.GetScale(),
|
||||||
|
camera.GetViewport().w * debugCamera.GetScale(),
|
||||||
|
camera.GetViewport().h * debugCamera.GetScale() };
|
||||||
|
SDL_RenderDrawRectF(Renderer, &debugViewport);
|
||||||
|
SDL_FRect debug2Viewport = { camera.GetPlayArea().x * debugCamera.GetScale(),
|
||||||
|
camera.GetPlayArea().y * debugCamera.GetScale(),
|
||||||
|
camera.GetPlayArea().w * debugCamera.GetScale(),
|
||||||
|
camera.GetPlayArea().h * debugCamera.GetScale() };
|
||||||
|
SDL_SetRenderDrawColor(Renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||||
|
SDL_RenderDrawRectF(Renderer, &debug2Viewport);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update screen
|
||||||
|
SDL_RenderPresent(Renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
58
2dgk_zad3/2dgk_zad3/KGame.h
Normal file
58
2dgk_zad3/2dgk_zad3/KGame.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "KTexture.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <SDL_render.h>
|
||||||
|
|
||||||
|
#include "KFont.h"
|
||||||
|
#include "KInput.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
class KExit;
|
||||||
|
class KObject;
|
||||||
|
|
||||||
|
class KGame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KGame();
|
||||||
|
~KGame();
|
||||||
|
void Win(KPlayer player);
|
||||||
|
KGame(const KGame& other) = delete;
|
||||||
|
KGame(KGame&& other) noexcept = delete;
|
||||||
|
KGame& operator=(const KGame& other) = delete;
|
||||||
|
KGame& operator=(KGame&& other) noexcept = delete;
|
||||||
|
int Run(int argc, char* args[]);
|
||||||
|
private:
|
||||||
|
SDL_Window* Window = nullptr;
|
||||||
|
|
||||||
|
SDL_Renderer* Renderer = nullptr;
|
||||||
|
|
||||||
|
std::unordered_map<std::pair<int, int>, std::shared_ptr<KObject>, Utils::PairHash> Objects;
|
||||||
|
std::vector<std::shared_ptr<KPawn>> Pawns;
|
||||||
|
std::vector<std::shared_ptr<KPlayerController>> PlayerControllers;
|
||||||
|
std::unordered_map<std::string, KTexture> Textures;
|
||||||
|
std::unordered_map<std::string, KFont> Fonts;
|
||||||
|
std::vector<KVector2D> FreePositions;
|
||||||
|
KInput Input;
|
||||||
|
uint32_t Time;
|
||||||
|
uint32_t PreviousTime;
|
||||||
|
SDL_FRect Map;
|
||||||
|
bool CollisionEnabled = true;
|
||||||
|
bool ShowWinner = false;
|
||||||
|
std::weak_ptr<KObject> Exit;
|
||||||
|
|
||||||
|
bool LoadLevel();
|
||||||
|
void LoadPlayerPawn();
|
||||||
|
bool LoadMedia();
|
||||||
|
|
||||||
|
int LvlCounter = 1;
|
||||||
|
bool Playing = true;
|
||||||
|
uint32_t RestartTick = -1;
|
||||||
|
short Scores[static_cast<int>(KPlayer::Player2) + 1] = { 0,0 };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
306
2dgk_zad3/2dgk_zad3/KInput.cpp
Normal file
306
2dgk_zad3/2dgk_zad3/KInput.cpp
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
#include "KInput.h"
|
||||||
|
#include "Constants.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
KInput::KInput() : GamePadsCount(0), Initialized(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::Init() {
|
||||||
|
if (Initialized) return;
|
||||||
|
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||||
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
|
||||||
|
const int nJoysticks = SDL_NumJoysticks();
|
||||||
|
GamePadsCount = 0;
|
||||||
|
|
||||||
|
// Count how many controllers there are
|
||||||
|
for (int i = 0; i < nJoysticks; i++)
|
||||||
|
if (SDL_IsGameController(i))
|
||||||
|
GamePadsCount++;
|
||||||
|
|
||||||
|
// If we have some controllers attached
|
||||||
|
if (GamePadsCount > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < GamePadsCount; i++)
|
||||||
|
{
|
||||||
|
// Open the controller and add it to our list
|
||||||
|
SDL_GameController* pad = SDL_GameControllerOpen(i);
|
||||||
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
|
ConnectedControllers.push_back(pad);
|
||||||
|
else
|
||||||
|
printf("SDL_GetError() = %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vectors are empty to begin with, this sets their size
|
||||||
|
ControllerInputs.resize(GamePadsCount);
|
||||||
|
LastControllerInputs.resize(GamePadsCount);
|
||||||
|
|
||||||
|
// Set the status of the controllers to "nothing is happening"
|
||||||
|
for (int i = 0; i < GamePadsCount; i++) {
|
||||||
|
for (int a = 0; a < SDL_CONTROLLER_AXIS_MAX; a++) {
|
||||||
|
ControllerInputs[i].Axis[a] = 0;
|
||||||
|
LastControllerInputs[i].Axis[a] = 0;
|
||||||
|
}
|
||||||
|
for (int b = 0; b < SDL_CONTROLLER_BUTTON_MAX; b++) {
|
||||||
|
ControllerInputs[i].Buttons[b] = false;
|
||||||
|
LastControllerInputs[i].Buttons[b] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::Free() {
|
||||||
|
for (const auto& pad : ConnectedControllers) {
|
||||||
|
SDL_GameControllerClose(pad);
|
||||||
|
}
|
||||||
|
ConnectedControllers.clear();
|
||||||
|
Actions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::HandleInputPreEvents() {
|
||||||
|
for (int i = 0; i < GamePadsCount; i++) {
|
||||||
|
for (int a = 0; a < SDL_CONTROLLER_AXIS_MAX; a++) {
|
||||||
|
LastControllerInputs[i].Axis[a] = ControllerInputs[i].Axis[a];
|
||||||
|
}
|
||||||
|
for (int b = 0; b < SDL_CONTROLLER_BUTTON_MAX; b++) {
|
||||||
|
LastControllerInputs[i].Buttons[b] = ControllerInputs[i].Buttons[b];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LastKeyboardInputs = KeyboardInputs;
|
||||||
|
}
|
||||||
|
void KInput::HandleInputPostEvents(const bool processInput) {
|
||||||
|
int size = 0;
|
||||||
|
const Uint8* currentKeyStates = SDL_GetKeyboardState(&size);
|
||||||
|
KeyboardInputs = std::vector<Uint8>(currentKeyStates, currentKeyStates + size);
|
||||||
|
if (processInput) {
|
||||||
|
ProcessActions();
|
||||||
|
ProcessAxes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void KInput::HandleEvent(const SDL_Event& event) {
|
||||||
|
switch (event.type) {
|
||||||
|
// This happens when a device is added
|
||||||
|
// A future improvement is to cope with new controllers being plugged in
|
||||||
|
// when the game is running
|
||||||
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
|
printf("DEVICEADDED cdevice.which = %d\n", event.cdevice.which);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// If a controller button is pressed
|
||||||
|
case SDL_CONTROLLERBUTTONDOWN:
|
||||||
|
// Cycle through the controllers
|
||||||
|
for (int i = 0; i < GamePadsCount; i++) {
|
||||||
|
// Looking for the button that was pressed
|
||||||
|
if (event.cbutton.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(ConnectedControllers[i]))) {
|
||||||
|
// So the relevant state can be updated
|
||||||
|
ControllerInputs[i].Buttons[event.cbutton.button] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Do the same for releasing a button
|
||||||
|
case SDL_CONTROLLERBUTTONUP:
|
||||||
|
for (int i = 0; i < GamePadsCount; i++) {
|
||||||
|
if (event.cbutton.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(ConnectedControllers[i]))) {
|
||||||
|
ControllerInputs[i].Buttons[event.cbutton.button] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// And something similar for axis motion
|
||||||
|
case SDL_CONTROLLERAXISMOTION:
|
||||||
|
for (int i = 0; i < GamePadsCount; i++) {
|
||||||
|
if (event.cbutton.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(ConnectedControllers[i]))) {
|
||||||
|
ControllerInputs[i].Axis[event.caxis.axis] = event.caxis.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::BindAction(const std::string& name, InputState expectedInputState,
|
||||||
|
const std::shared_ptr<KPlayerController>& controllerObject,
|
||||||
|
KPlayerCommand command, KPlayer player) {
|
||||||
|
Actions.emplace_back(name, expectedInputState, controllerObject, command, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::BindAxis(const std::string& name, const std::shared_ptr<KPlayerController>& controllerObject, KPlayerAxisCommand command, KPlayer player)
|
||||||
|
{
|
||||||
|
Axes.emplace_back(name, controllerObject, command, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::CheckAction(const std::string& name, const InputState expectedInputState, KPlayer player) {
|
||||||
|
const auto keyBindRange = KeyBinds[static_cast<int>(player)].equal_range(name);
|
||||||
|
for (auto keyBind = keyBindRange.first; keyBind != keyBindRange.second; ++keyBind) {
|
||||||
|
switch (expectedInputState) {
|
||||||
|
case InputState::Pressed:
|
||||||
|
if (IsKeyboardButtonPressed(keyBind->second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case InputState::Released:
|
||||||
|
if (IsKeyboardButtonReleased(keyBind->second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case InputState::Hold:
|
||||||
|
if (IsKeyboardButtonHeld(keyBind->second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto buttonBindRange = ButtonBinds[static_cast<int>(player)].equal_range(name);
|
||||||
|
for (auto buttonBind = buttonBindRange.first; buttonBind != buttonBindRange.second; ++buttonBind) {
|
||||||
|
switch (expectedInputState) {
|
||||||
|
case InputState::Pressed:
|
||||||
|
if (IsControllerButtonPressed(buttonBind->second.first, buttonBind->second.second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case InputState::Released:
|
||||||
|
if (IsControllerButtonReleased(buttonBind->second.first, buttonBind->second.second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case InputState::Hold:
|
||||||
|
if (IsControllerButtonHeld(buttonBind->second.first, buttonBind->second.second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::ProcessActions() {
|
||||||
|
for (auto& action : Actions) {
|
||||||
|
if (CheckAction(action.Name, action.ExpectedInputState, action.Player)) {
|
||||||
|
if (auto obj = action.ControllerObject.lock())
|
||||||
|
std::invoke(action.Command, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::ProcessAxes()
|
||||||
|
{
|
||||||
|
for (auto& axis : Axes) {
|
||||||
|
if (auto obj = axis.ControllerObject.lock())
|
||||||
|
std::invoke(axis.AxisCommand, obj, GetAxisValue(axis.Name, axis.Player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::AddAxisMapping(const std::string& name, const float& scale, const std::string& key, const KPlayer& player)
|
||||||
|
{
|
||||||
|
if (key.rfind("Gamepad", 0) == 0) {
|
||||||
|
const auto delimiterPosition = key.find('_', 7);
|
||||||
|
const auto controllerIndex = static_cast<Controllers>(std::stoi(key.substr(7, delimiterPosition)));
|
||||||
|
auto axis = key.substr(delimiterPosition + 1);
|
||||||
|
std::for_each(axis.begin(), axis.end(), [](char& c) {
|
||||||
|
c = ::tolower(c);
|
||||||
|
});
|
||||||
|
ControllerAxisBinds[static_cast<int>(player)].emplace(name, KControllerAxisMapping(controllerIndex, SDL_GameControllerGetAxisFromString(axis.c_str()), scale));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDL_Scancode scanCode = SDL_GetScancodeFromName(key.c_str());
|
||||||
|
if (scanCode != SDL_SCANCODE_UNKNOWN) {
|
||||||
|
KeyAxisBinds[static_cast<int>(player)].emplace(name, std::make_pair(scanCode, scale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInput::AddActionMapping(const std::string& name, const std::string& key, const KPlayer& player)
|
||||||
|
{
|
||||||
|
if (key.rfind("Gamepad", 0) == 0) {
|
||||||
|
const auto delimiterPosition = key.find('_', 7);
|
||||||
|
const auto controllerIndex = static_cast<Controllers>(std::stoi(key.substr(7, delimiterPosition)));
|
||||||
|
auto button = key.substr(delimiterPosition + 1);
|
||||||
|
std::for_each(button.begin(), button.end(), [](char& c) {
|
||||||
|
c = ::tolower(c);
|
||||||
|
});
|
||||||
|
ButtonBinds[static_cast<int>(player)].emplace(name, std::make_pair(controllerIndex, SDL_GameControllerGetButtonFromString(button.c_str())));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDL_Scancode scanCode = SDL_GetScancodeFromName(key.c_str());
|
||||||
|
if (scanCode != SDL_SCANCODE_UNKNOWN) {
|
||||||
|
KeyBinds[static_cast<int>(player)].emplace(name, scanCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::IsControllerButtonPressed(const Controllers controllerId, const SDL_GameControllerButton button) const
|
||||||
|
{
|
||||||
|
if (controllerId < Controllers::Controller1 || controllerId > static_cast<Controllers>(GamePadsCount - 1)) return false;
|
||||||
|
|
||||||
|
return ControllerInputs[static_cast<int>(controllerId)].Buttons[button] && !LastControllerInputs[static_cast<int>(controllerId)].Buttons[button];
|
||||||
|
}
|
||||||
|
bool KInput::IsControllerButtonReleased(const Controllers controllerId, const SDL_GameControllerButton button) const
|
||||||
|
{
|
||||||
|
if (controllerId < Controllers::Controller1 || controllerId > static_cast<Controllers>(GamePadsCount - 1)) return false;
|
||||||
|
|
||||||
|
return !ControllerInputs[static_cast<int>(controllerId)].Buttons[button] && LastControllerInputs[static_cast<int>(controllerId)].Buttons[button];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::IsControllerButtonHeld(const Controllers controllerId, const SDL_GameControllerButton button) const
|
||||||
|
{
|
||||||
|
if (controllerId < Controllers::Controller1 || controllerId > static_cast<Controllers>(GamePadsCount - 1)) return false;
|
||||||
|
|
||||||
|
return ControllerInputs[static_cast<int>(controllerId)].Buttons[button] && LastControllerInputs[static_cast<int>(controllerId)].Buttons[button];
|
||||||
|
}
|
||||||
|
|
||||||
|
float KInput::GetControllerAxis(const Controllers controllerId, const SDL_GameControllerAxis axis) const
|
||||||
|
{
|
||||||
|
if (controllerId <Controllers::Controller1 || controllerId > static_cast<Controllers>(GamePadsCount - 1)) return 0.0;
|
||||||
|
|
||||||
|
const int value = ControllerInputs[static_cast<int>(controllerId)].Axis[axis];
|
||||||
|
if (std::abs(value) < Constants::JOYSTICK_DEAD_ZONE) return 0.0;
|
||||||
|
|
||||||
|
return static_cast<float>(value) / 32768.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::IsKeyboardButtonPressed(const Uint8 scanCode) const
|
||||||
|
{
|
||||||
|
if (scanCode > KeyboardInputs.size() || scanCode > LastKeyboardInputs.size())
|
||||||
|
return false;
|
||||||
|
return KeyboardInputs[scanCode] && KeyboardInputs[scanCode] != LastKeyboardInputs[scanCode];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::IsKeyboardButtonReleased(const Uint8 scanCode) const
|
||||||
|
{
|
||||||
|
if (scanCode > KeyboardInputs.size() || scanCode > LastKeyboardInputs.size())
|
||||||
|
return false;
|
||||||
|
return !KeyboardInputs[scanCode] && KeyboardInputs[scanCode] != LastKeyboardInputs[scanCode];
|
||||||
|
}
|
||||||
|
|
||||||
|
float KInput::GetAxisValue(const std::string& name, const KPlayer& player) const
|
||||||
|
{
|
||||||
|
float value = 0.f;
|
||||||
|
const auto keyAxisBindRange = KeyAxisBinds[static_cast<int>(player)].equal_range(name);
|
||||||
|
for (auto keyAxisBind = keyAxisBindRange.first; keyAxisBind != keyAxisBindRange.second; ++keyAxisBind) {
|
||||||
|
if (IsKeyboardButtonHeld(keyAxisBind->second.first)) {
|
||||||
|
value += 1.0f * keyAxisBind->second.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto controllerAxisBindRange = ControllerAxisBinds[static_cast<int>(player)].equal_range(name);
|
||||||
|
for (auto controllerAxisBind = controllerAxisBindRange.first; controllerAxisBind != controllerAxisBindRange.second; ++controllerAxisBind) {
|
||||||
|
value += GetControllerAxis(controllerAxisBind->second.Controller, controllerAxisBind->second.Axis) * controllerAxisBind->second.Scale;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KInput::IsKeyboardButtonHeld(const Uint8 scanCode) const
|
||||||
|
{
|
||||||
|
if (scanCode > KeyboardInputs.size())
|
||||||
|
return false;
|
||||||
|
return KeyboardInputs[scanCode];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
61
2dgk_zad3/2dgk_zad3/KInput.h
Normal file
61
2dgk_zad3/2dgk_zad3/KInput.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_events.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Controllers.h"
|
||||||
|
#include "GamePad.h"
|
||||||
|
#include "KActionBind.h"
|
||||||
|
#include "KPlayer.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
struct KControllerAxisMapping {
|
||||||
|
KControllerAxisMapping(const Controllers controller, const SDL_GameControllerAxis axis, const float scale) : Controller(controller), Axis(axis), Scale(scale) {}
|
||||||
|
Controllers Controller;
|
||||||
|
SDL_GameControllerAxis Axis;
|
||||||
|
float Scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
class KInput {
|
||||||
|
std::vector<SDL_GameController*> ConnectedControllers;
|
||||||
|
std::vector<GamePad> ControllerInputs;
|
||||||
|
std::vector<GamePad> LastControllerInputs;
|
||||||
|
std::vector<Uint8> KeyboardInputs;
|
||||||
|
std::vector<Uint8> LastKeyboardInputs;
|
||||||
|
std::vector<KActionBind> Actions;
|
||||||
|
std::vector<KAxisBind> Axes;
|
||||||
|
std::unordered_multimap<std::string, Uint8> KeyBinds[static_cast<int>(KPlayer::Player2) + 1];
|
||||||
|
std::unordered_multimap<std::string, std::pair<Controllers, SDL_GameControllerButton>> ButtonBinds[static_cast<int>(KPlayer::Player2) + 1];
|
||||||
|
std::unordered_multimap<std::string, KControllerAxisMapping> ControllerAxisBinds[static_cast<int>(KPlayer::Player2) + 1];
|
||||||
|
std::unordered_multimap<std::string, std::pair<Uint8, float>> KeyAxisBinds[static_cast<int>(KPlayer::Player2) + 1];
|
||||||
|
int GamePadsCount;
|
||||||
|
bool Initialized;
|
||||||
|
|
||||||
|
void ProcessActions();
|
||||||
|
void ProcessAxes();
|
||||||
|
public:
|
||||||
|
KInput();
|
||||||
|
void Init();
|
||||||
|
void Free();
|
||||||
|
void HandleInputPreEvents();
|
||||||
|
void HandleInputPostEvents(bool processInput);
|
||||||
|
void HandleEvent(const SDL_Event& event);
|
||||||
|
void BindAction(const std::string& name, InputState expectedInputState, const std::shared_ptr<KPlayerController>& controllerObject, KPlayerCommand command, KPlayer player);
|
||||||
|
void BindAxis(const std::string& name, const std::shared_ptr<KPlayerController>& controllerObject, KPlayerAxisCommand command, KPlayer player);
|
||||||
|
bool CheckAction(const std::string& name, InputState expectedInputState, KPlayer player);
|
||||||
|
|
||||||
|
void AddAxisMapping(const std::string& name, const float& scale, const std::string& key, const KPlayer& player);
|
||||||
|
void AddActionMapping(const std::string& name, const std::string& key, const KPlayer& player);
|
||||||
|
|
||||||
|
bool IsControllerButtonPressed(Controllers controllerId, SDL_GameControllerButton button) const;
|
||||||
|
bool IsControllerButtonReleased(Controllers controllerId, SDL_GameControllerButton button) const;
|
||||||
|
bool IsControllerButtonHeld(Controllers controllerId, SDL_GameControllerButton button) const;
|
||||||
|
float GetControllerAxis(Controllers controllerId, SDL_GameControllerAxis axis) const;
|
||||||
|
bool IsKeyboardButtonHeld(Uint8 scanCode) const;
|
||||||
|
bool IsKeyboardButtonPressed(Uint8 scanCode) const;
|
||||||
|
bool IsKeyboardButtonReleased(Uint8 scanCode) const;
|
||||||
|
float GetAxisValue(const std::string& name, const KPlayer& player) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
23
2dgk_zad3/2dgk_zad3/KObject.cpp
Normal file
23
2dgk_zad3/2dgk_zad3/KObject.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "KObject.h"
|
||||||
|
|
||||||
|
#include "KCamera.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
std::atomic<int> KObject::IdCounter{ 0 };
|
||||||
|
|
||||||
|
KObject::KObject(const KVector2D& position, const KTexture& texture) :
|
||||||
|
Id(++IdCounter), Position(position), Texture(texture)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void KObject::Render(SDL_Renderer* renderer, const KCamera& camera) const
|
||||||
|
{
|
||||||
|
Texture.Render(renderer, Position.X - Texture.GetWidth() / 2.f - camera.GetViewport().x, Position.Y - Texture.GetHeight() / 2.f - camera.GetViewport().y, nullptr, camera.GetScale());
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KObject::GetPosition() const
|
||||||
|
{
|
||||||
|
return Position;
|
||||||
|
}
|
||||||
|
}
|
28
2dgk_zad3/2dgk_zad3/KObject.h
Normal file
28
2dgk_zad3/2dgk_zad3/KObject.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
#include "KTexture.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KCamera;
|
||||||
|
class KCollider;
|
||||||
|
|
||||||
|
class KObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KObject(const KVector2D& position, const KTexture& texture);
|
||||||
|
virtual ~KObject() = default;
|
||||||
|
void Render(SDL_Renderer* renderer, const KCamera& camera) const;
|
||||||
|
KVector2D GetPosition() const;
|
||||||
|
virtual const KCollider* GetCollider() const = 0;
|
||||||
|
const int Id;
|
||||||
|
static std::atomic<int> IdCounter;
|
||||||
|
protected:
|
||||||
|
KVector2D Position{ 0.f, 0.f };
|
||||||
|
private:
|
||||||
|
const KTexture& Texture;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
86
2dgk_zad3/2dgk_zad3/KPawn.cpp
Normal file
86
2dgk_zad3/2dgk_zad3/KPawn.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include "KPawn.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "KPlayerController.h"
|
||||||
|
#include "KExit.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
void KPawn::CollisionDetectionStep(const std::unordered_map<std::pair<int, int>, std::shared_ptr<KObject>, Utils::PairHash>& objects)
|
||||||
|
{
|
||||||
|
if (GetCollider() == nullptr) return;
|
||||||
|
|
||||||
|
const auto xPos = static_cast<int>(GetPosition().X / Constants::TILE_WIDTH);
|
||||||
|
const auto yPos = static_cast<int>(GetPosition().Y / Constants::TILE_HEIGHT);
|
||||||
|
|
||||||
|
for (const auto& [oX, oY] : std::initializer_list<std::pair<int, int>>{ {0, 0}, {-1,0}, {1,0}, {0,-1}, {0,1}, {-1,-1}, {1,1}, {1,-1}, {-1,1} })
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const auto& other = objects.at({ xPos + oX, yPos + oY });
|
||||||
|
if (other->GetCollider() == nullptr) continue;
|
||||||
|
if (other->Id == Id) continue;
|
||||||
|
if (GetCollider()->IsCollision(other->GetCollider())) {
|
||||||
|
if (typeid(*other) == typeid(KExit)) {
|
||||||
|
if (const auto pc = PlayerController.lock()) {
|
||||||
|
//pc->NotifyWin();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto separationVector = GetCollider()->GetSeparationVector(other->GetCollider());
|
||||||
|
|
||||||
|
Position += separationVector;
|
||||||
|
if (separationVector.Y < 0)
|
||||||
|
{
|
||||||
|
Velocity.Y = 0;
|
||||||
|
Grounded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::out_of_range&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPawn::MovementStep(const float& timeStep)
|
||||||
|
{
|
||||||
|
Position.X += Velocity.X * timeStep;
|
||||||
|
Position.Y += Velocity.Y * timeStep + 1.f / 2.f * Constants::GRAVITY * timeStep * timeStep;
|
||||||
|
Velocity.Y += Constants::GRAVITY * timeStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPawn::CollisionDetectionWithMapStep(const SDL_FRect& map)
|
||||||
|
{
|
||||||
|
const auto separationVector = GetCollider()->GetSeparationVector(map);
|
||||||
|
Position += separationVector;
|
||||||
|
if (separationVector.Y < 0)
|
||||||
|
{
|
||||||
|
Velocity.Y = 0;
|
||||||
|
Grounded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPawn::AddXMovementInput(const float& input)
|
||||||
|
{
|
||||||
|
Velocity.X = input * Constants::SPEED * (1 - Constants::SMOOTH) + Velocity.X * Constants::SMOOTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPawn::StopJump() {
|
||||||
|
if (!Grounded) {
|
||||||
|
if (Velocity.Y < -Constants::JUMP_SHORT_SPEED)
|
||||||
|
Velocity.Y = -Constants::JUMP_SHORT_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPawn::StartJump() {
|
||||||
|
if (Grounded) {
|
||||||
|
Grounded = false;
|
||||||
|
Velocity.Y = -Constants::JUMP_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
33
2dgk_zad3/2dgk_zad3/KPawn.h
Normal file
33
2dgk_zad3/2dgk_zad3/KPawn.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "KObject.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KPlayerController;
|
||||||
|
|
||||||
|
class KPawn : public KObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KPawn(const KVector2D& position, const KTexture& texture,
|
||||||
|
const std::shared_ptr<KPlayerController>& playerController)
|
||||||
|
: KObject(position, texture),
|
||||||
|
PlayerController(playerController)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void CollisionDetectionStep(const std::unordered_map<std::pair<int, int>, std::shared_ptr<KObject>, Utils::PairHash>& objects);
|
||||||
|
void MovementStep(const float& timeStep);
|
||||||
|
void CollisionDetectionWithMapStep(const SDL_FRect& map);
|
||||||
|
void AddXMovementInput(const float& input);
|
||||||
|
void StopJump();
|
||||||
|
void StartJump();
|
||||||
|
private:
|
||||||
|
const std::weak_ptr<KPlayerController> PlayerController;
|
||||||
|
KVector2D Velocity{ 0.f, 0.f };
|
||||||
|
bool Grounded;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
8
2dgk_zad3/2dgk_zad3/KPlayer.h
Normal file
8
2dgk_zad3/2dgk_zad3/KPlayer.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
enum class KPlayer : int {
|
||||||
|
Player1,
|
||||||
|
Player2
|
||||||
|
};
|
||||||
|
}
|
56
2dgk_zad3/2dgk_zad3/KPlayerController.cpp
Normal file
56
2dgk_zad3/2dgk_zad3/KPlayerController.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "KPlayerController.h"
|
||||||
|
|
||||||
|
#include "KGame.h"
|
||||||
|
#include "KInput.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
void KPlayerController::SetupInputBindings(KInput& input)
|
||||||
|
{
|
||||||
|
input.BindAxis("MoveX", shared_from_this(), &KPlayerController::MoveXAxis, Player);
|
||||||
|
input.BindAction("Jump", InputState::Pressed, shared_from_this(), &KPlayerController::StartJump, Player);
|
||||||
|
input.BindAction("Jump", InputState::Released, shared_from_this(), &KPlayerController::StopJump, Player);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::MoveXAxis(const float axis)
|
||||||
|
{
|
||||||
|
Input.X += axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::StartJump() {
|
||||||
|
InputStartJump = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::StopJump() {
|
||||||
|
InputStopJump = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::Update(float deltaTime)
|
||||||
|
{
|
||||||
|
Input.Normalize();
|
||||||
|
if (Pawn != nullptr) {
|
||||||
|
Pawn->AddXMovementInput(Input.X);
|
||||||
|
if (InputStartJump)
|
||||||
|
Pawn->StartJump();
|
||||||
|
if (InputStopJump)
|
||||||
|
Pawn->StopJump();
|
||||||
|
}
|
||||||
|
Input *= 0;
|
||||||
|
InputStartJump = false;
|
||||||
|
InputStopJump = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::Possess(KPawn* pawn)
|
||||||
|
{
|
||||||
|
Pawn = pawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPlayerController::UnPossess()
|
||||||
|
{
|
||||||
|
Pawn = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const KPlayer& KPlayerController::GetPlayer() const
|
||||||
|
{
|
||||||
|
return Player;
|
||||||
|
}
|
||||||
|
}
|
40
2dgk_zad3/2dgk_zad3/KPlayerController.h
Normal file
40
2dgk_zad3/2dgk_zad3/KPlayerController.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KPawn.h"
|
||||||
|
#include "KPlayer.h"
|
||||||
|
#include "KVector2d.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
class KGame;
|
||||||
|
class KInput;
|
||||||
|
|
||||||
|
class KPlayerController : public std::enable_shared_from_this<KPlayerController>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KPlayerController(const KPlayer player, KGame* const game)
|
||||||
|
: Player(player),
|
||||||
|
Game(game)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupInputBindings(KInput& input);
|
||||||
|
void MoveXAxis(float axis);
|
||||||
|
void StartJump();
|
||||||
|
void StopJump();
|
||||||
|
void Update(float deltaTime);
|
||||||
|
void NotifyWin() const;
|
||||||
|
void Possess(KPawn* pawn);
|
||||||
|
void UnPossess();
|
||||||
|
const KPlayer& GetPlayer() const;
|
||||||
|
private:
|
||||||
|
KVector2D Input{ 0.f, 0.f };
|
||||||
|
const KPlayer Player;
|
||||||
|
KPawn* Pawn{};
|
||||||
|
KGame* Game;
|
||||||
|
bool InputStartJump{};
|
||||||
|
bool InputStopJump{};
|
||||||
|
};
|
||||||
|
typedef void (KPlayerController::* KPlayerCommand)();
|
||||||
|
typedef void (KPlayerController::* KPlayerAxisCommand)(float input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
134
2dgk_zad3/2dgk_zad3/KRect.cpp
Normal file
134
2dgk_zad3/2dgk_zad3/KRect.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
#include "KRect.h"
|
||||||
|
|
||||||
|
#include "KCircle.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
|
||||||
|
float KRect::GetWidth() const {
|
||||||
|
return Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRect::GetHeight() const {
|
||||||
|
return Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KRect::GetSeparationVector(const float left, const float right, const float top, const float bottom) {
|
||||||
|
const auto x = left < right ? -left : right;
|
||||||
|
const auto y = top < bottom ? -top : bottom;
|
||||||
|
auto vX = x;
|
||||||
|
auto vY = y;
|
||||||
|
if (fabs(x) < fabs(y))
|
||||||
|
vY = 0;
|
||||||
|
if (fabs(x) > fabs(y))
|
||||||
|
vX = 0;
|
||||||
|
return { vX, vY };
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KRect::GetSeparationVector(const KCircle* other) const {
|
||||||
|
const float l = GetLeft();
|
||||||
|
const float r = GetRight();
|
||||||
|
const float t = GetTop();
|
||||||
|
const float b = GetBottom();
|
||||||
|
const auto f = KVector2D(Utils::Clamp(other->GetParent()->GetPosition().X, l, r),
|
||||||
|
Utils::Clamp(other->GetParent()->GetPosition().Y, t, b));
|
||||||
|
|
||||||
|
if (other->GetParent()->GetPosition() == f) {
|
||||||
|
const auto left = other->GetParent()->GetPosition().X - l + other->GetRadius();
|
||||||
|
const auto right = r - other->GetParent()->GetPosition().X + other->GetRadius();
|
||||||
|
const auto top = other->GetParent()->GetPosition().Y - t + other->GetRadius();
|
||||||
|
const auto bottom = b - other->GetParent()->GetPosition().Y + other->GetRadius();
|
||||||
|
return GetSeparationVector(left, right, top, bottom) * -1.f;
|
||||||
|
}
|
||||||
|
return (other->GetParent()->GetPosition() - f) / (other->GetParent()->GetPosition() - f).Length() * (other->GetRadius() - (other->GetParent()->GetPosition() - f).Length()) * 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KRect::GetSeparationVector(const KRect* other) const {
|
||||||
|
const auto left = GetRight() - other->GetLeft();
|
||||||
|
const auto right = other->GetRight() - GetLeft();
|
||||||
|
const auto top = GetBottom() - other->GetTop();
|
||||||
|
const auto bottom = other->GetBottom() - GetTop();
|
||||||
|
|
||||||
|
return GetSeparationVector(left, right, top, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KRect::IsCollision(const KCircle* other) const {
|
||||||
|
const auto f = KVector2D(Utils::Clamp(other->GetParent()->GetPosition().X, GetLeft(), GetRight()),
|
||||||
|
Utils::Clamp(other->GetParent()->GetPosition().Y, GetTop(), GetBottom()));
|
||||||
|
|
||||||
|
return (other->GetParent()->GetPosition() - f).Length() < other->GetRadius();
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRect::GetLeft() const
|
||||||
|
{
|
||||||
|
return GetParent()->GetPosition().X - Width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRect::GetRight() const
|
||||||
|
{
|
||||||
|
return GetParent()->GetPosition().X + Width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRect::GetBottom() const
|
||||||
|
{
|
||||||
|
return GetParent()->GetPosition().Y + Height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRect::GetTop() const
|
||||||
|
{
|
||||||
|
return GetParent()->GetPosition().Y - Height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KRect::IsCollision(const KRect* other) const {
|
||||||
|
return GetRight() >= other->GetLeft()
|
||||||
|
&& other->GetRight() >= GetLeft()
|
||||||
|
&& GetBottom() >= other->GetTop()
|
||||||
|
&& other->GetBottom() >= GetTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KRect::IsCollision(const KCollider* other) const
|
||||||
|
{
|
||||||
|
const auto circle = dynamic_cast<const KCircle*>(other);
|
||||||
|
if (circle != nullptr)
|
||||||
|
return IsCollision(circle);
|
||||||
|
|
||||||
|
const auto rect = dynamic_cast<const KRect*>(other);
|
||||||
|
if (rect != nullptr)
|
||||||
|
return IsCollision(rect);
|
||||||
|
|
||||||
|
throw std::runtime_error("unsupported shape");
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KRect::GetSeparationVector(const KCollider* other) const
|
||||||
|
{
|
||||||
|
const auto circle = dynamic_cast<const KCircle*>(other);
|
||||||
|
if (circle != nullptr)
|
||||||
|
return GetSeparationVector(circle);
|
||||||
|
|
||||||
|
const auto rect = dynamic_cast<const KRect*>(other);
|
||||||
|
if (rect != nullptr)
|
||||||
|
return GetSeparationVector(rect);
|
||||||
|
|
||||||
|
throw std::runtime_error("unsupported shape");
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D KRect::GetSeparationVector(const SDL_FRect& map) const
|
||||||
|
{
|
||||||
|
KVector2D separationVector{ 0.f,0.f };
|
||||||
|
if (GetParent()->GetPosition().X - map.x - GetWidth() / 2 < 0)
|
||||||
|
{
|
||||||
|
separationVector.X += -(GetParent()->GetPosition().X - map.x - GetWidth() / 2);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().X + GetWidth() / 2 - (map.x + map.w) > 0)
|
||||||
|
{
|
||||||
|
separationVector.X += -(GetParent()->GetPosition().X - (map.x + map.w) + GetWidth() / 2);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().Y - GetHeight() / 2 - map.y < 0) {
|
||||||
|
separationVector.Y += -(GetParent()->GetPosition().Y - map.y - GetHeight() / 2);
|
||||||
|
}
|
||||||
|
if (GetParent()->GetPosition().Y + GetHeight() / 2 - (map.y + map.h) > 0) {
|
||||||
|
separationVector.Y += -(GetParent()->GetPosition().Y - (map.y + map.h) + GetHeight() / 2);
|
||||||
|
}
|
||||||
|
return separationVector;
|
||||||
|
}
|
||||||
|
}
|
38
2dgk_zad3/2dgk_zad3/KRect.h
Normal file
38
2dgk_zad3/2dgk_zad3/KRect.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
|
||||||
|
#include "KCollider.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
class KCircle;
|
||||||
|
|
||||||
|
class KRect final : public KCollider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KRect(KObject* parent, const float width, const float height)
|
||||||
|
: KCollider(parent),
|
||||||
|
Width(width),
|
||||||
|
Height(height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
float GetWidth() const override;
|
||||||
|
float GetHeight() const override;
|
||||||
|
static KVector2D GetSeparationVector(float left, float right, float top, float bottom);
|
||||||
|
bool IsCollision(const KCollider* other) const override;
|
||||||
|
KVector2D GetSeparationVector(const KCollider* other) const override;
|
||||||
|
KVector2D GetSeparationVector(const SDL_FRect& map) const override;
|
||||||
|
private:
|
||||||
|
KVector2D GetSeparationVector(const KCircle* other) const;
|
||||||
|
KVector2D GetSeparationVector(const KRect* other) const;
|
||||||
|
bool IsCollision(const KCircle* other) const;
|
||||||
|
float GetLeft() const;
|
||||||
|
float GetRight() const;
|
||||||
|
float GetBottom() const;
|
||||||
|
float GetTop() const;
|
||||||
|
bool IsCollision(const KRect* other) const;
|
||||||
|
float Width;
|
||||||
|
float Height;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
2dgk_zad3/2dgk_zad3/KRectPawn.cpp
Normal file
15
2dgk_zad3/2dgk_zad3/KRectPawn.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "KRectPawn.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
KRectPawn::KRectPawn(const KVector2D& position, const KTexture& texture,
|
||||||
|
const std::shared_ptr<KPlayerController>& playerController) : KPawn(position, texture, playerController),
|
||||||
|
Collider(this, texture.GetWidth(), texture.GetHeight())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const KCollider* KRectPawn::GetCollider() const
|
||||||
|
{
|
||||||
|
return &Collider;
|
||||||
|
}
|
||||||
|
}
|
20
2dgk_zad3/2dgk_zad3/KRectPawn.h
Normal file
20
2dgk_zad3/2dgk_zad3/KRectPawn.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KPawn.h"
|
||||||
|
#include "KRect.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KRectPawn final :
|
||||||
|
public KPawn
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KRectPawn(const KVector2D& position, const KTexture& texture,
|
||||||
|
const std::shared_ptr<KPlayerController>& playerController);
|
||||||
|
|
||||||
|
const KCollider* GetCollider() const override;
|
||||||
|
private:
|
||||||
|
KRect Collider;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
144
2dgk_zad3/2dgk_zad3/KTexture.cpp
Normal file
144
2dgk_zad3/2dgk_zad3/KTexture.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
#include "KTexture.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
KTexture::KTexture() : Texture(nullptr), Width(0), Height(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KTexture::KTexture(KTexture&& other) noexcept
|
||||||
|
: Texture(other.Texture),
|
||||||
|
Width(other.Width),
|
||||||
|
Height(other.Height) {
|
||||||
|
other.Texture = nullptr;
|
||||||
|
other.Width = 0;
|
||||||
|
other.Height = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
KTexture& KTexture::operator=(KTexture&& other) noexcept {
|
||||||
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
Texture = other.Texture;
|
||||||
|
Width = other.Width;
|
||||||
|
Height = other.Height;
|
||||||
|
other.Texture = nullptr;
|
||||||
|
other.Width = 0;
|
||||||
|
other.Height = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
KTexture::~KTexture()
|
||||||
|
{
|
||||||
|
//Deallocate
|
||||||
|
Free();
|
||||||
|
|
||||||
|
}
|
||||||
|
bool KTexture::LoadFromFile(const std::string& path, SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
//Get rid of preexisting texture
|
||||||
|
Free();
|
||||||
|
//The final texture
|
||||||
|
SDL_Texture* newTexture = nullptr;
|
||||||
|
|
||||||
|
//Load image at specified path
|
||||||
|
SDL_Surface* loadedSurface = SDL_LoadBMP(path.c_str());
|
||||||
|
if (loadedSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Color key image
|
||||||
|
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0xFF, 0, 0));
|
||||||
|
//Create texture from surface pixels
|
||||||
|
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||||
|
if (newTexture == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Get image dimensions
|
||||||
|
Width = loadedSurface->w;
|
||||||
|
Height = loadedSurface->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get rid of old loaded surface
|
||||||
|
SDL_FreeSurface(loadedSurface);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return success
|
||||||
|
Texture = newTexture;
|
||||||
|
return Texture != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KTexture::LoadFromSurface(SDL_Surface* surface, SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
Free();
|
||||||
|
Texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
|
if (Texture == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to create texture from surface! SDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Width = surface->w;
|
||||||
|
Height = surface->h;
|
||||||
|
}
|
||||||
|
return Texture != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTexture::Free()
|
||||||
|
{
|
||||||
|
//Free texture if it exists
|
||||||
|
if (Texture != nullptr)
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(Texture);
|
||||||
|
Texture = nullptr;
|
||||||
|
Width = 0;
|
||||||
|
Height = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTexture::Render(SDL_Renderer* renderer, const float x, const float y, SDL_Rect* clip, const float scale) const
|
||||||
|
{
|
||||||
|
if (Texture == nullptr) return;
|
||||||
|
//Set rendering space and render to screen
|
||||||
|
SDL_FRect renderQuad = {
|
||||||
|
x * scale, y * scale,
|
||||||
|
Width * scale, Height * scale
|
||||||
|
};
|
||||||
|
|
||||||
|
//Set clip rendering dimensions
|
||||||
|
if (clip != nullptr)
|
||||||
|
{
|
||||||
|
renderQuad.w = clip->w;
|
||||||
|
renderQuad.h = clip->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Render to screen
|
||||||
|
SDL_RenderCopyF(renderer, Texture, clip, &renderQuad);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTexture::RenderEx(SDL_Renderer* renderer, const float x, const float y, const double degrees) const
|
||||||
|
{
|
||||||
|
if (Texture == nullptr) return;
|
||||||
|
//Set rendering space and render to screen
|
||||||
|
const SDL_FRect renderQuad = {
|
||||||
|
x , y ,
|
||||||
|
static_cast<float>(Width) , static_cast<float>(Height)
|
||||||
|
};
|
||||||
|
|
||||||
|
//Render to screen
|
||||||
|
SDL_RenderCopyExF(renderer, Texture, nullptr, &renderQuad, degrees, nullptr, SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int KTexture::GetWidth() const
|
||||||
|
{
|
||||||
|
return Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KTexture::GetHeight() const
|
||||||
|
{
|
||||||
|
return Height;
|
||||||
|
}
|
||||||
|
}
|
48
2dgk_zad3/2dgk_zad3/KTexture.h
Normal file
48
2dgk_zad3/2dgk_zad3/KTexture.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_render.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
//Texture wrapper class
|
||||||
|
class KTexture {
|
||||||
|
public:
|
||||||
|
KTexture();
|
||||||
|
|
||||||
|
~KTexture();
|
||||||
|
|
||||||
|
|
||||||
|
KTexture(const KTexture& other) = delete;
|
||||||
|
|
||||||
|
KTexture(KTexture&& other) noexcept;
|
||||||
|
|
||||||
|
KTexture& operator=(const KTexture& other) = delete;
|
||||||
|
|
||||||
|
KTexture& operator=(KTexture&& other) noexcept;
|
||||||
|
|
||||||
|
//Loads image at specified path
|
||||||
|
bool LoadFromFile(const std::string& path, SDL_Renderer* renderer);
|
||||||
|
|
||||||
|
bool LoadFromSurface(SDL_Surface* surface, SDL_Renderer* renderer);
|
||||||
|
|
||||||
|
//Deallocates texture
|
||||||
|
void Free();
|
||||||
|
|
||||||
|
//Renders texture at given point
|
||||||
|
void Render(SDL_Renderer* renderer, float x, float y, SDL_Rect* clip = nullptr, float scale = 1.f) const;
|
||||||
|
|
||||||
|
void RenderEx(SDL_Renderer* renderer, float x, float y, double degrees) const;
|
||||||
|
|
||||||
|
//Gets image dimensions
|
||||||
|
int GetWidth() const;
|
||||||
|
int GetHeight() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//The actual hardware texture
|
||||||
|
SDL_Texture* Texture;
|
||||||
|
|
||||||
|
//Image dimensions
|
||||||
|
int Width;
|
||||||
|
int Height;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
33
2dgk_zad3/2dgk_zad3/KTile.cpp
Normal file
33
2dgk_zad3/2dgk_zad3/KTile.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "KTile.h"
|
||||||
|
|
||||||
|
#include <SDL_render.h>
|
||||||
|
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "KTexture.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
|
||||||
|
int KTile::GetType() const {
|
||||||
|
return static_cast<int>(Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect KTile::GetBox() const {
|
||||||
|
return Box;
|
||||||
|
}
|
||||||
|
|
||||||
|
KTile::KTile(const int x, const int y, const TileType tileType) {
|
||||||
|
//Get the offsets
|
||||||
|
Box.x = x;
|
||||||
|
Box.y = y;
|
||||||
|
|
||||||
|
Box.w = Constants::TILE_WIDTH;
|
||||||
|
Box.h = Constants::TILE_HEIGHT;
|
||||||
|
|
||||||
|
//Get the tile type
|
||||||
|
Type = tileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KTile::Render(SDL_Renderer* renderer, KTexture tileTextures[], const SDL_Rect& camera, const float scale) const {
|
||||||
|
tileTextures[GetType()].Render(renderer, Box.x - camera.x, Box.y - camera.y, nullptr, scale);
|
||||||
|
}
|
||||||
|
}
|
34
2dgk_zad3/2dgk_zad3/KTile.h
Normal file
34
2dgk_zad3/2dgk_zad3/KTile.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <SDL_render.h>
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KTexture;
|
||||||
|
|
||||||
|
enum class TileType : std::uint32_t {
|
||||||
|
Default = 0,
|
||||||
|
Wall = 1
|
||||||
|
};
|
||||||
|
class KTile {
|
||||||
|
public:
|
||||||
|
//Initializes position and type
|
||||||
|
KTile(int x, int y, TileType tileType);
|
||||||
|
|
||||||
|
//Shows the tile
|
||||||
|
void Render(SDL_Renderer* renderer, KTexture tileTextures[], const SDL_Rect& camera, float scale = 1.f) const;
|
||||||
|
|
||||||
|
//Get the tile type
|
||||||
|
int GetType() const;
|
||||||
|
|
||||||
|
SDL_Rect GetBox() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//The attributes of the tile
|
||||||
|
SDL_Rect Box{};
|
||||||
|
|
||||||
|
//The tile type
|
||||||
|
TileType Type;
|
||||||
|
};
|
||||||
|
}
|
82
2dgk_zad3/2dgk_zad3/KVector2d.h
Normal file
82
2dgk_zad3/2dgk_zad3/KVector2d.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cfloat>
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
struct KVector2D {
|
||||||
|
float X;
|
||||||
|
float Y;
|
||||||
|
|
||||||
|
KVector2D(const float x, const float y) : X(x), Y(y) {}
|
||||||
|
|
||||||
|
float Length() const { return sqrt(X * X + Y * Y); }
|
||||||
|
float Length2() const { return X * X + Y * Y; }
|
||||||
|
|
||||||
|
bool operator==(const KVector2D& v2) const {
|
||||||
|
return (*this - v2).Length2() < FLT_EPSILON * FLT_EPSILON;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D operator+(const KVector2D& v2) const {
|
||||||
|
return { X + v2.X, Y + v2.Y };
|
||||||
|
}
|
||||||
|
|
||||||
|
friend KVector2D& operator+=(KVector2D& v1, const KVector2D& v2) {
|
||||||
|
v1.X += v2.X;
|
||||||
|
v1.Y += v2.Y;
|
||||||
|
return v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D operator*(const float scalar) const
|
||||||
|
{
|
||||||
|
return { X * scalar, Y * scalar };
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D& operator*=(const float scalar) {
|
||||||
|
X *= scalar;
|
||||||
|
Y *= scalar;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D operator-(const KVector2D& v2) const {
|
||||||
|
return { X - v2.X, Y - v2.Y };
|
||||||
|
}
|
||||||
|
friend KVector2D& operator-=(KVector2D& v1, const KVector2D& v2) {
|
||||||
|
v1.X -= v2.X;
|
||||||
|
v1.Y -= v2.Y;
|
||||||
|
return v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
KVector2D operator/(const float scalar) const
|
||||||
|
{
|
||||||
|
return { X / scalar, Y / scalar };
|
||||||
|
}
|
||||||
|
KVector2D& operator/=(const float scalar) {
|
||||||
|
X /= scalar;
|
||||||
|
Y /= scalar;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
float DotProduct(const KVector2D& v2) const {
|
||||||
|
return DotProduct(*this, v2);
|
||||||
|
}
|
||||||
|
KVector2D Reflect(const KVector2D& normal) const {
|
||||||
|
return Reflect(normal, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Normalize() {
|
||||||
|
const float l = Length();
|
||||||
|
if (l > 1.f) {
|
||||||
|
(*this) *= 1 / l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static KVector2D Reflect(const KVector2D& normal, const KVector2D& vector) {
|
||||||
|
const float dn = 2 * vector.DotProduct(normal);
|
||||||
|
return vector - normal * dn;
|
||||||
|
}
|
||||||
|
static float DotProduct(const KVector2D& v1, const KVector2D& v2) {
|
||||||
|
return v1.X * v2.X + v1.Y * v2.Y ;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
9
2dgk_zad3/2dgk_zad3/KWall.cpp
Normal file
9
2dgk_zad3/2dgk_zad3/KWall.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "KWall.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
const KCollider* KWall::GetCollider() const
|
||||||
|
{
|
||||||
|
return &Collider;
|
||||||
|
}
|
||||||
|
}
|
22
2dgk_zad3/2dgk_zad3/KWall.h
Normal file
22
2dgk_zad3/2dgk_zad3/KWall.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "KObject.h"
|
||||||
|
#include "KRect.h"
|
||||||
|
|
||||||
|
namespace KapitanGame
|
||||||
|
{
|
||||||
|
class KWall final :
|
||||||
|
public KObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KWall(const KVector2D& position, const KTexture& texture)
|
||||||
|
: KObject(position, texture),
|
||||||
|
Collider(this, texture.GetWidth() * 1.f, texture.GetHeight() * 1.f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const KCollider* GetCollider() const override;
|
||||||
|
private:
|
||||||
|
KRect Collider;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
8
2dgk_zad3/2dgk_zad3/Main.cpp
Normal file
8
2dgk_zad3/2dgk_zad3/Main.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "KGame.h"
|
||||||
|
|
||||||
|
int main(int argc, char* args[])
|
||||||
|
{
|
||||||
|
KapitanGame::KGame game;
|
||||||
|
|
||||||
|
return game.Run(argc, args);
|
||||||
|
}
|
7
2dgk_zad3/2dgk_zad3/Utils.cpp
Normal file
7
2dgk_zad3/2dgk_zad3/Utils.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
109
2dgk_zad3/2dgk_zad3/Utils.h
Normal file
109
2dgk_zad3/2dgk_zad3/Utils.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <random>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "KPlayer.h"
|
||||||
|
|
||||||
|
namespace KapitanGame {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
template<typename ... Args>
|
||||||
|
std::string StringFormat(const std::string& format, Args ... args)
|
||||||
|
{
|
||||||
|
const int sizeS = std::snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0'
|
||||||
|
if (sizeS <= 0) { throw std::runtime_error("Error during formatting."); }
|
||||||
|
const auto size = static_cast<size_t>(sizeS);
|
||||||
|
const auto buf = std::make_unique<char[]>(size);
|
||||||
|
std::snprintf(buf.get(), size, format.c_str(), args ...);
|
||||||
|
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
constexpr const T& Clamp(const T& x, const T& min, const T& max)
|
||||||
|
{
|
||||||
|
return std::max(std::min(max, x), min);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
constexpr const T& Clamp01(const T& x)
|
||||||
|
{
|
||||||
|
return Clamp(x, 0.f, 1.f);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
constexpr const T& Lerp(const T& a, const T& b, const float& t)
|
||||||
|
{
|
||||||
|
return a + (b - a) * Clamp01(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::default_random_engine make_default_random_engine()
|
||||||
|
{
|
||||||
|
// This gets a source of actual, honest-to-god randomness
|
||||||
|
std::random_device source;
|
||||||
|
|
||||||
|
// Here, we fill an array of random data from the source
|
||||||
|
unsigned int random_data[10];
|
||||||
|
for (auto& elem : random_data) {
|
||||||
|
elem = source();
|
||||||
|
}
|
||||||
|
|
||||||
|
// this creates the random seed sequence out of the random data
|
||||||
|
std::seed_seq seq(random_data + 0, random_data + 10);
|
||||||
|
return std::default_random_engine{ seq };
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::default_random_engine& GetRandomEngine()
|
||||||
|
{
|
||||||
|
// Making rng static ensures that it stays the same
|
||||||
|
// Between different invocations of the function
|
||||||
|
static std::default_random_engine rng(make_default_random_engine());
|
||||||
|
return rng;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double RandomNumber() {
|
||||||
|
const std::uniform_real_distribution<double> dist(0.0, 1.0);
|
||||||
|
return dist(GetRandomEngine());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C, C BeginVal, C EndVal>
|
||||||
|
class Iterator {
|
||||||
|
typedef std::underlying_type_t<C> ValT;
|
||||||
|
int Value;
|
||||||
|
public:
|
||||||
|
explicit Iterator(const C& f) : Value(static_cast<ValT>(f)) {}
|
||||||
|
Iterator() : Value(static_cast<ValT>(BeginVal)) {}
|
||||||
|
Iterator operator++() {
|
||||||
|
++Value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
C operator*() { return static_cast<C>(Value); }
|
||||||
|
Iterator begin() { return *this; } //default ctor is good
|
||||||
|
Iterator end() {
|
||||||
|
static const Iterator END_ITERATE = ++Iterator(EndVal); // cache it
|
||||||
|
return END_ITERATE;
|
||||||
|
}
|
||||||
|
bool operator!=(const Iterator& i) { return Value != i.Value; }
|
||||||
|
};
|
||||||
|
|
||||||
|
inline KPlayer GetPlayerFromString(const std::string& str)
|
||||||
|
{
|
||||||
|
static std::unordered_map<std::string, KPlayer> const TABLE = { {"Player1",KPlayer::Player1},{"Player2",KPlayer::Player2} };
|
||||||
|
const auto it = TABLE.find(str);
|
||||||
|
if (it != TABLE.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
return KPlayer::Player1;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef Iterator<KPlayer, KPlayer::Player1, KPlayer::Player1> KPlayerIterator;
|
||||||
|
|
||||||
|
struct PairHash {
|
||||||
|
template <class T1, class T2>
|
||||||
|
std::size_t operator () (const std::pair<T1, T2>& p) const {
|
||||||
|
auto h1 = std::hash<T1>{}(p.first);
|
||||||
|
auto h2 = std::hash<T2>{}(p.second);
|
||||||
|
return h1 ^ h2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
202
2dgk_zad3/2dgk_zad3/assets/fonts/LICENSE.txt
Normal file
202
2dgk_zad3/2dgk_zad3/assets/fonts/LICENSE.txt
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
93
2dgk_zad3/2dgk_zad3/assets/fonts/OFL.txt
Normal file
93
2dgk_zad3/2dgk_zad3/assets/fonts/OFL.txt
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
Copyright 2012 The Press Start 2P Project Authors (cody@zone38.net), with Reserved Font Name "Press Start 2P".
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
BIN
2dgk_zad3/2dgk_zad3/assets/fonts/PressStart2P-Regular.ttf
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/fonts/PressStart2P-Regular.ttf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
2dgk_zad3/2dgk_zad3/assets/fonts/Roboto-Thin.ttf
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/fonts/Roboto-Thin.ttf
(Stored with Git LFS)
Normal file
Binary file not shown.
33
2dgk_zad3/2dgk_zad3/assets/levels/level1.txt
Normal file
33
2dgk_zad3/2dgk_zad3/assets/levels/level1.txt
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#################################
|
||||||
|
# # # # # # #
|
||||||
|
# ######### # # ### # # ### ### #
|
||||||
|
# # # # # # # #
|
||||||
|
### ### ### ### # ### # # # #####
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# # ### # # # # ####### # # ### #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
####### ### ### # ####### ### # #
|
||||||
|
# # # # # # # # # #
|
||||||
|
# # # ### ### # # # # ### # #####
|
||||||
|
# # # # # # # # # #
|
||||||
|
# # ### # ### # # ### # # ### # #
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# # # ### ### # ### ### ### # # #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# ### ##### ##### # ######### ###
|
||||||
|
# # # # # # #
|
||||||
|
##### ### # ### ####### # ##### #
|
||||||
|
# # # # # #
|
||||||
|
# ######### # # ####### ##### ###
|
||||||
|
# # # # # # # # #
|
||||||
|
### ### ### ########### ### # ###
|
||||||
|
# # # # # # #
|
||||||
|
# # ### # ### # ##### ### ### # #
|
||||||
|
# # # # # # # # #
|
||||||
|
# # ##### ### ### ### # ### # ###
|
||||||
|
# # # # # # # # # #
|
||||||
|
# ##### # # ##### # # ##### #####
|
||||||
|
# # # # # # # # # # # # #
|
||||||
|
# # ### ##### ####### # # # ### #
|
||||||
|
# # # # # #
|
||||||
|
#################################
|
37
2dgk_zad3/2dgk_zad3/assets/levels/level2.txt
Normal file
37
2dgk_zad3/2dgk_zad3/assets/levels/level2.txt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#####################################
|
||||||
|
# # # # # # #
|
||||||
|
# ### ### # # # ######### # ##### # #
|
||||||
|
# # # # # # # # # #
|
||||||
|
### # ### # ####### # # ##### # ### #
|
||||||
|
# # # # # # # # #
|
||||||
|
### ########### # ### # # # # ### ###
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# # ### ### # ### ### # ######### # #
|
||||||
|
# # # # # # # # #
|
||||||
|
# # ### # # ### # # # ### ######### #
|
||||||
|
# # # # # # # # # # # # # #
|
||||||
|
# ##### # # # # ####### ### ##### # #
|
||||||
|
# # # # # # # #
|
||||||
|
# ##### # # # ##### ####### ### # ###
|
||||||
|
# # # # # # # # # #
|
||||||
|
####### ### ### # # # # ### ####### #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# ##### # # ##### ### # ### # # ### #
|
||||||
|
# # # # # # # # # # # # # #
|
||||||
|
# # # ### ### ### ### # ### ##### ###
|
||||||
|
# # # # # # # # #
|
||||||
|
# ####### ##### # ### ####### #######
|
||||||
|
# # # # # # #
|
||||||
|
# # ### ##### ############# ### #####
|
||||||
|
# # # # # # # # # #
|
||||||
|
### # # ######### # # # # # # # ### #
|
||||||
|
# # # # # # # # # #
|
||||||
|
# ##### ### ### # # ### # ### ##### #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# # ### ### # # # # ##### # # # # # #
|
||||||
|
# # # # # # # # # # # # # #
|
||||||
|
# ####### ### ######### ######### # #
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# # ######### # # # ##### # # # # # #
|
||||||
|
# # # # #
|
||||||
|
#####################################
|
41
2dgk_zad3/2dgk_zad3/assets/levels/level3.txt
Normal file
41
2dgk_zad3/2dgk_zad3/assets/levels/level3.txt
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#########################################
|
||||||
|
# # # # # # # #
|
||||||
|
# # ### # # ####### ### ####### ####### #
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# # # # # ##### ####### # ### # ### #####
|
||||||
|
# # # # # # # # # #
|
||||||
|
# # ### # ##### ##### ### ### # ##### # #
|
||||||
|
# # # # # # # # # #
|
||||||
|
### ######### ##### ####### ### ##### # #
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# ### # ### ### ##### # # ### ### # ### #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
### ### ####### # # # ####### # # # # # #
|
||||||
|
# # # # # # # # # # # # # # #
|
||||||
|
# ### # # ### ### # ### # # ### ##### ###
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# # # ### ##### ##### # ##### # # ### ###
|
||||||
|
# # # # # # # #
|
||||||
|
# ####### ### ### # # ######### # #######
|
||||||
|
# # # # # # # #
|
||||||
|
# ### ##### ### # ########### ######### #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# ##### # # ### ### ### ### # # # # ### #
|
||||||
|
# # # # # # # # # # # # #
|
||||||
|
# # ### # ### # ### # ##### ##### # # ###
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# ##### ####### ####### ### ##### # # # #
|
||||||
|
# # # # # # # # # # # # #
|
||||||
|
### ### ### ### # # ### ##### ####### # #
|
||||||
|
# # # # # # # # #
|
||||||
|
### ##### ##### ### ##### # ### ### # # #
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# ##### # ### ##### # # # ### ### ### # #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
##### # ### ##### ### # # # ### # # # ###
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# ##### ####### ####### # ##### ### # ###
|
||||||
|
# # # # # # # # # # #
|
||||||
|
# # # # ### ### # ### # ##### ### # # # #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
#########################################
|
BIN
2dgk_zad3/2dgk_zad3/assets/textures/P1.bmp
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/textures/P1.bmp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
2dgk_zad3/2dgk_zad3/assets/textures/P2.bmp
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/textures/P2.bmp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
2dgk_zad3/2dgk_zad3/assets/textures/arrow.bmp
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/textures/arrow.bmp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
2dgk_zad3/2dgk_zad3/assets/textures/exit.bmp
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/textures/exit.bmp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
2dgk_zad3/2dgk_zad3/assets/textures/wall.bmp
(Stored with Git LFS)
Normal file
BIN
2dgk_zad3/2dgk_zad3/assets/textures/wall.bmp
(Stored with Git LFS)
Normal file
Binary file not shown.
33
2dgk_zad3/2dgk_zad3/config.json
Normal file
33
2dgk_zad3/2dgk_zad3/config.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"Input": {
|
||||||
|
"Player1": {
|
||||||
|
"AxisMappings": [
|
||||||
|
{
|
||||||
|
"AxisName": "MoveX",
|
||||||
|
"Scale": 1.000000,
|
||||||
|
"Key": "D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"AxisName": "MoveX",
|
||||||
|
"Scale": -1.000000,
|
||||||
|
"Key": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"AxisName": "MoveX",
|
||||||
|
"Scale": 1.000000,
|
||||||
|
"Key": "Gamepad0_LeftX"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ActionMappings": [
|
||||||
|
{
|
||||||
|
"ActionName": "Jump",
|
||||||
|
"Key": "Space"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ActionName": "Jump",
|
||||||
|
"Key": "Gamepad0_A"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
2dgk_zad3/2dgk_zad3/resource.h
Normal file
14
2dgk_zad3/2dgk_zad3/resource.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Visual C++ generated include file.
|
||||||
|
// Used by 2dgk_zad3.rc
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
#endif
|
||||||
|
#endif
|
10
2dgk_zad3/2dgk_zad3/vcpkg.json
Normal file
10
2dgk_zad3/2dgk_zad3/vcpkg.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
||||||
|
"name": "dgk-zad3",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"dependencies": [
|
||||||
|
"sdl2",
|
||||||
|
"nlohmann-json",
|
||||||
|
"sdl2-ttf"
|
||||||
|
]
|
||||||
|
}
|
7
2dgk_zad3/readme.txt
Normal file
7
2dgk_zad3/readme.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
IDE: Microsoft Visual Studio 2022
|
||||||
|
Kompilator: Microsoft Visual C++
|
||||||
|
Biblioteki: SDL2, SDL2_ttf, nlohmann-json
|
||||||
|
|
||||||
|
Przetestowane pady: DualSense, DualShock 3 (ze sterownikiem/wrapperem XInputowym ScpToolkit), telefon Android (ze sterownikiem/wrapperem XInputowym HandyGamePad).
|
||||||
|
|
||||||
|
Uwaga: Do pobrania bibliotek projekt wykorzystuje vcpkg, menedżer bibliotek C++, w trybie Manifest. Należy go pobrać i skonfigurować zgodnie z instrukcją: https://github.com/microsoft/vcpkg#getting-started
|
Loading…
x
Reference in New Issue
Block a user