Added death animations.
This commit is contained in:
parent
bc3e2bf6b0
commit
964b02d256
@ -13,3 +13,5 @@ vi2d CONSTANT::TILE_SIZE={24,24};
|
|||||||
vi2d CONSTANT::WORLD_SIZE={64,64};
|
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 vi2d WORLD_SIZE;
|
||||||
|
|
||||||
static float SCROLL_BOUNDARY;
|
static float SCROLL_BOUNDARY;
|
||||||
|
|
||||||
|
static float DEATH_FADE_TIME;
|
||||||
};
|
};
|
19
olcCodeJam2023Entry/DeathAnimation.h
Normal file
19
olcCodeJam2023Entry/DeathAnimation.h
Normal file
@ -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();
|
||||||
|
};
|
34
olcCodeJam2023Entry/DeathAnimations.cpp
Normal file
34
olcCodeJam2023Entry/DeathAnimations.cpp
Normal file
@ -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;
|
||||||
|
}
|
@ -502,3 +502,7 @@ bool Unit::CanInteractWithAllies(){
|
|||||||
bool Unit::CanInteractWithEnemies(){
|
bool Unit::CanInteractWithEnemies(){
|
||||||
return enemyInteractable;
|
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);
|
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
||||||
bool CanInteractWithEnemies();
|
bool CanInteractWithEnemies();
|
||||||
bool CanInteractWithAllies();
|
bool CanInteractWithAllies();
|
||||||
|
Renderable&GetImage();
|
||||||
|
|
||||||
std::vector<bool>& operator <<=(const int n){
|
std::vector<bool>& operator <<=(const int n){
|
||||||
for(int i=0;i<GetMemorySize()-1;i++){
|
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<LeftShifter>(vf2d{128,128},IMAGES,true));
|
||||||
units.push_back(std::make_unique<RightShifter>(vf2d{129,129},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,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<MemorySwapper>(vf2d{131,131},IMAGES,true));
|
||||||
units.push_back(std::make_unique<Corrupter>(vf2d{132,132},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));
|
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->AttemptAttack(closestUnit,units);
|
||||||
u->_Update(this);
|
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);
|
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){
|
for(auto&u:units){
|
||||||
@ -337,6 +349,12 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
|||||||
for(auto&u:units){
|
for(auto&u:units){
|
||||||
u->Draw(game,IMAGES);
|
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){
|
for(auto&collectionPoint:collectionPoints){
|
||||||
collectionPoint->Update(this,*IMAGES[MATRIX]);
|
collectionPoint->Update(this,*IMAGES[MATRIX]);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "Unit.h"
|
#include "Unit.h"
|
||||||
#include "Constant.h"
|
#include "Constant.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
#include "DeathAnimation.h"
|
||||||
|
|
||||||
struct Letter{
|
struct Letter{
|
||||||
vf2d pos;
|
vf2d pos;
|
||||||
@ -27,6 +28,7 @@ class VirusAttack : public olc::PixelGameEngine
|
|||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<Unit>>units;
|
std::vector<std::shared_ptr<Unit>>units;
|
||||||
std::vector<std::unique_ptr<CollectionPoint>>collectionPoints;
|
std::vector<std::unique_ptr<CollectionPoint>>collectionPoints;
|
||||||
|
std::vector<std::unique_ptr<DeathAnimation>>deathAnimations;
|
||||||
|
|
||||||
std::map<Image,std::unique_ptr<Renderable>>IMAGES;
|
std::map<Image,std::unique_ptr<Renderable>>IMAGES;
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Constant.h" />
|
<ClInclude Include="Constant.h" />
|
||||||
|
<ClInclude Include="DeathAnimation.h" />
|
||||||
<ClInclude Include="Image.h" />
|
<ClInclude Include="Image.h" />
|
||||||
<ClInclude Include="olcPGEX_PopUpMenu.h" />
|
<ClInclude Include="olcPGEX_PopUpMenu.h" />
|
||||||
<ClInclude Include="olcPGEX_QuickGUI.h" />
|
<ClInclude Include="olcPGEX_QuickGUI.h" />
|
||||||
@ -150,6 +151,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Constant.cpp" />
|
<ClCompile Include="Constant.cpp" />
|
||||||
|
<ClCompile Include="DeathAnimations.cpp" />
|
||||||
<ClCompile Include="TileManager.cpp" />
|
<ClCompile Include="TileManager.cpp" />
|
||||||
<ClCompile Include="Unit.cpp" />
|
<ClCompile Include="Unit.cpp" />
|
||||||
<ClCompile Include="util.cpp" />
|
<ClCompile Include="util.cpp" />
|
||||||
|
@ -66,6 +66,9 @@
|
|||||||
<ClInclude Include="util.h">
|
<ClInclude Include="util.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="DeathAnimation.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="VirusAttack.cpp">
|
<ClCompile Include="VirusAttack.cpp">
|
||||||
@ -83,6 +86,9 @@
|
|||||||
<ClCompile Include="util.cpp">
|
<ClCompile Include="util.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="DeathAnimations.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="olcCodeJam2023Entry.rc">
|
<ResourceCompile Include="olcCodeJam2023Entry.rc">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user