Refactored how images are stored.
This commit is contained in:
parent
342bb8a5c9
commit
1d8f42283b
@ -9,8 +9,5 @@ Pixel CONSTANT::PROCEDURE_COLOR={212, 11, 162};
|
||||
|
||||
vf2d CONSTANT::UNSELECTED={-99,-99};
|
||||
|
||||
Renderable CONSTANT::VIRUS_IMG1;
|
||||
Renderable CONSTANT::SELECTION_CIRCLE;
|
||||
|
||||
vi2d CONSTANT::TILE_SIZE={24,24};
|
||||
vi2d CONSTANT::WORLD_SIZE={64,64};
|
@ -12,8 +12,6 @@ public:
|
||||
|
||||
static vf2d UNSELECTED;
|
||||
|
||||
static Renderable VIRUS_IMG1,SELECTION_CIRCLE;
|
||||
|
||||
static vi2d TILE_SIZE;
|
||||
static vi2d WORLD_SIZE;
|
||||
};
|
12
olcCodeJam2023Entry/Image.h
Normal file
12
olcCodeJam2023Entry/Image.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
enum Image{
|
||||
TILE,
|
||||
MINIMAP_HUD,
|
||||
OUTLINE,
|
||||
MINIMAP_OUTLINE,
|
||||
VIRUS_IMG1,
|
||||
SELECTION_CIRCLE
|
||||
};
|
||||
|
@ -68,14 +68,14 @@ Unit::Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly)
|
||||
|
||||
|
||||
|
||||
void Unit::Draw(TileTransformedView&game){
|
||||
void Unit::Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
|
||||
game.DrawRotatedDecal(ghostPos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192});
|
||||
if(IsSelected()){
|
||||
game.DrawRotatedDecal(ghostPos,CONSTANT::SELECTION_CIRCLE.Decal(),0,CONSTANT::SELECTION_CIRCLE.Sprite()->Size()/2,vf2d(img.Sprite()->Size())/CONSTANT::SELECTION_CIRCLE.Sprite()->Size(),WHITE);
|
||||
game.DrawRotatedDecal(ghostPos,IMAGES[SELECTION_CIRCLE]->Decal(),0,IMAGES[SELECTION_CIRCLE]->Sprite()->Size()/2,vf2d(img.Sprite()->Size())/IMAGES[SELECTION_CIRCLE]->Sprite()->Size(),WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::DrawHud(TileTransformedView&game){
|
||||
void Unit::DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
|
||||
int initialBarX=ghostPos.x-GetMemorySize()/2*CONSTANT::BAR_SQUARE_SIZE.x;
|
||||
int initialBarY=ghostPos.y-CONSTANT::BAR_SQUARE_SIZE.y-img.Sprite()->height/2-2;
|
||||
Pixel col=0;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include "Constant.h"
|
||||
#include "Image.h"
|
||||
|
||||
struct Marker{
|
||||
size_t index;
|
||||
@ -35,8 +36,8 @@ public:
|
||||
std::vector<bool>ghostMemory;
|
||||
void Update(float fElapsedTime);
|
||||
virtual void Attack(Unit&victim)=0;
|
||||
virtual void Draw(TileTransformedView&game);
|
||||
virtual void DrawHud(TileTransformedView&game);
|
||||
virtual void Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
||||
virtual void DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
||||
bool IsFriendly();
|
||||
bool IsSelected();
|
||||
void Select();
|
||||
|
@ -12,23 +12,33 @@ VirusAttack::VirusAttack()
|
||||
sAppName = "olcCodeJam 2023 Entry";
|
||||
}
|
||||
|
||||
void VirusAttack::InitializeImages(){
|
||||
auto LoadImage=[&](Image img,std::string filepath,bool filter=false,bool clamp=true){
|
||||
IMAGES[img]=std::make_unique<Renderable>();
|
||||
IMAGES[img]->Load(filepath,nullptr,filter,clamp);
|
||||
};
|
||||
LoadImage(TILE,"assets/tile.png",false,false);
|
||||
LoadImage(MINIMAP_HUD,"assets/minimap_hud.png");
|
||||
LoadImage(OUTLINE,"assets/outline.png");
|
||||
LoadImage(VIRUS_IMG1,"assets/unit.png");
|
||||
LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png");
|
||||
|
||||
}
|
||||
|
||||
bool VirusAttack::OnUserCreate(){
|
||||
game.Initialise(GetScreenSize());
|
||||
|
||||
CONSTANT::VIRUS_IMG1.Load("assets/unit.png");
|
||||
CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png");
|
||||
InitializeImages();
|
||||
|
||||
TILE.Load("assets/tile.png",nullptr,false,false);
|
||||
MINIMAP_HUD.Load("assets/minimap_hud.png");
|
||||
OUTLINE.Load("assets/outline.png");
|
||||
MINIMAP_OUTLINE.Create(64,64);
|
||||
IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>();
|
||||
IMAGES[MINIMAP_OUTLINE]->Create(64,64);
|
||||
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true));
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},*IMAGES[VIRUS_IMG1],true));
|
||||
for(int i=0;i<10;i++){
|
||||
if(rand()%2==0){
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,true));
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],true));
|
||||
} else {
|
||||
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false));
|
||||
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -121,11 +131,11 @@ void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std:
|
||||
}
|
||||
|
||||
void VirusAttack::DrawMinimap(){
|
||||
DrawDecal(GetScreenSize()-MINIMAP_HUD.Sprite()->Size(),MINIMAP_HUD.Decal(),{1,1});
|
||||
DrawDecal(GetScreenSize()-IMAGES[MINIMAP_HUD]->Sprite()->Size(),IMAGES[MINIMAP_HUD]->Decal(),{1,1});
|
||||
vf2d minimapTL=GetScreenSize()-vf2d{64,64};
|
||||
vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE;
|
||||
vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE;
|
||||
SetDrawTarget(MINIMAP_OUTLINE.Sprite());
|
||||
SetDrawTarget(IMAGES[MINIMAP_OUTLINE]->Sprite());
|
||||
for(int y=0;y<64;y++){
|
||||
for(int x=0;x<64;x++){
|
||||
Draw(x,y,BLANK);
|
||||
@ -135,9 +145,9 @@ void VirusAttack::DrawMinimap(){
|
||||
for(auto&u:units){
|
||||
FillRect(u->GetGhostPos()/worldPixelSize*64,vf2d{2,2}*u->GetUnitSize()/24,u->IsFriendly()?GREEN:RED);
|
||||
}
|
||||
MINIMAP_OUTLINE.Decal()->Update();
|
||||
IMAGES[MINIMAP_OUTLINE]->Decal()->Update();
|
||||
SetDrawTarget(nullptr);
|
||||
DrawDecal(minimapTL,MINIMAP_OUTLINE.Decal());
|
||||
DrawDecal(minimapTL,IMAGES[MINIMAP_OUTLINE]->Decal());
|
||||
}
|
||||
|
||||
void VirusAttack::HandlePanAndZoom(float fElapsedTime){
|
||||
@ -208,13 +218,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
u->HideGhost();
|
||||
}
|
||||
}
|
||||
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,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){
|
||||
u->Draw(game);
|
||||
u->Draw(game,IMAGES);
|
||||
}
|
||||
for(auto&u:units){
|
||||
u->DrawHud(game);
|
||||
u->DrawHud(game,IMAGES);
|
||||
}
|
||||
|
||||
DrawSelectionRectangle();
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include "Unit.h"
|
||||
#include "Constant.h"
|
||||
#include "Image.h"
|
||||
|
||||
class VirusAttack : public olc::PixelGameEngine
|
||||
{
|
||||
private:
|
||||
std::vector<std::shared_ptr<Unit>>units;
|
||||
|
||||
Renderable TILE,MINIMAP_HUD,OUTLINE,MINIMAP_OUTLINE;
|
||||
std::map<Image,std::unique_ptr<Renderable>>IMAGES;
|
||||
|
||||
TileTransformedView game;
|
||||
|
||||
@ -22,6 +24,7 @@ private:
|
||||
void HandlePanAndZoom(float fElapsedTime);
|
||||
void DrawMinimap();
|
||||
void HandleMinimapClick();
|
||||
void InitializeImages();
|
||||
|
||||
public:
|
||||
VirusAttack();
|
||||
|
@ -132,6 +132,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Constant.h" />
|
||||
<ClInclude Include="Image.h" />
|
||||
<ClInclude Include="olcPGEX_PopUpMenu.h" />
|
||||
<ClInclude Include="olcPGEX_QuickGUI.h" />
|
||||
<ClInclude Include="olcPGEX_SplashScreen.h" />
|
||||
|
@ -60,6 +60,9 @@
|
||||
<ClInclude Include="TileManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Image.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="VirusAttack.cpp">
|
||||
|
Loading…
x
Reference in New Issue
Block a user