Add project files.

master
sigonasr2 1 year ago
parent c6a4207675
commit 00e9bfe27b
  1. 31
      ShooterGame.sln
  2. 192
      ShooterGame/ShooterGame.cpp
  3. 138
      ShooterGame/ShooterGame.vcxproj
  4. 27
      ShooterGame/ShooterGame.vcxproj.filters
  5. 6695
      ShooterGame/olcPixelGameEngine.h
  6. BIN
      ShooterGame/tilesheet.png

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShooterGame", "ShooterGame\ShooterGame.vcxproj", "{0C2682A1-988B-4C60-8BA1-157CD1E2637A}"
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
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Debug|x64.ActiveCfg = Debug|x64
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Debug|x64.Build.0 = Debug|x64
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Debug|x86.ActiveCfg = Debug|Win32
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Debug|x86.Build.0 = Debug|Win32
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Release|x64.ActiveCfg = Release|x64
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Release|x64.Build.0 = Release|x64
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Release|x86.ActiveCfg = Release|Win32
{0C2682A1-988B-4C60-8BA1-157CD1E2637A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58E72BF6-4430-4DB9-B280-270B333F31C0}
EndGlobalSection
EndGlobal

@ -0,0 +1,192 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
struct Rect{
float x,y,w,h;
};
struct Enemy{
olc::vf2d pos;
Rect alienSpr;
int health=1;
bool alive=true;
//Returns true if the enemy has died.
void Hurt(int damage=1){
health-=damage;
if(health<=0){
alive=false;
}
}
};
struct Bullet{
olc::vf2d pos;
bool alive=true;
void Update(float fElapsedTime){
pos.y-=96*fElapsedTime;
}
void Kill(){
alive=false;
}
};
class ShooterGame : public olc::PixelGameEngine
{
Rect alien1={5,22, 11,9};
Rect alien2={19,22, 12,6};
Rect alien3={34,20, 11,8};
Rect ship={35,6, 11,7};
olc::Decal*tilesheet;
std::vector<Enemy>enemies;
std::vector<Bullet>bullets;
olc::vf2d playerPos={128,200};
float playerShotTimer=0;
int enemyMoveAmount=0;
bool movingRight=true;
float enemyMoveTimer=0;
void DrawSubSprite(olc::vi2d pos,Rect sprite,olc::Pixel color=olc::WHITE){
DrawPartialDecal(pos-olc::vf2d{sprite.w,sprite.h}/2,{sprite.w,sprite.h},tilesheet,{sprite.x,sprite.y},{sprite.w,sprite.h},color);
}
public:
ShooterGame()
{
// Name your application
sAppName = "Shooter Game";
}
public:
bool OnUserCreate() override
{
tilesheet = new olc::Decal(new olc::Sprite("tilesheet.png"));
for(int y=0;y<4;y++){
for(int x=0;x<12;x++){
int alienType = rand()%3; //Choose an alien number between 0-2
Rect alienSpr;
int alienHealth=1;
switch(alienType){
case 0:{
alienSpr=alien1;
}break;
case 1:{
alienSpr=alien2;
}break;
case 2:{
alienSpr=alien3;
alienHealth=3;
}break;
}
enemies.push_back({{24.f+16*x,24.f+12*y},alienSpr,alienHealth});
}
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
Clear(olc::BLACK);
if(enemyMoveTimer==0){
if(movingRight){
if(enemyMoveAmount>=3){
movingRight=false;
for(Enemy&enemy:enemies){
enemy.pos.y+=12;
}
} else {
enemyMoveAmount++;
for(Enemy&enemy:enemies){
enemy.pos.x+=16;
}
}
}
else
{
if(enemyMoveAmount<0){
movingRight=true;
for(Enemy&enemy:enemies){
enemy.pos.y+=12;
}
} else {
enemyMoveAmount--;
for(Enemy&enemy:enemies){
enemy.pos.x-=16;
}
}
}
enemyMoveTimer=0.8;
}
enemyMoveTimer=std::max(enemyMoveTimer-fElapsedTime,0.f);
for(Bullet&bullet:bullets){
bullet.Update(fElapsedTime);
for(Enemy&enemy:enemies){
float distanceFromEnemy=sqrt(pow(bullet.pos.x-enemy.pos.x,2)+pow(bullet.pos.y-enemy.pos.y,2));
if(distanceFromEnemy<=7){
enemy.Hurt(1);
bullet.Kill();
}
}
}
enemies.erase(std::remove_if(enemies.begin(),enemies.end(),[](Enemy&enemy){return !enemy.alive;}),enemies.end());
bullets.erase(std::remove_if(bullets.begin(),bullets.end(),[](Bullet&bullet){return !bullet.alive;}),bullets.end());
playerShotTimer=std::max(playerShotTimer-fElapsedTime,0.f);
if(GetKey(olc::A).bHeld){
playerPos.x-=48*fElapsedTime;
}
if(GetKey(olc::D).bHeld){
playerPos.x+=48*fElapsedTime;
}
if(GetKey(olc::SPACE).bHeld){
if(playerShotTimer==0){
bullets.push_back({playerPos});
playerShotTimer=0.4;
}
}
for(Enemy&enemy:enemies){
if(enemy.health>2){
DrawSubSprite(enemy.pos,enemy.alienSpr,olc::RED);
}else
if(enemy.health>1){
DrawSubSprite(enemy.pos,enemy.alienSpr,olc::YELLOW);
} else {
DrawSubSprite(enemy.pos,enemy.alienSpr,olc::GREEN);
}
}
for(Bullet&bullet:bullets){
DrawLine(bullet.pos,bullet.pos+olc::vi2d{0,-4});
}
DrawSubSprite(playerPos,ship);
return true;
}
};
int main()
{
ShooterGame demo;
if (demo.Construct(256, 240, 4, 4))
demo.Start();
return 0;
}

@ -0,0 +1,138 @@
<?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>{0c2682a1-988b-4c60-8ba1-157cd1e2637a}</ProjectGuid>
<RootNamespace>ShooterGame</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>
</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>
</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>
</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>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="olcPixelGameEngine.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ShooterGame.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,27 @@
<?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>
<ClInclude Include="olcPixelGameEngine.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ShooterGame.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Loading…
Cancel
Save