Add resouce bar, move collection points into its own class.
This commit is contained in:
parent
6bed39f178
commit
a32a998061
26
olcCodeJam2023Entry/CollectionPoint.cpp
Normal file
26
olcCodeJam2023Entry/CollectionPoint.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "CollectionPoint.h"
|
||||
#include "util.h"
|
||||
|
||||
CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type)
|
||||
:pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){
|
||||
img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height);
|
||||
pge->SetDrawTarget(img.Sprite());
|
||||
pge->Clear(BLANK);
|
||||
pge->DrawSprite({0,0},collectionPointImg.Sprite());
|
||||
pge->SetDrawTarget(nullptr);
|
||||
img.Decal()->Update();
|
||||
}
|
||||
|
||||
void CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){
|
||||
pge->SetDrawTarget(img.Sprite());
|
||||
for(int y=0;y<img.Sprite()->height;y++){
|
||||
for(int x=0;x<img.Sprite()->width;x++){
|
||||
Pixel col=originalCollectionPointImg->GetPixel(x,y);
|
||||
if(col==WHITE){
|
||||
pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
img.Decal()->Update();
|
||||
pge->SetDrawTarget(nullptr);
|
||||
}
|
15
olcCodeJam2023Entry/CollectionPoint.h
Normal file
15
olcCodeJam2023Entry/CollectionPoint.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "MemoryType.h"
|
||||
|
||||
class CollectionPoint{
|
||||
public:
|
||||
vf2d pos;
|
||||
Renderable img;
|
||||
Sprite*originalCollectionPointImg;
|
||||
MemoryType type;
|
||||
vf2d randomOffset;
|
||||
float rot;
|
||||
CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type);
|
||||
void Update(PixelGameEngine*pge,Renderable&matrixImg);
|
||||
};
|
@ -30,5 +30,6 @@ enum Image{
|
||||
PRC_ICON,
|
||||
RNG_ICON,
|
||||
SPD_ICON,
|
||||
RESOURCE,
|
||||
};
|
||||
|
||||
|
9
olcCodeJam2023Entry/MemoryType.h
Normal file
9
olcCodeJam2023Entry/MemoryType.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
enum MemoryType{
|
||||
HEALTH,
|
||||
RANGE,
|
||||
ATKSPD,
|
||||
MOVESPD,
|
||||
PROCEDURE
|
||||
};
|
@ -8,20 +8,14 @@
|
||||
#include "olcPGEX_AudioSource.h"
|
||||
#include "util.h"
|
||||
#include "DebuffIcon.h"
|
||||
#include "CollectionPoint.h"
|
||||
#include "MemoryType.h"
|
||||
|
||||
struct Marker{
|
||||
size_t index;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
enum MemoryType{
|
||||
HEALTH,
|
||||
RANGE,
|
||||
ATKSPD,
|
||||
MOVESPD,
|
||||
PROCEDURE
|
||||
};
|
||||
|
||||
struct Memory{
|
||||
MemoryType type;
|
||||
int size;
|
||||
@ -126,6 +120,7 @@ private:
|
||||
bool enemyInteractable=true;
|
||||
float lineShift=0;
|
||||
void ApplyMatrixEffect(Renderable&r);
|
||||
std::weak_ptr<CollectionPoint>attachedPoint;
|
||||
};
|
||||
|
||||
struct BasicUnit:Unit{
|
||||
|
@ -46,6 +46,7 @@ void VirusAttack::InitializeImages(){
|
||||
LoadImage(PRC_ICON,"assets/prc_icon.png");
|
||||
LoadImage(RNG_ICON,"assets/rng_icon.png");
|
||||
LoadImage(SPD_ICON,"assets/spd_icon.png");
|
||||
LoadImage(RESOURCE,"assets/material.png");
|
||||
}
|
||||
|
||||
bool VirusAttack::OnUserCreate(){
|
||||
@ -415,6 +416,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
|
||||
DrawSelectionRectangle();
|
||||
RenderFogOfWar();
|
||||
GradientFillRectDecal({0,0},{float(ScreenWidth()),12.f},BLACK,{VERY_DARK_BLUE.r,VERY_DARK_BLUE.g,VERY_DARK_BLUE.b,128},{VERY_DARK_BLUE.r,VERY_DARK_BLUE.g,VERY_DARK_BLUE.b,128},BLACK);
|
||||
DrawRectDecal({0,0},{float(ScreenWidth()),12.f},{3, 194, 252});
|
||||
auto DrawResourceDisplay=[&](int index,int resourceValue,Pixel col){
|
||||
DrawDecal({6.f+index*42,1.f},IMAGES[RESOURCE]->Decal(),{1,1},col);
|
||||
DrawShadowStringDecal({6.f+index*42+20,2.f},std::to_string(resourceValue),col,BLACK);
|
||||
};
|
||||
DrawResourceDisplay(0,player_resources.health,CONSTANT::HEALTH_COLOR);
|
||||
DrawResourceDisplay(1,player_resources.atkSpd,CONSTANT::ATKSPD_COLOR);
|
||||
DrawResourceDisplay(2,player_resources.moveSpd,CONSTANT::MOVESPD_COLOR);
|
||||
DrawResourceDisplay(3,player_resources.range,CONSTANT::RANGE_COLOR);
|
||||
DrawResourceDisplay(4,player_resources.procedure,CONSTANT::PROCEDURE_COLOR);
|
||||
|
||||
DrawMinimap();
|
||||
|
||||
@ -438,30 +450,6 @@ void VirusAttack::RenderFogOfWar(){
|
||||
}
|
||||
}
|
||||
|
||||
VirusAttack::CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type)
|
||||
:pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){
|
||||
img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height);
|
||||
pge->SetDrawTarget(img.Sprite());
|
||||
pge->Clear(BLANK);
|
||||
pge->DrawSprite({0,0},collectionPointImg.Sprite());
|
||||
pge->SetDrawTarget(nullptr);
|
||||
img.Decal()->Update();
|
||||
}
|
||||
|
||||
void VirusAttack::CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){
|
||||
pge->SetDrawTarget(img.Sprite());
|
||||
for(int y=0;y<img.Sprite()->height;y++){
|
||||
for(int x=0;x<img.Sprite()->width;x++){
|
||||
Pixel col=originalCollectionPointImg->GetPixel(x,y);
|
||||
if(col==WHITE){
|
||||
pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
img.Decal()->Update();
|
||||
pge->SetDrawTarget(nullptr);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
VirusAttack app;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "olcPGEX_AudioSource.h"
|
||||
#include "Sound.h"
|
||||
#include "DebuffIcon.h"
|
||||
#include "CollectionPoint.h"
|
||||
|
||||
struct Letter{
|
||||
vf2d pos;
|
||||
@ -16,19 +17,16 @@ struct Letter{
|
||||
char c;
|
||||
};
|
||||
|
||||
struct Resources{
|
||||
int health=0;
|
||||
int atkSpd=0;
|
||||
int moveSpd=0;
|
||||
int range=0;
|
||||
int procedure=0;
|
||||
};
|
||||
|
||||
class VirusAttack : public olc::PixelGameEngine
|
||||
{
|
||||
class CollectionPoint{
|
||||
public:
|
||||
vf2d pos;
|
||||
Renderable img;
|
||||
Sprite*originalCollectionPointImg;
|
||||
MemoryType type;
|
||||
vf2d randomOffset;
|
||||
float rot;
|
||||
CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type);
|
||||
void Update(PixelGameEngine*pge,Renderable&matrixImg);
|
||||
};
|
||||
private:
|
||||
std::vector<std::shared_ptr<Unit>>units;
|
||||
std::vector<std::unique_ptr<CollectionPoint>>collectionPoints;
|
||||
@ -41,6 +39,8 @@ private:
|
||||
olcPGEX_AudioListener AL;
|
||||
Audio*bgm;
|
||||
|
||||
Resources player_resources,enemy_resources;
|
||||
|
||||
TileTransformedView game;
|
||||
|
||||
float matrixTimer=0;
|
||||
|
BIN
olcCodeJam2023Entry/assets/material.png
Normal file
BIN
olcCodeJam2023Entry/assets/material.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 695 B |
@ -139,10 +139,12 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CollectionPoint.h" />
|
||||
<ClInclude Include="Constant.h" />
|
||||
<ClInclude Include="DeathAnimation.h" />
|
||||
<ClInclude Include="DebuffIcon.h" />
|
||||
<ClInclude Include="Image.h" />
|
||||
<ClInclude Include="MemoryType.h" />
|
||||
<ClInclude Include="olcPGEX_AudioListener.h" />
|
||||
<ClInclude Include="olcPGEX_AudioSource.h" />
|
||||
<ClInclude Include="olcPGEX_PopUpMenu.h" />
|
||||
@ -162,6 +164,7 @@
|
||||
<ClInclude Include="VirusAttack.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CollectionPoint.cpp" />
|
||||
<ClCompile Include="Constant.cpp" />
|
||||
<ClCompile Include="DeathAnimations.cpp" />
|
||||
<ClCompile Include="DebuffIcon.cpp" />
|
||||
|
@ -81,6 +81,12 @@
|
||||
<ClInclude Include="DebuffIcon.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CollectionPoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MemoryType.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="VirusAttack.cpp">
|
||||
@ -104,6 +110,9 @@
|
||||
<ClCompile Include="DebuffIcon.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CollectionPoint.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="olcCodeJam2023Entry.rc">
|
||||
|
@ -1128,6 +1128,8 @@ namespace olc
|
||||
// Draws a multiline string as a decal, with tiniting and scaling
|
||||
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
void DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
// Draws a single shaded filled rectangle as a decal
|
||||
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
|
||||
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
|
||||
@ -1142,6 +1144,8 @@ namespace olc
|
||||
void DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p = olc::WHITE);
|
||||
void DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawRotatedShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
void DrawRotatedShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
// Clears entire draw target to Pixel
|
||||
void Clear(Pixel p);
|
||||
// Clears the rendering back buffer
|
||||
@ -3261,6 +3265,54 @@ namespace olc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawStringDecal(pos, sText, col,scale);
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawStringPropDecal(pos, sText, col,scale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PixelGameEngine::DrawRotatedShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawRotatedStringDecal(pos+vf2d{x,y}, sText,fAngle,center,shadowCol,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawRotatedStringDecal(pos, sText,fAngle,center,col,scale);
|
||||
}
|
||||
void PixelGameEngine::DrawRotatedShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawRotatedStringPropDecal(pos+vf2d{x,y}, sText,fAngle,center,shadowCol,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawRotatedStringPropDecal(pos, sText,fAngle,center,col,scale);
|
||||
}
|
||||
|
||||
// Thanks Oso-Grande/Sopadeoso For these awesom and stupidly clever Text Rotation routines... duh XD
|
||||
void PixelGameEngine::DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user