Add project files.

master
sigonasr2 1 year ago
parent 47c8f98c89
commit 7b81f4aad4
  1. 31
      ShooterExample.sln
  2. BIN
      ShooterExample/8-bit Aliens.png
  3. 220
      ShooterExample/ShooterExample.cpp
  4. 138
      ShooterExample/ShooterExample.vcxproj
  5. 27
      ShooterExample/ShooterExample.vcxproj.filters
  6. 6695
      ShooterExample/olcPixelGameEngine.h

@ -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}") = "ShooterExample", "ShooterExample\ShooterExample.vcxproj", "{BFEFE123-590A-4768-8E34-8FAD8DFFE223}"
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
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Debug|x64.ActiveCfg = Debug|x64
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Debug|x64.Build.0 = Debug|x64
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Debug|x86.ActiveCfg = Debug|Win32
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Debug|x86.Build.0 = Debug|Win32
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Release|x64.ActiveCfg = Release|x64
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Release|x64.Build.0 = Release|x64
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Release|x86.ActiveCfg = Release|Win32
{BFEFE123-590A-4768-8E34-8FAD8DFFE223}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ABF6C5B6-2E14-4C67-B825-539C3E2B130A}
EndGlobalSection
EndGlobal

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,220 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
struct Rect{
int x,y,w,h;
};
class Enemy{
olc::vf2d pos;
Rect*sprite;
int health;
public:
Enemy(olc::vi2d pos,Rect*sprite,int health=1)
:pos(pos),sprite(sprite),health(health){};
olc::vf2d GetPos(){
return pos;
}
olc::vi2d GetSprPos(){
return {sprite->x,sprite->y};
}
olc::vi2d GetSprSize(){
return {sprite->w,sprite->h};
}
void Hurt(int damage=1){
health-=damage;
}
bool IsAlive(){
return health>0;
}
void Move(olc::vi2d moveAmt){
pos+=moveAmt;
}
olc::Pixel GetColor(){
if(health>1){
return {255,96,96};
} else {
return olc::GREEN;
}
}
};
class Player{
olc::vf2d pos;
Rect*sprite;
float lastShootTime=0;
public:
Player(olc::vi2d pos,Rect*sprite)
:pos(pos),sprite(sprite){}
olc::vf2d GetPos(){
return pos;
}
olc::vi2d GetSprPos(){
return {sprite->x,sprite->y};
}
olc::vi2d GetSprSize(){
return {sprite->w,sprite->h};
}
void Update(float fElapsedTime){
lastShootTime=std::max(lastShootTime-fElapsedTime,0.f);
}
bool CanShoot(){
return lastShootTime==0;
}
void OnShoot(){
lastShootTime=0.5;
}
void Move(olc::vf2d moveAmt){
pos+=moveAmt;
}
};
class Bullet{
olc::vf2d pos;
bool alive=true;
public:
Bullet(olc::vi2d pos)
:pos(pos){}
olc::vf2d GetPos(){
return pos;
}
void Update(float fElapsedTime){
pos+={0,-72*fElapsedTime};
}
bool CollidesWith(Enemy&enemy){
float dist2=pow(enemy.GetPos().x+enemy.GetSprSize().x-pos.x,2)+pow(enemy.GetPos().y+enemy.GetSprSize().y-pos.y,2);
return dist2<64;
}
void KillBullet(){
alive=false;
}
bool IsAlive(){
return alive||pos.y<0;
}
};
// Override base class with your custom functionality
class ShooterExample : public olc::PixelGameEngine
{
public:
ShooterExample()
{
// Name your application
sAppName = "Shooter Example";
}
public:
olc::Renderable spriteSheet;
Rect enemyA={5,21, 11,9};
Rect enemyB={19,22, 12,6};
Rect enemyC={34,20, 11,8};
Rect ship={35,6, 11,7};
std::vector<Enemy>enemies;
std::vector<Bullet>bullets;
Player player{{ScreenWidth()/2,ScreenHeight()-36},&ship};
int alienShift=0;
bool movingRight=true;
float lastShiftTime=0;
bool OnUserCreate() override
{
spriteSheet.Load("8-bit Aliens.png");
olc::vf2d alienOffset={24,38};
for (int y=0;y<4;y++){
for (int x=0;x<12;x++){
switch(rand()%3){
case 0:{
Enemy enemy{alienOffset+olc::vi2d{x*16,y*12},&enemyA};
enemies.push_back(enemy);
}break;
case 1:{
Enemy enemy{alienOffset+olc::vi2d{x*16,y*12},&enemyB};
enemies.push_back(enemy);
}break;
case 2:{
Enemy enemy{alienOffset+olc::vi2d{x*16,y*12},&enemyC,2};
enemies.push_back(enemy);
}break;
}
}
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
//Update Game Objects
player.Update(fElapsedTime);
for(Bullet&b:bullets){
b.Update(fElapsedTime);
}
lastShiftTime+=fElapsedTime;
if(lastShiftTime>0.8){
lastShiftTime-=0.8;
if(abs(alienShift)>=3){
alienShift+=movingRight?-1:1;
movingRight=!movingRight;
for(Enemy&e:enemies){
e.Move({0,12});
}
} else
if(movingRight){
alienShift++;
for(Enemy&e:enemies){
e.Move({12,0});
}
} else {
alienShift--;
for(Enemy&e:enemies){
e.Move({-12,0});
}
}
}
if(GetKey(olc::SPACE).bHeld){
if(player.CanShoot()){
player.OnShoot();
bullets.push_back({player.GetPos()+player.GetSprSize()});
}
}
if(GetKey(olc::LEFT).bHeld){
player.Move({-48*fElapsedTime,0});
}
if(GetKey(olc::RIGHT).bHeld){
player.Move({48*fElapsedTime,0});
}
// Called once per frame, draws random coloured pixels
Clear(olc::BLACK);
for(Enemy&e:enemies){
for(Bullet&b:bullets){
if(!b.IsAlive())continue;
if(b.CollidesWith(e)){
e.Hurt();
b.KillBullet();
}
DrawLineDecal(b.GetPos(),b.GetPos()+olc::vi2d{0,-4},olc::WHITE);
}
DrawPartialDecal(e.GetPos()+e.GetSprSize()/2,e.GetSprSize(),spriteSheet.Decal(),e.GetSprPos(),e.GetSprSize(),e.GetColor());
}
DrawPartialDecal(player.GetPos()+player.GetSprSize()/2,player.GetSprSize(),spriteSheet.Decal(),player.GetSprPos(),player.GetSprSize());
enemies.erase(std::remove_if(enemies.begin(),enemies.end(),[](Enemy&e){return !e.IsAlive();}),enemies.end());
bullets.erase(std::remove_if(bullets.begin(),bullets.end(),[](Bullet&b){return !b.IsAlive();}),bullets.end());
return true;
}
};
int main()
{
ShooterExample 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>{bfefe123-590a-4768-8e34-8fad8dffe223}</ProjectGuid>
<RootNamespace>ShooterExample</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="ShooterExample.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="ShooterExample.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save