parent
c345251fd0
commit
bf2ed34855
@ -0,0 +1,82 @@ |
||||
#define OLC_PGE_APPLICATION |
||||
#include "olcPixelGameEngine.h" |
||||
|
||||
#include "olcUTIL_Geometry2D.h" |
||||
|
||||
#define PI 3.14159 |
||||
using namespace olc; |
||||
|
||||
// Override base class with your custom functionality
|
||||
class Example : public olc::PixelGameEngine |
||||
{ |
||||
Decal*image; |
||||
vf2d pos; |
||||
float time; |
||||
float updateTimer; |
||||
float rot=0; |
||||
public: |
||||
Example() |
||||
{ |
||||
// Name your application
|
||||
sAppName = "Example"; |
||||
} |
||||
public: |
||||
bool OnUserCreate() override |
||||
{ |
||||
pos=GetScreenSize()/2; |
||||
image=new Decal(new Sprite("assets/avatar.png")); |
||||
return true; |
||||
} |
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override |
||||
{ |
||||
updateTimer-=fElapsedTime; |
||||
if(updateTimer<=0){ |
||||
updateTimer=0.5; |
||||
time+=0.6; |
||||
} |
||||
rot+=fElapsedTime; |
||||
pos=GetMousePos(); |
||||
//DrawRotatedDecal(pos,image,0,image->sprite->Size()/2);
|
||||
vf2d multiplier={0.5,0.5}; |
||||
float rotation=rot; |
||||
float scaleFactor=0.05; //How much to oscillate between the total scale.
|
||||
|
||||
multiplier.x*=(1-abs(sin(time))*scaleFactor); |
||||
multiplier.x*=(1-abs(cos(1.5*time))*scaleFactor); |
||||
geom2d::rect<float>imgSquare={pos-vf2d(image->sprite->Size()/2)*multiplier.x+vf2d{abs(sin(time))*scaleFactor*image->sprite->width*multiplier.x,0},vf2d(image->sprite->Size())*multiplier}; |
||||
for(int y=0;y<ScreenHeight();y+=24){ |
||||
for(int x=0;x<ScreenWidth();x+=24){ |
||||
geom2d::rect<float>square={{float(x),float(y)},{24,24}}; |
||||
if(geom2d::overlaps(square,imgSquare)){ |
||||
vf2d pos=square.pos; |
||||
pos.x+=std::max(0.f,imgSquare.pos.x-square.pos.x); |
||||
pos.y+=std::max(0.f,imgSquare.pos.y-square.pos.y); |
||||
vf2d offset={square.pos.x-imgSquare.pos.x+std::max(0.f,imgSquare.pos.x-square.pos.x),square.pos.y-imgSquare.pos.y+std::max(0.f,imgSquare.pos.y-square.pos.y)}; |
||||
vf2d size={std::min(24.f,imgSquare.right().start.x-square.pos.x),std::min(24.f,imgSquare.bottom().start.y-square.pos.y)}; |
||||
vf2d finalOffset=offset/multiplier; |
||||
vf2d finalSize=size/multiplier; |
||||
finalOffset.y=image->sprite->height-finalOffset.y; |
||||
finalSize.y*=-1; |
||||
geom2d::line<float>lineTo{imgSquare.middle(),square.middle()}; |
||||
float angleTo=lineTo.vector().polar().y; |
||||
vf2d initialPos=vf2d{cos(rotation)*lineTo.length(),sin(rotation)*lineTo.length()}; |
||||
vf2d newPos={initialPos.x*cos(angleTo)-initialPos.y*sin(angleTo),initialPos.x*sin(angleTo)+initialPos.y*cos(angleTo)}; |
||||
DrawPartialRotatedDecal(imgSquare.middle()+newPos,image,rotation,{12,12},finalOffset,finalSize,vf2d{multiplier.x,multiplier.y*-1}); |
||||
DrawRectDecal(square.pos,square.size,RED); |
||||
}else{ |
||||
DrawRectDecal(square.pos,square.size); |
||||
} |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
}; |
||||
|
||||
int main() |
||||
{ |
||||
Example demo; |
||||
if (demo.Construct(1280, 720, 1, 1)) |
||||
demo.Start(); |
||||
return 0; |
||||
} |
@ -0,0 +1,143 @@ |
||||
<?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>{88ad8db5-1417-429e-acf4-1d0551e43bdf}</ProjectGuid> |
||||
<RootNamespace>ReflectionPrototype</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" /> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</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> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</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> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemGroup> |
||||
<ClCompile Include="ReflectionPrototype.cpp" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ClInclude Include="olcPixelGameEngine.h" /> |
||||
<ClInclude Include="olcUTIL_Geometry2D.h" /> |
||||
</ItemGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
<ImportGroup Label="ExtensionTargets"> |
||||
</ImportGroup> |
||||
</Project> |
After Width: | Height: | Size: 715 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue