Implemented minimap hud.
This commit is contained in:
parent
cc6669d46b
commit
ab6c43f347
@ -18,6 +18,9 @@ bool VirusAttack::OnUserCreate(){
|
||||
CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png");
|
||||
|
||||
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);
|
||||
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true));
|
||||
for(int i=0;i<10;i++){
|
||||
@ -113,21 +116,36 @@ void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std:
|
||||
}
|
||||
}
|
||||
|
||||
bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
HandleDraggingSelection();
|
||||
HandleRightClickMove();
|
||||
void VirusAttack::DrawMinimap(){
|
||||
DrawDecal(GetScreenSize()-MINIMAP_HUD.Sprite()->Size(),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());
|
||||
for(int y=0;y<64;y++){
|
||||
for(int x=0;x<64;x++){
|
||||
Draw(x,y,BLANK);
|
||||
}
|
||||
}
|
||||
DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale());
|
||||
MINIMAP_OUTLINE.Decal()->Update();
|
||||
SetDrawTarget(nullptr);
|
||||
DrawDecal(minimapTL,MINIMAP_OUTLINE.Decal());
|
||||
}
|
||||
|
||||
void VirusAttack::HandlePanAndZoom(float fElapsedTime){
|
||||
float speedScale=std::min(1.f,game.GetWorldScale().x);
|
||||
if(GetKey(A).bHeld){
|
||||
game.MoveWorldOffset({-256*fElapsedTime,0});
|
||||
game.MoveWorldOffset(vf2d{-256*fElapsedTime,0}/speedScale);
|
||||
}
|
||||
if(GetKey(W).bHeld){
|
||||
game.MoveWorldOffset({0,-256*fElapsedTime});
|
||||
game.MoveWorldOffset(vf2d{0,-256*fElapsedTime}/speedScale);
|
||||
}
|
||||
if(GetKey(S).bHeld){
|
||||
game.MoveWorldOffset({0,256*fElapsedTime});
|
||||
game.MoveWorldOffset(vf2d{0,256*fElapsedTime}/speedScale);
|
||||
}
|
||||
if(GetKey(D).bHeld){
|
||||
game.MoveWorldOffset({256*fElapsedTime,0});
|
||||
game.MoveWorldOffset(vf2d{256*fElapsedTime,0}/speedScale);
|
||||
}
|
||||
|
||||
if(GetMouseWheel()>0){
|
||||
@ -135,11 +153,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
game.ZoomAtScreenPos(1.25,GetMousePos());
|
||||
}
|
||||
} else
|
||||
if(GetMouseWheel()<0){
|
||||
if(game.GetWorldScale().x>0.5){
|
||||
game.ZoomAtScreenPos(0.75,GetMousePos());
|
||||
if(GetMouseWheel()<0){
|
||||
if(game.GetWorldScale().x>0.5){
|
||||
game.ZoomAtScreenPos(0.75,GetMousePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
HandleDraggingSelection();
|
||||
HandleRightClickMove();
|
||||
HandlePanAndZoom(fElapsedTime);
|
||||
|
||||
for(auto&u:units){
|
||||
Unit*closestUnit=nullptr;
|
||||
@ -162,6 +186,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
|
||||
DrawSelectionRectangle();
|
||||
|
||||
DrawMinimap();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ class VirusAttack : public olc::PixelGameEngine
|
||||
private:
|
||||
std::vector<std::shared_ptr<Unit>>units;
|
||||
|
||||
Renderable TILE;
|
||||
Renderable TILE,MINIMAP_HUD,OUTLINE,MINIMAP_OUTLINE;
|
||||
|
||||
TileTransformedView game;
|
||||
|
||||
@ -19,6 +19,8 @@ private:
|
||||
void CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2);
|
||||
void IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2);
|
||||
vf2d GetWorldMousePos();
|
||||
void HandlePanAndZoom(float fElapsedTime);
|
||||
void DrawMinimap();
|
||||
|
||||
public:
|
||||
VirusAttack();
|
||||
|
||||
BIN
olcCodeJam2023Entry/assets/minimap_hud.png
Normal file
BIN
olcCodeJam2023Entry/assets/minimap_hud.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
BIN
olcCodeJam2023Entry/assets/outline.png
Normal file
BIN
olcCodeJam2023Entry/assets/outline.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 609 B |
Loading…
x
Reference in New Issue
Block a user