Added death animations.

CorrectiveAction
sigonasr2 1 year ago
parent bc3e2bf6b0
commit 964b02d256
  1. 4
      olcCodeJam2023Entry/Constant.cpp
  2. 2
      olcCodeJam2023Entry/Constant.h
  3. 19
      olcCodeJam2023Entry/DeathAnimation.h
  4. 34
      olcCodeJam2023Entry/DeathAnimations.cpp
  5. 4
      olcCodeJam2023Entry/Unit.cpp
  6. 1
      olcCodeJam2023Entry/Unit.h
  7. 18
      olcCodeJam2023Entry/VirusAttack.cpp
  8. 2
      olcCodeJam2023Entry/VirusAttack.h
  9. 2
      olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj
  10. 6
      olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters

@ -12,4 +12,6 @@ vf2d CONSTANT::UNSELECTED={-99,-99};
vi2d CONSTANT::TILE_SIZE={24,24};
vi2d CONSTANT::WORLD_SIZE={64,64};
float CONSTANT::SCROLL_BOUNDARY=36;
float CONSTANT::SCROLL_BOUNDARY=36;
float CONSTANT::DEATH_FADE_TIME=1;

@ -18,4 +18,6 @@ public:
static vi2d WORLD_SIZE;
static float SCROLL_BOUNDARY;
static float DEATH_FADE_TIME;
};

@ -0,0 +1,19 @@
#pragma once
#include "olcPixelGameEngine.h"
#include "Constant.h"
#include "olcPGEX_TransformedView.h"
class DeathAnimation{
vf2d pos;
Renderable img;
Renderable&originalImg;
Renderable&matrixImg;
vf2d randomOffset;
float fadeTimer=CONSTANT::DEATH_FADE_TIME;
bool friendly;
public:
DeathAnimation(PixelGameEngine*pge,vf2d pos,Renderable&unitImg,Renderable&matrixImg,bool friendly);
void Update(float fElapsedTime);
void Draw(TileTransformedView&game,PixelGameEngine*pge);
bool IsDone();
};

@ -0,0 +1,34 @@
#include "DeathAnimation.h"
DeathAnimation::DeathAnimation(PixelGameEngine*pge,vf2d pos,Renderable&unitImg,Renderable&matrixImg,bool friendly)
:pos(pos),matrixImg(matrixImg),originalImg(unitImg),friendly(friendly),randomOffset(rand()%168,rand()%168){
img.Create(unitImg.Sprite()->width,unitImg.Sprite()->height);
pge->SetDrawTarget(img.Sprite());
pge->DrawSprite({0,0},unitImg.Sprite());
pge->SetDrawTarget(nullptr);
img.Decal()->Update();
}
void DeathAnimation::Update(float fElapsedTime){
fadeTimer=std::max(0.f,fadeTimer-fElapsedTime);
}
void DeathAnimation::Draw(TileTransformedView&game,PixelGameEngine*pge){
pge->SetDrawTarget(img.Sprite());
pge->Clear(BLANK);
for(int y=0;y<img.Sprite()->height;y++){
for(int x=0;x<img.Sprite()->width;x++){
Pixel col=originalImg.Sprite()->GetPixel(x,y);
if(col.a==255&&col.r<=(CONSTANT::DEATH_FADE_TIME-fadeTimer)*255){
pge->Draw(x,y,matrixImg.Sprite()->GetPixel(x+randomOffset.x,y+randomOffset.y));
} else {
pge->Draw(x,y,originalImg.Sprite()->GetPixel(x+randomOffset.x,y+randomOffset.y));
}
}
}
img.Decal()->Update();
pge->SetDrawTarget(nullptr);
game.DrawRotatedDecal(pos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255,uint8_t((fadeTimer/CONSTANT::DEATH_FADE_TIME)*255)}:Pixel{255,192,192,uint8_t((fadeTimer/CONSTANT::DEATH_FADE_TIME)*255)});
}
bool DeathAnimation::IsDone(){
return fadeTimer==0;
}

@ -501,4 +501,8 @@ bool Unit::CanInteractWithAllies(){
bool Unit::CanInteractWithEnemies(){
return enemyInteractable;
}
Renderable&Unit::GetImage(){
return img;
}

@ -58,6 +58,7 @@ public:
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
bool CanInteractWithEnemies();
bool CanInteractWithAllies();
Renderable&GetImage();
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){

@ -51,6 +51,7 @@ bool VirusAttack::OnUserCreate(){
units.push_back(std::make_unique<LeftShifter>(vf2d{128,128},IMAGES,true));
units.push_back(std::make_unique<RightShifter>(vf2d{129,129},IMAGES,true));
units.push_back(std::make_unique<BitRestorer>(vf2d{130,130},IMAGES,true));
units.push_back(std::make_unique<BitRestorer>(vf2d{130,140},IMAGES,true));
units.push_back(std::make_unique<MemorySwapper>(vf2d{131,131},IMAGES,true));
units.push_back(std::make_unique<Corrupter>(vf2d{132,132},IMAGES,true));
units.push_back(std::make_unique<MemoryAllocator>(vf2d{133,133},IMAGES,true));
@ -328,6 +329,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
u->AttemptAttack(closestUnit,units);
u->_Update(this);
}
std::erase_if(units,[&](std::shared_ptr<Unit>u){
if(u->GetHealth()==0){
deathAnimations.emplace_back(std::make_unique<DeathAnimation>(this,u->GetPos(),u->GetImage(),*IMAGES[MATRIX],u->IsFriendly()));
return true;
} else {
return false;
}
});
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN);
for(auto&u:units){
@ -337,6 +349,12 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
for(auto&u:units){
u->Draw(game,IMAGES);
}
for(auto&deadUnit:deathAnimations){
deadUnit->Update(fElapsedTime);
deadUnit->Draw(game,this);
}
std::erase_if(deathAnimations,[](auto&u){return u->IsDone();});
for(auto&collectionPoint:collectionPoints){
collectionPoint->Update(this,*IMAGES[MATRIX]);

@ -4,6 +4,7 @@
#include "Unit.h"
#include "Constant.h"
#include "Image.h"
#include "DeathAnimation.h"
struct Letter{
vf2d pos;
@ -27,6 +28,7 @@ class VirusAttack : public olc::PixelGameEngine
private:
std::vector<std::shared_ptr<Unit>>units;
std::vector<std::unique_ptr<CollectionPoint>>collectionPoints;
std::vector<std::unique_ptr<DeathAnimation>>deathAnimations;
std::map<Image,std::unique_ptr<Renderable>>IMAGES;

@ -132,6 +132,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Constant.h" />
<ClInclude Include="DeathAnimation.h" />
<ClInclude Include="Image.h" />
<ClInclude Include="olcPGEX_PopUpMenu.h" />
<ClInclude Include="olcPGEX_QuickGUI.h" />
@ -150,6 +151,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="Constant.cpp" />
<ClCompile Include="DeathAnimations.cpp" />
<ClCompile Include="TileManager.cpp" />
<ClCompile Include="Unit.cpp" />
<ClCompile Include="util.cpp" />

@ -66,6 +66,9 @@
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DeathAnimation.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="VirusAttack.cpp">
@ -83,6 +86,9 @@
<ClCompile Include="util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DeathAnimations.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="olcCodeJam2023Entry.rc">

Loading…
Cancel
Save